keen/col/mut-priority-queue

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

Mutable priority queue.

Elements are key-value pairs. Pairs are sorted by key. Popping removes the first 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) mut-priority-queue(a (k, v)[]) k priority
to[k, v] (k, v) mut-priority-queue(a (k, v)[]) k priority
Copies an array to a new priority queue.
clear[k, v] void(a (k, v) mut-priority-queue) k priority
Removes all pairs from the queue.
is-empty[k, v] bool(a (k, v) mut-priority-queue) k priority
true if a.size == 0.
size[k, v] nat64(a (k, v) mut-priority-queue) k priority
Number of pairs in the queue. This is O(a size).
~=[k, v] void(a (k, v) mut-priority-queue, (key k, value v)) k priority
Adds a pair to the queue. This is O(a.size log).
peek[k, v] (k, v) option(a (k, v) mut-priority-queue)
Returns the first pair (with the lowest key) without modifying a. This is O(1).
pop[k, v] (k, v) option(a (k, v) mut-priority-queue) k priority
Removes and returns the first pair (with the lowest key). Returns an empty option if the queue was empty. This is amortized O(a.size log).
copy[k, v] (k, v) mut-priority-queue(a (k, v) mut-priority-queue) k priority
Copy pairs to a new priority queue. This is O(n).
to[k, v] (k, v)[](a (k, v) mut-priority-queue) k priority
Copy pairs to an array. This is O(n).