heap
Generated by tinox doc
tinox.core.heap, bundled with the compiler and also available as a standalone tinox-central package.
Min heap
import tinox.core.heap
class Main
{
fnc main() -> Int32
{
// Heap::new() defaults to a min-heap comparator (a < b).
const h: Heap<Int64> = Heap::new()
Heap::push(h, 5)
Heap::push(h, 1)
Heap::push(h, 3)
println("smallest: " + Heap::peek(h).toString())
println("popped: " + Heap::pop(h).toString())
println("next smallest: " + Heap::peek(h).toString())
return 0
}
}
class Heap<T>
Fields
items | List<T> | |
comparator | fnc(T, T) -> Bool |
Methods
fn new() → Heap<T>
fn newWithCompare(comparator: fnc(T, T) -> Bool) → Heap<T>
fn push(heap: Heap<T>, item: T) → Nothing
fn pop(heap: Heap<T>) → T
fn peek(heap: Heap<T>) → T
fn siftUp(heap: Heap<T>, startIndex: Int64) → Nothing
fn siftDown(heap: Heap<T>, startIndex: Int64) → Nothing
fn isEmpty(heap: Heap<T>) → Bool
fn size(heap: Heap<T>) → Int64
fn buildHeap(heap: Heap<T>, items: List<T>) → Nothing
class MaxHeap<T>
Fields
heap | Heap<T> |
Methods
fn new() → MaxHeap<T>
fn push(h: MaxHeap<T>, item: T) → Nothing
fn pop(h: MaxHeap<T>) → T
fn peek(h: MaxHeap<T>) → T
class MinHeap<T>
Fields
heap | Heap<T> |
Methods
fn new() → MinHeap<T>
fn push(h: MinHeap<T>, item: T) → Nothing
fn pop(h: MinHeap<T>) → T
fn peek(h: MinHeap<T>) → T