keen/col/mut-priority-queue

Source
mut-priority-queue[k, v] record mut (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 sorted-key
to[k, v] (k, v) mut-priority-queue(a (k, v)[]) k sorted-key
Copies an array to a new priority queue.
clear[k, v] void(a (k, v) mut-priority-queue) k sorted-key
Removes all pairs from the queue.
is-empty[k, v] bool(a (k, v) mut-priority-queue) k sorted-key
true if a.size == 0.
size[k, v] nat64(a (k, v) mut-priority-queue) k sorted-key
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 sorted-key
Adds a pair to the queue. This is O(a.size log).
peek[k, v] (k, v) option(a (k, v) mut-priority-queue) k sorted-key
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 sorted-key
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 sorted-key
Copy pairs to a new priority queue. This is O(n).
to[k, v] (k, v)[](a (k, v) mut-priority-queue) k sorted-key
Copy pairs to an array. This is O(n).