IntPQueue.PlainThis 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 queue is an abstract mutable data structure. It can be thought of as a bag of elements, where each element carries a certain priority.
val create : unit -> 'a tcreate() creates an empty priority queue.
Time complexity: O(1).
add q x i inserts the element x with priority i into the queue q.
Time complexity: O(1) (amortized).
val extract : 'a t -> 'a optionextract 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.
val is_empty : 'a t -> boolis_empty q tests whether the queue q is empty.
Time complexity: O(1).
val cardinal : 'a t -> intcardinal q returns the number of elements in the queue q.
Time complexity: O(1).