[API Review] PriorityQueue APIs

I've only skimmed so apologies if I'm missing something, but my concern here is a familiar one to anyone who remembers the RangeSet process: rather than following generic programming principles and exposing the fundamental algorithms as building blocks, the API attempts to expose one completely sealed component. It's not uncommon to start with an arbitrary (unsorted) random access collection, then heapify it and proceed with heap operations on it, without creating new storage. That's why having the heap algorithms exposed on arbitrary random access collections is useful in STL. There might be a compromise for Swift that simply exposes an init() taking an array (or you could use _copyToContiguousArray() internally on the existing init—but you should document that a copy of storage can be avoided in that case). The fully-general wrapped solution would require parameterizing PriorityQueue on the underlying storage type, so you could use a Deque, for example.

2 Likes