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 item
returns 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 item
returns a queue containing justitem
. val fromList : item list -> queue
-
fromList items
returns a queue containing theitems
. val insert : (item * queue) -> queue
-
insert (pq, item)
returns the queue that ispq
withitem
added. val remove : queue -> (item * queue)
-
remove pq
returns(item, pq')
, whereitem
is the highest priority item inpq
andpq'
is the result of removingitem
frompq
. This function raises the Empty exception whenpq
is empty. val next : queue -> (item * queue) option
-
remove pq
returnsSOME(item, pq')
, whereitem
is the highest priority item inpq
andpq'
is the result of removingitem
frompq
. Ifpq
is empty, thenNONE
is returned. val findAndRemove : queue * (item → bool) → (item * queue) option
-
findAndRemove (pq, pred)
returnsSOME(item, pq')
, whereitem
is the highest priority item inpq
such thatpred item
returnstrue
, and andpq'
is the result of removingitem
frompq
. If no such item exists, thenNONE
is returned. val delete : queue * (item → bool) → queue
-
delete (pq, pred)
deletes any item inpq
that 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 pq
returns the number of items inpq
. val isEmpty : queue -> bool
-
isEmpty pq
returnstrue
if, and only if,pq
is empty.