class AtCoder::PriorityQueue(T)

Overview

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

Included Modules

Defined in:

priority_queue.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(enumerable : Enumerable(T)) #

Initializes queue with the elements in enumerable.


[View source]
def self.new #

[View source]
def self.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

[View source]
def self.new(&block : T, T -> Bool) #

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

[View source]

Class Method Detail

def self.max(enumerable : Enumerable(T)) #

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


[View source]
def self.max #

Create a new queue in ascending order of priority.


[View source]
def self.min(enumerable : Enumerable(T)) #

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


[View source]
def self.min #

Create a new queue in descending order of priority.


[View source]

Instance Method Detail

def <<(v : T) : self #

Alias of #push


[View source]
def each(&) #

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


[View source]
def empty?(*args, **options) #

Returns true if the queue is empty.


[View source]
def empty?(*args, **options, &) #

Returns true if the queue is empty.


[View source]
def first(&) #

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


[View source]
def heap : Array(T) #

[View source]
def pop #

Pops value from the queue.


[View source]
def pop! #

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


[View source]
def push(v : T) : self #

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


[View source]
def size(*args, **options) #

Returns size of the queue.


[View source]
def size(*args, **options, &) #

Returns size of the queue.


[View source]