Crates.io | medianheap |
lib.rs | medianheap |
version | 0.4.1 |
source | src |
created_at | 2018-12-02 06:02:47.148006 |
updated_at | 2024-01-13 01:02:59.871456 |
description | A median heap for keeping track of a running median. |
homepage | https://github.com/reitermarkus/medianheap-rs |
repository | https://github.com/reitermarkus/medianheap-rs |
max_upload_size | |
id | 99631 |
size | 15,859 |
Add this to your Cargo.toml
:
[dependencies]
medianheap = "0.4"
Elements of a MedianHeap
must be Ord
. If you want to create a MedianHeap
containing floating point numbers, you can use the ordered-float
crate.
let mut heap = MedianHeap::new();
assert_eq!(heap.median(), None);
heap.push(1);
assert_eq!(heap.median(), Some(Median::Single(&1)));
heap.push(3);
assert_eq!(heap.median(), Some(Median::Pair(&1, &3)));