class CGL::BinaryHeap(T)

Overview

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.

Defined in:

cgl/utils/binary_heap.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(initial_capacity : Int) #

[View source]
def self.new #

Creates a new empty BinaryHeap.


[View source]

Instance Method Detail

def ==(other : BinaryHeap) : Bool #

[View source]
def ==(other) : Bool #
Description copied from class Reference

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


[View source]
def adjust(value : T, with new_priority : Number) #

[View source]
def clear #

[View source]
def delete(value : T) : T | Nil #

[View source]
def empty? : Bool #

[View source]
def heapify! #

[View source]
def includes?(value : T) : Bool #

[View source]
def inspect(io) #

[View source]
def next_priority : Float64 #

[View source]
def next_priority(&) #

[View source]
def peek : T #

[View source]
def peek(&) #

[View source]
def peek? : T | Nil #

[View source]
def pop : T #

[View source]
def push(priority : Number, value : T) : self #

[View source]
def size : Int32 #

Returns the number of elements in the heap.


[View source]
def to_a : Array(Tuple(Float64, T)) #

[View source]
def to_slice : Slice(Tuple(Float64, T)) #

[View source]