package intPQueue
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=4083a2898648f400d470671a71077c1b
sha512=d0ded93af26124ac551391e65eab1773db4524326d8a5c3ebdb2b92ec96878b13b456a08ac593aa27a506023030c7dc78fe48d44483dc987a34887c481b655c6
doc/intPQueue/IntPQueue/Plain/index.html
Module IntPQueue.Plain
Source
This is a priority queue whose keys are low nonnegative integers.
This queue is optimized for throughput, that is, speed. When an element is extracted out of the queue, the queue may retain a pointer to this element. This creates a memory leak: that is, the existence of this pointer can prevent the garbage collector from freeing this element. In practice, we do not expect this to be a problem, especially in scenarios where the queue itself is not long-lived.
A priority is a nonnegative integer.
A priority queue is an abstract mutable data structure. It can be thought of as a bag of elements, where each element carries a certain priority.
add q x i
inserts the element x
with priority i
into the queue q
.
Time complexity: O(1)
(amortized).
extract q
extracts an element out of the queue q
and returns it. This element has minimum priority among all of the elements that are currently present in the queue. If the queue is empty, None
is returned.
Time complexity: O(p)
. If the queue is used in a monotonic manner (that is, if the priority that is used in every call to add
is at least as high as the priority of the last element that was returned by extract
) then the time complexity of n
calls to extract
is only O(n+p)
. Indeed, in this monotonic scenario, the cost of scanning the queue's main array, so as to find the next element with minimum priority, is shared between all invocations of extract
.
extract' q
extracts an element out of the queue q
and returns a pair of this element and its priority. This element has minimum priority among all of the elements that are currently present in the queue. If the queue is empty, None
is returned.
Time complexity: see extract
.
is_empty q
tests whether the queue q
is empty.
Time complexity: O(1)
.
cardinal q
returns the number of elements in the queue q
.
Time complexity: O(1)
.
repeat q f
repeatedly extracts an element with minimum priority out of q
and passes it to f
(which may insert new elements into q
), until q
is exhausted.
Time complexity: the total cost of n
calls to extract
and n
invocations of the function f
.