Priority Queues
(require data/priority-queue) | package: priority-queue |
Imperative max priority queues. Currently implemented with a binary heap, but that is an internal detail that is subject to change in the future.
Two priority queues are equal? if they have equal? comparison functions, contain the same number of elements and when sorted by priority each corresponding pair of elements are equal?. This can be an expensive operation.
1 Predicates
procedure
(priority-queue? obj) → boolean?
obj : any/c
procedure
(priority-queue-empty? pq) → boolean?
pq : priority-queue?
2 Constructors
procedure
(make-priority-queue < elem ...) → priority-queue?
< : (-> any/c any/c any/c) elem : any/c
procedure
(list->priority-queue < elems) → priority-queue?
< : (-> any/c any/c any/c) elems : list?
procedure
(vector->priority-queue < elems) → priority-queue?
< : (-> any/c any/c any/c) elems : vector?
procedure
pq : priority-queue?
3 Mutating the queue
procedure
(priority-queue-insert! pq elem) → void?
pq : priority-queue? elem : any/c
procedure
(priority-queue-remove-max! pq) → any/c
pq : (and/c priority-queue? (not/c priority-queue-empty?))
procedure
(priority-queue-remove! pq elem [=?]) → boolean?
pq : priority-queue? elem : any/c =? : (-> any/c any/c any/c) = equal?
If the queue has multiple elements that can compare equal to the given one, it is unspecified which one is removed.
procedure
(in-priority-queue! pq) → sequence?
pq : priority-queue?
A priority queue can be used directly as a sequence? with the same effect.
4 Other operations
procedure
(priority-queue-peek-max pq) → any/c
pq : (and/c priority-queue? (not/c priority-queue-empty?))
procedure
pq : priority-queue?
procedure
(priority-queue-ordering pq) → (-> any/c any/c any/c)
pq : priority-queue?
procedure
(priority-queue-map f pq [<]) → priority-queue?
f : (-> any/c any/c) pq : priority-queue? < : (-> any/c any/c any/c) = (priority-queue-ordering pq)
procedure
(priority-queue->list pq) → list?
pq : priority-queue?
procedure
(priority-queue->vector pq) → vector?
pq : priority-queue?
procedure
(priority-queue->vector! pq vec) → vector?
pq : priority-queue? vec : (and/c vector? (not/c immutable?))
procedure
(priority-queue->sorted-list pq) → list?
pq : priority-queue?
procedure
pq : priority-queue?
procedure
(priority-queue->sorted-vector! pq vec) → vector?
pq : priority-queue? vec : (and/c vector? (not/c immutable?))