class

Collections::PriorityQueue(T, P)

Inherits Reference < Object

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

Instance methods

empty?
Source
peek

Returns the lowest-priority value without removing it. Raises IndexError when the queue is empty.

Source
peek?

Like #peek, but returns nil when the queue is empty.

Source
peek_entry

Returns the lowest-priority {value, priority} pair without removing it. Raises IndexError when the queue is empty.

Source
peek_entry?

Like #peek_entry, but returns nil when the queue is empty.

Source
pop

Removes and returns the lowest-priority value. Raises IndexError when the queue is empty.

Source
pop?

Like #pop, but returns nil when the queue is empty.

Source
pop_entry

Removes and returns the lowest-priority {value, priority} pair. Raises IndexError when the queue is empty.

Source
pop_entry?

Like #pop_entry, but returns nil when the queue is empty.

Source
push(value : T, priority : P) : self

Adds value with the given priority. Returns self for chaining.

Source
size
Source