class

AtCoder::PriorityQueue(T)

Inherits Enumerable / Reference / Object

Implements standard priority queue like std::priority_queue.

q = AtCoder::PriorityQueue(Int64).new
q << 1_i64
q << 3_i64
q << 2_i64
q.pop # => 3
q.pop # => 2
q.pop # => 1

Constructors

new(enumerable : Enumerable(T))

Initializes queue with the elements in enumerable.

Source
new(enumerable : Enumerable(T), &block : T, T -> Bool)

Initializes queue with the elements in enumerable and the custom comperator.

If the second argument b should be popped earlier than the first argument a, return true. Else, return false.

q = AtCoder::PriorityQueue.new([1, 3, 2]) { |a, b| a >= b }
q.pop # => 1
q.pop # => 2
q.pop # => 3
Source
new

Initializes queue with the custom comperator.

If the second argument b should be popped earlier than the first argument a, return true. Else, return false.

q = AtCoder::PriorityQueue(Int64).new { |a, b| a >= b }
q << 1_i64
q << 3_i64
q << 2_i64
q.pop # => 1
q.pop # => 2
q.pop # => 3
Source

Class methods

max(enumerable : Enumerable(T))

Create a new queue in ascending order of priority with the elements in enumerable.

Source
max

Create a new queue in ascending order of priority.

Source
min(enumerable : Enumerable(T))

Create a new queue in descending order of priority with the elements in enumerable.

Source
min

Create a new queue in descending order of priority.

Source

Instance methods

<<(v : T) : self

Alias of push

Source
each

Yields each item in the queue in comparator's order.

Source
empty?(*args, **options)

Returns true if the queue is empty.

Source
empty?(*args, **options, &)

Returns true if the queue is empty.

Source
first

Returns, but does not remove, the head of the queue.

Source
heap
Source
pop

Pops value from the queue.

Source
pop!

Pops value from the queue. Raises Enumerable::EmptyError if queue is of 0 size.

Source
push(v : T) : self

Pushes value into the queue. This method returns self, so several calls can be chained.

Source
size(*args, **options)

Returns size of the queue.

Source
size(*args, **options, &)

Returns size of the queue.

Source