Priority queue over comparable items with heap-style insertion and top-element access.
Construct with an item schema in front of the module name, for example Int32 PriorityQueue.
data: backing array storage that stores the heap elements.push (item --): inserts one item and restores heap order.top (-- ref): returns Ref to the current top item.pop (--): removes the current top item and restores heap order.getSize (-- count): returns the current item count.empty (-- isEmpty): reports whether the queue has no items.swap (i1 i2 --): swaps two heap positions.parent (ordinal -- parentOrdinal): parent-ordinal helper.lchild (ordinal -- childOrdinal): left-child ordinal helper.rchild (ordinal -- childOrdinal): right-child ordinal helper.lift (ordinal --): restores heap order upward from one ordinal.<.push preserves that maximal-item property.top and pop require one non-empty queue.top returns one Ref into the current heap array storage.push and pop may move stored items while restoring heap order, so earlier references into the queue storage must be treated as invalid after those operations.pop removes the current top item and then repairs heap order with the remaining items."PriorityQueue" use
"String" use
"control" use
{} Int32 {} [
q: Int32 PriorityQueue;
("empty0=" q.empty LF) printList
10 @q.push
3 @q.push
20 @q.push
("size=" q.getSize LF
"top=" @q.top new LF
"empty1=" q.empty LF) printList
0
] "main" exportFunction
empty0=TRUE
size=3
top=20
empty1=FALSE