PriorityQueue
A queue that pops its least element first: push and pop take
O(log n) time, peek O(1), and fromArray builds a queue in O(n).
new orders the elements by their Ord. Tuples compare element by
element, so a priority paired with a value is a tuple with the priority
first, and Dijkstra's search pushes (distance, node):
let frontier = PriorityQueue.new()
PriorityQueue.push(frontier, (0, start))
while let Some((d, here)) = PriorityQueue.pop(frontier) { ... }
newBy takes the order instead, as Vec.sortBy does; the greatest first
is newBy(fun(x, y) = Vec.threeWay(y, x)). Elements the order calls equal
pop in no particular order.
There is no way to lower an element's priority in place. Push it again with the new priority, and skip the stale entry when it pops.
Copies xs, which is left as it was.
Removes and returns the least element.
The least element, left in the queue.
Removes every element and returns them in the order pop would, least
first, leaving the queue empty.
The elements in no particular order, copied, leaving the queue as it was.
A new queue holding the elements of both, ordered as p is; q's order
is dropped. There is no Monoid: an empty queue would have to choose an
order, and as the left operand it would impose it on the right one, so it
could not be an identity for a queue made by newBy.
The elements, in no particular order, as a call to fromArray:
PriorityQueue.fromArray([x, ...]). That call orders by Ord, so for a
queue made by newBy it builds a different queue; the order is a
function and does not print.
What its Debug prints: a container's text shows its elements' Debug,
so that a string in it is quoted.