| Crates.io | cmsketch |
| lib.rs | cmsketch |
| version | 0.2.2 |
| created_at | 2023-05-17 08:42:19.62681+00 |
| updated_at | 2025-04-14 09:07:43.804878+00 |
| description | A count min sketch implementation in Rust |
| homepage | https://github.com/mrcroxx/cmsketch-rs |
| repository | https://github.com/mrcroxx/cmsketch-rs |
| max_upload_size | |
| id | 866779 |
| size | 47,871 |
A count min sketch implementation in Rust.
Inspired by Facebook/CacheLib and Caffeine.
Add cmsketch into the dependencies of your project:
cmsketch = "0.2"
use cmsketch::CMSketchU32;
const ERROR: f64 = 0.01;
const CONFIDENCE: f64 = 0.95;
fn main() {
let mut cms = CMSketchU32::new(ERROR, CONFIDENCE);
for i in 0..10 {
for _ in 0..i {
cms.inc(i);
}
}
for i in 0..10 {
assert!(cms.estimate(i) >= i as u32);
}
cms.halve();
for i in 0..10 {
assert!(cms.estimate(i) >= (i as f64 * 0.5) as u32);
}
}
Rust version >= 1.81.0.