UXHeapEntry
UXHeapEntry pairs an object with its priority inside a
UXBinaryHeap.
#use <UXKit> // or #import "UXBinaryHeap.xc"Overview
Section titled “Overview”class UXHeapEntry : Object { Object* obj; // what was inserted i32 pri; // its key; LOWER comes out first}insert makes an entry, and
removeMinimum discards
it and returns obj. The public interface never exposes an entry.
Why the priority is stored beside the object
Section titled “Why the priority is stored beside the object”The alternatives both cost more. A comparator callback adds an indirect call per comparison, and a heap does O(log n) comparisons per operation. Asking the object for its own priority requires every insertable type to implement something.
Storing the key at insert time makes each comparison a plain integer
compare. An object can go in twice with different priorities, and it needs
no cooperation: any Object* is insertable.
The cost is that the key is a snapshot:
obj is strong
Section titled “obj is strong”The heap keeps its items alive until they are removed, so a queue of pending work never fills with nulls.
For the same reason, call
removeAll on a heap you are
abandoning instead of draining.
Fields
Section titled “Fields”Object* objThe inserted object, returned by
removeMinimum.
i32 priThe ordering key. Lower comes first; negate it for a max-heap.
Conforms to
Section titled “Conforms to”- Inherits
Object
See also
Section titled “See also”UXBinaryHeap: the heap these live inUXBagEntry: the same one-row-of-a-collection shape, counted instead of ordered