A priority queue. pop returns the smallest item by the comparator, which returns a
negative number when its first argument comes first, as the comparator of Array.sort
does. Two items that compare as equal come out in no fixed order, so a caller that needs
one puts a sequence number into its items.
push and pop take time logarithmic in the number of items, and peek takes constant
time. A heap with a budget charges one Resource.Cells for each item of its largest size
so far, so an item that takes the place of a popped one is free.
A priority queue.
popreturns the smallest item by the comparator, which returns a negative number when its first argument comes first, as the comparator ofArray.sortdoes. Two items that compare as equal come out in no fixed order, so a caller that needs one puts a sequence number into its items.pushandpoptake time logarithmic in the number of items, andpeektakes constant time. A heap with a budget charges oneResource.Cellsfor each item of its largest size so far, so an item that takes the place of a popped one is free.