pub struct CMSketchUsize { /* private fields */ }Expand description
Count-Min Sketch storing non-atomic usize counters.
Use CMSketchUsize::new to size the table based on error (eps) and confidence requirements.
Implementations§
Source§impl CMSketchUsize
impl CMSketchUsize
Sourcepub fn new(eps: f64, confidence: f64) -> Self
pub fn new(eps: f64, confidence: f64) -> Self
Creates a new sketch sized by the target error eps and confidence.
eps controls the maximum additive error (≈ 2/width), while
confidence determines the number of hash rows (depth).
Typical confidence to depth mapping:
0.50 => 1 row
0.80 => 3 rows
0.95 => 5 rows
0.995 => 8 rows§Panics
Panics if eps <= 0.0 or confidence <= 0.0.
Sourcepub fn inc_by(&mut self, hash: u64, count: usize)
pub fn inc_by(&mut self, hash: u64, count: usize)
Increments the count associated with the provided hash by count.
Saturates at the maximum value representable by the counter type.
Sourcepub fn dec_by(&mut self, hash: u64, count: usize)
pub fn dec_by(&mut self, hash: u64, count: usize)
Decrements the count associated with the provided hash by count.
Saturates at zero if the counter would go negative.
Sourcepub fn estimate(&self, hash: u64) -> usize
pub fn estimate(&self, hash: u64) -> usize
Returns the minimum counter across all rows for hash.
This is the standard Count-Min Sketch estimator and forms an upper bound.
Sourcepub fn halve(&mut self)
pub fn halve(&mut self)
Divides every counter by two using a right shift.
Useful for exponential decay where counts represent recent activity.