feat: generic collection

This commit is contained in:
Pascal Engélibert 2023-04-14 12:39:11 +02:00
commit 7db8e9c3ab
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
5 changed files with 128 additions and 21 deletions

View file

@ -8,7 +8,8 @@ Simple, space-efficient algorithm to compute the median of an accumulation of el
* **Time-efficient**: push is `O(log(N))`
* **Generic**: `T: Clone + Ord`
* **Tested**
* **No unsafe**, no deps except `std`
* **No unsafe**, no deps
* **no_std** (optional): supports generic collections
Faster than other implementations if there are samples having the same value. If this is not your case, you should use another implementation.
@ -17,7 +18,7 @@ Faster than other implementations if there are samples having the same value. If
```rust
use median_accumulator::*;
let mut acc = MedianAcc::new();
let mut acc = vec::MedianAcc::new();
assert_eq!(acc.get_median(), None);
acc.push(7);
@ -30,9 +31,21 @@ assert_eq!(acc.get_median(), Some(MedianResult::One(7)));
If you ever encounter an `unreachable` panic, please file an issue or send me an e-mail.
## no_std
Example with [smallvec](https://crates.io/crates/smallvec): (`smallvec` feature required)
```rust
use median_accumulator::*;
let mut acc = MedianAcc::<i32, smallvec::SmallVec<[(i32, u32); 64]>>::new();
```
For other collections than `Vec` or `SmallVec`, you must implement [cc-traits](https://crates.io/crates/cc-traits) and `InsertIndex`.
## License
CopyLeft 2022 Pascal Engélibert
CopyLeft 2022-2023 Pascal Engélibert [(why copyleft?)](https://txmn.tk/blog/why-copyleft/)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.