csheap-0.1.10 has been yanked.
csheap
Simple heap implementation over a vector.
// Create a new heap instance for u32 elements.
let mut heap = new;
// Create a new heap instance from an u32 vector.
// this take the ownership of the vector.
let mut heap = from_vec;
// To avoid this, clone the vector.
let mut heap = from_vec;
There are two basic operations:
insert
: Insert a new element in the heap.extract
: Remove an element and return this based on the type of the heap.
Heaps comes in two flavors: Min
and Max
.
Min
:extract
always take first the minimal element.Max
:extract
always take first the maximal element.
// Create a heap that always return the maximal element
let mut heap = new;
heap.insert;
heap.insert;
heap.extract; // returns 2