go-heap-rs

Test Docs

Golang's heap written in Rust

Advantages

Disadvantages

Importing

toml [dependencies] go-heap-rs = "0.1"

Example of usage

```rust struct MinHeap(Vec);

impl Heap for MinHeap { fn len(&self) -> usize { self.0.len() }

fn less(&self, i: usize, j: usize) -> bool {
    self.0[i] < self.0[j]
}

fn swap(&mut self, i: usize, j: usize) {
    self.0.swap(i, j);
}

fn push(&mut self, x: T) {
    self.0.push(x);
}

fn pop(&mut self) -> T {
    self.0.pop().expect("pop on an empty vec!")
}

fn peak(&self) -> Option<&T> {
    self.0.get(0)
}

}

fn test() { let myvec = MinHeap(vec![2, 4, 3, 1]); let mut heap = HeapType::new(myvec); asserteq!(heap.peak(), Some(&1)); asserteq!(heap.pop(), Some(1)); heap.push(-1); assert_eq!(heap.pop(), Some(-1)); } ```