The LeftPriorityQFn functor provides a functional implementation of priority
queues using leaftist heaps.
Synopsis
signature PRIORITY
signature MONO_PRIORITYQ
functor LeftPriorityQFn (P : PRIORITY) : MONO_PRIORITYQ
Functor Argument Interface
type priority
val compare : (priority * priority) -> order
type item
val priority : item -> priority
Functor Argument Description
type priority-
The abstract type of priority values.
val compare : (priority * priority) -> order-
compare (pri1, pri2)returns the order of the two priority values. type item-
The type of items in the priority queue.
val priority : item -> priority-
priority itemreturns the priority value foritem.
Interface
type item
type queue
val empty : queue
val singleton : item -> queue
val fromList : item list -> queue
val insert : (item * queue) -> queue
val remove : queue -> (item * queue)
val next : queue -> (item * queue) option
val findAndRemove : queue * (item -> bool) -> (item * queue) option
val delete : queue * (item -> bool) -> queue
val merge : (queue * queue) -> queue
val numItems : queue -> int
val isEmpty : queue -> bool
Interface Description
type item-
The type of items in the priority queue.
type queue-
The priority queue type.
val empty : queue-
The empty priority queue.
val singleton : item -> queue-
singleton itemreturns a queue containing justitem. val fromList : item list -> queue-
fromList itemsreturns a queue containing theitems. val insert : (item * queue) -> queue-
insert (pq, item)returns the queue that ispqwithitemadded. val remove : queue -> (item * queue)-
remove pqreturns(item, pq'), whereitemis the highest priority item inpqandpq'is the result of removingitemfrompq. This function raises the Empty exception whenpqis empty. val next : queue -> (item * queue) option-
remove pqreturnsSOME(item, pq'), whereitemis the highest priority item inpqandpq'is the result of removingitemfrompq. Ifpqis empty, thenNONEis returned. val findAndRemove : queue * (item → bool) → (item * queue) option-
findAndRemove (pq, pred)returnsSOME(item, pq'), whereitemis the highest priority item inpqsuch thatpred itemreturnstrue, and andpq'is the result of removingitemfrompq. If no such item exists, thenNONEis returned. val delete : queue * (item → bool) → queue-
delete (pq, pred)deletes any item inpqthat satisfies the predicate and returns the resulting queue. val merge : (queue * queue) -> queue-
merge (pq1, pq2)returns the priority queue formed by merging the items in the two queues. val numItems : queue -> int-
numItems pqreturns the number of items inpq. val isEmpty : queue -> bool-
isEmpty pqreturnstrueif, and only if,pqis empty.