Heap already has
Sequence conformance via two computed properties. If
Collection conformance was ever added, it would also be through such a property.
Iteration through a
Heap is destructive. When you use official iteration, like through a
in loop, the
IteratorProtocol object is a copy of the receiver, so the original isn't affected. But all
Collection operations are non-destructive; given an element's index, you must be able to compute the next index without mutating the collection. That can't really be done with a heap.
(Yes, there are refinements of
Collection for mutation, but neither are appropriate for
Heap, because a
Heap allows only narrow changes, but
MutableCollection mandate arbitrary changes in their domains.)
I've been thinking out how it could be done. My thought so far was a linked list; the internal storage changes from
Element to a
(Element, previous: Int?, next: Int?) tuple, and you keep track of the maximum element's index. But the updates whenever you add (or remove?) an element end up being linear.
For scrambled in memory, I only meant for unscrambled elements be logically adjacent, not physically (i.e.