#root::data
Heap root/data/Heap.vi
struct Heap[T](...);
A min-heap, which provides efficient access to the smallest value in the heap.
empty root/data/Heap.vi:14
const empty[T]: Heap[T];
The empty heap.
Heap::empty // Heap([])
single root/data/Heap.vi:20
fn single[T](value: T) -> Heap[T];
Create a heap containing a single element.
Heap::single(46) // Heap([46])
insert root/data/Heap.vi:32
fn insert[T; Ord[T]](self: &Heap[T], value: T);
Insert a value into the heap. O(log n)
let heap = Heap::empty; heap.insert(3); heap.insert(1); heap.insert(2); heap as List // [1, 2, 3]
pop root/data/Heap.vi:37
fn pop[T; Ord[T]](...: &Heap[T]) -> Option[T];
Remove the smallest value from the heap. O(log n)
peek root/data/Heap.vi:48
fn peek[T; Ord[T]](...: &Heap[T]) -> Option[&T];
Peek at the smallest value in the heap. O(1)
is_empty root/data/Heap.vi:57
fn is_empty[T](...: &Heap[T]) -> Bool;
count root/data/Heap.vi:70
fn count[T](...: &Heap[T]) -> N32;
Count the number of elements in the heap. O(n)
merge root/data/Heap.vi:86
impl merge[T; Ord[T]]: Concat[Heap[T], Heap[T], Heap[T]];
Merge two heaps. O(log n)
let a = [5, 3, 1] as Heap; let b = [0, 4, 2] as Heap; let merged = a ++ b; merged as List // [0, 1, 2, 3, 4, 5]
fork root/data/Heap.vi:110
impl fork[T; Fork[T]]: Fork[Heap[T]];
drop root/data/Heap.vi:122
impl drop[T; Drop[T]]: Drop[Heap[T]];
from_list root/data/Heap.vi:140
impl from_list[T; Ord[T]]: Cast[List[T], Heap[T]];
Build a heap out of the elements of a list.
let heap = [3, 1, 2] as Heap; heap.pop() // Some(1) heap.pop() // Some(2) heap.pop() // Some(3) heap.pop() // None
to_list root/data/Heap.vi:160
impl to_list[T; Ord[T]]: Cast[Heap[T], List[T]];
Convert a heap to a list in ascending order.
let heap = Heap::empty; heap.insert(5); heap.insert(3); heap.insert(2); heap.insert(4); heap.insert(1); heap as List // [1, 2, 3, 4, 5]
Iter root/data/Heap.vi:171
struct Iter[T](...);
iter root/data/Heap.vi:185
impl iter[T; Ord[T]]: Cast[Heap[T], Iter[T]];
Iterate over the elements of the heap in ascending order.
let heap = [3, 1, 2]; for value in heap { io.println("{value}"); }
1 2 3
show root/data/Heap.vi:210
impl show[T; Show[T]]: Show[Heap[T]];
Display the heap. The first displayed value is the minimum value, but all other values are displayed in an arbitrary order.
let heap = [5, 2, 1, 3, 4] as Heap "{heap.show()}" // Heap([1, 2, 5, 3, 4])