class CGL::BinaryHeap(T)
- CGL::BinaryHeap(T)
- Reference
- Object
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.crConstructors
- .new(initial_capacity : Int)
-
.new
Creates a new empty BinaryHeap.
Instance Method Summary
- #==(other : BinaryHeap) : Bool
-
#==(other) : Bool
Returns
false
(other can only be aValue
here). - #adjust(value : T, with new_priority : Number)
- #clear
- #delete(value : T) : T?
- #empty? : Bool
- #heapify!
- #includes?(value : T) : Bool
- #inspect(io)
- #next_priority : Float64
- #next_priority(&)
- #peek : T
- #peek(&)
- #peek? : T?
- #pop : T
- #push(priority : Number, value : T) : self
-
#size : Int32
Returns the number of elements in the heap.
- #to_a : Array(Tuple(Float64, T))
- #to_slice : Slice(Tuple(Float64, T))
Constructor Detail
Instance Method Detail
def ==(other) : Bool
#
Description copied from class Reference
Returns false
(other can only be a Value
here).