CMSketchUsize

Struct CMSketchUsize 

Source
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

Source

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.

Source

pub fn inc(&mut self, hash: u64)

Increments the count associated with the provided hash by 1.

Source

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.

Source

pub fn dec(&mut self, hash: u64)

Decrements the count associated with the provided hash by 1.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Resets all counters to zero.

Source

pub fn halve(&mut self)

Divides every counter by two using a right shift.

Useful for exponential decay where counts represent recent activity.

Source

pub fn decay(&mut self, decay: f64)

Multiplies every counter by decay and truncates back into $type.

Values are floored after multiplication; choose decay in (0, 1].

Source

pub fn width(&self) -> usize

Returns the configured table width (number of columns).

Source

pub fn depth(&self) -> usize

Returns the number of hash rows.

Source

pub fn capacity(&self) -> usize

Returns the maximum representable counter for this sketch.

Source

pub fn memory(&self) -> usize

Returns the amount of memory the sketch uses in bytes.

Trait Implementations§

Source§

impl Debug for CMSketchUsize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.