class

CGL::BinaryHeap(T)

Inherits Reference / Object

A simple priority queue implemented as a array-based heap.

Each inserted elements is given a certain priority, based on the result of the comparison. This is a min-heap, which means retrieving an element will always return the one with the highest priority.

To avoid O(n) complexity when deleting an arbitrary element, a map is used to cache indices for each element.

Constructors

new(initial_capacity : Int)
Source
new

Creates a new empty BinaryHeap.

Source

Instance methods

==(other : BinaryHeap) : Bool
Source
==(other) : Bool

Returns false (other can only be a Value here).

Source
adjust(value : T, with new_priority : Number)
Source
clear
Source
delete(value : T) : T | Nil
Source
empty?
Source
heapify!
Source
includes?(value : T) : Bool
Source
inspect(io)
Source
next_priority
Source
next_priority
Source
peek
Source
peek
Source
peek?
Source
push(priority : Number, value : T) : self
Source
size

Returns the number of elements in the heap.

Source
to_a
Source
to_slice
Source