pub struct CMSketchU32 { /* private fields */ }Expand description
Count-Min Sketch storing non-atomic u32 counters.
Use CMSketchU32::new to size the table based on error (eps) and confidence requirements.
Implementations§
Source§impl CMSketchU32
impl CMSketchU32
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: u32)
pub fn inc_by(&mut self, hash: u64, count: u32)
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: u32)
pub fn dec_by(&mut self, hash: u64, count: u32)
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) -> u32
pub fn estimate(&self, hash: u64) -> u32
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.