pub struct CountMinSketch { /* private fields */ }Expand description
Count-Min Sketch for approximate frequency estimation.
Uses depth independent hash functions (derived from a single hash via
mixing) and width counters per row. Each counter is a u8 saturating
at CountMinSketch::MAX_COUNT (15 by default, representing 4-bit counters).
§Error Bounds
For a sketch with width w and depth d, after N total increments:
estimate(x) <= true_count(x) + epsilon * Nwith probability>= 1 - delta- where
epsilon = e / wanddelta = (1/2)^d
Implementations§
Source§impl CountMinSketch
impl CountMinSketch
Sourcepub fn new(width: usize, depth: usize, reset_interval: u64) -> Self
pub fn new(width: usize, depth: usize, reset_interval: u64) -> Self
Create a new Count-Min Sketch with the given dimensions.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a sketch with default parameters (w=1024, d=4, reset=8192).
Sourcepub fn increment(&mut self, hash: u64) -> bool
pub fn increment(&mut self, hash: u64) -> bool
Increment the count for a key.
Returns true if this increment triggered the periodic aging reset
(all counters halved). Callers pairing the sketch with a
Doorkeeper must clear the doorkeeper when this returns true,
so the one-hit-wonder filter restarts with the new epoch.
Sourcepub fn estimate(&self, hash: u64) -> u8
pub fn estimate(&self, hash: u64) -> u8
Estimate the frequency of a key (minimum across all rows).
Sourcepub fn total_increments(&self) -> u64
pub fn total_increments(&self) -> u64
Total number of increments since creation or last reset.
Trait Implementations§
Source§impl Clone for CountMinSketch
impl Clone for CountMinSketch
Source§fn clone(&self) -> CountMinSketch
fn clone(&self) -> CountMinSketch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more