keen/col/priority-queue

Source
priority-queue[k, v] record (has private fields)

Immutable priority queue.

Elements are key-value pairs. Pairs are sorted by key. Popping removes the pair with the lowest key.

If two pairs have the same key, the second pair added will be popped second.

list-new[k, v] (k, v) priority-queue(a (k, v)[]) k sorted-key
to[k, v] (k, v) priority-queue(a (k, v)[]) k sorted-key
to[k, v] (k, v)[](a (k, v) priority-queue) k sorted-key
is-empty[k, v] bool(a (k, v) priority-queue) k sorted-key
true if a.size == 0.
size[k, v] nat64(a (k, v) priority-queue) k sorted-key
Number of pairs in the priority queue. This is O(n) where n is the result.
~[k, v] (k, v) priority-queue(a (k, v) priority-queue, b (k, v)) k sorted-key
Adds a pair to the queue. This is O(1), since the work of sorting pairs is actually done in pop.
pop[k, v] ((k, v), (k, v) priority-queue) option(a (k, v) priority-queue) k sorted-key
Removes and returns the pair with the lowest key. Returns an empty option if a is-empty. This is amortized O(a.size log).
some[k, v] bool(a (k, v) priority-queue, f bool mut((k, v))) k sorted-key