PQ
signature
A priority queue is a collection of key-value pairs which prioritizes access
to its minimum key. The key type is ordered and fixed by the
Key
substructure while the value type
is polymorphic.
structure Key : ORDKEY
type α t
type α pq = α t
val empty : unit → α pq
val singleton : (Key.t * α) → α pq
val fromList : (Key.t * α) list → α pq
val size : α pq → int
val findMin : α pq → (Key.t * α) option
val insert : α pq * (Key.t * α) → α pq
val deleteMin : α pq → (Key.t * α) option * α pq
val meld : α pq * α pq → α pq
val $ : (Key.t * α) → α pq
val % : (Key.t * α) list → α pq
structure Key : ORDKEY
Key
substructure defines the key type of
priority queues, providing comparison and other useful functions.
type α t
type α pq = α t
α t
, for readability.
val empty :
unit → α pq
val singleton :
(Key.t * α) → α pq
(singleton (k, v))
evaluates to the priority queue containing
only the pair $(k, v)$.
val fromList :
(Key.t * α) list → α pq
val size :
α pq → int
val findMin :
α pq → (Key.t * α) option
NONE
if the queue is empty.
If there are multiple minimum keys, then any one of them might
be chosen.
val insert :
α pq * (Key.t * α) → α pq
val deleteMin :
α pq → (Key.t * α) option * α pq
(deleteMin q)
evaluates to $(x, q')$ where $x$ is the minimum
key (paired with its associated value) in $q$, and
$q'$ is the priority queue which contains all elements of $q$ except for
$x$. If there are multiple minimum keys in $q$, then any one of them might
be chosen. If $q$ is empty, then $x$ = NONE
and $q' = q$.
val meld :
α pq * α pq → α pq
(meld (x, y))
evalautes to the
priority queue which contains all key-value pairs from both $x$ and $y$.
val $ :
(Key.t * α) → α pq
singleton
.
val % :
(Key.t * α) list → α pq
fromList
.