Enhancement over Rust's std::collections::BinaryHeap
.
It supports the following features and still maintains backward compatibility.
- Max heap
- Min heap
- Heap ordered by closure
- Heap ordered by key generated by closure
You can change the line
use std::collections::BinaryHeap;
to like below.
use binary_heap_plus::*;
Your code will compile as before unless you use unstable APIs.
This crate requires Rust 1.26 or later.
- (original)
::new()
// creates a max heap ::new_min()
// creates a min heap::new_by(f)
// creates a heap ordered by the given closuref
::new_by_key(g)
// creates a heap ordered by key generated by the given closureg
- (original)
::with_capacity(n)
// creates a max heap with capacityn
::with_capacity_min(n)
// creates a min heap with capacityn
::with_capacity_by(n, f)
// creates a heap with capacityn
, ordered by the given closuref
::with_capacity_by_key(n, g)
// creates a heap with capacityn
, ordered by key generated by the given closureg
In future, the trait Compare<T>
might be replaced with FnMut(&T, &T) -> Ordering
.
To do that, rustc needs to stabilize a few unstable features.
- I received many valuable feedback from Pre-RFC thread [1].
- The current design is based on @ExpHP's suggestion that compiles on stable compiler.
- DDOtten, steven099, CAD97, ExpHP, scottmcm, Nemo157 and gnzlbg, thanks for looking into the design!
- @ulysseB sent me a first pull request!
See the following discussions for the background of the crate: