Collections::PriorityQueue(T, P)
A min-priority queue: values are popped lowest-priority-first. Built as a
thin wrapper over BinaryHeapMin, so pushes and pops are O(log n).
The value type T and the priority type P are independent — T need not
be comparable, only P (any type whose <=> yields a non-nil Int32, such
as Int32, Int64 or Float64).
pq = Collections::PriorityQueue(String, Int32).new
pq.push("low", 5)
pq.push("high", 1)
pq.pop # => "high"
Constructors
new
SourceInstance methods
empty?
Sourcepeek
Returns the lowest-priority value without removing it. Raises IndexError
when the queue is empty.
peek_entry
Returns the lowest-priority {value, priority} pair without removing it.
Raises IndexError when the queue is empty.
pop_entry
Removes and returns the lowest-priority {value, priority} pair. Raises
IndexError when the queue is empty.
push(value : T, priority : P) : self
Adds value with the given priority. Returns self for chaining.
size
Source