Skip to main content

CountMinSketch

Count-Min sketch for frequency estimation. Probabilistic counter that over-estimates frequencies. Uses d hash functions and w counters per row to provide (epsilon, delta) guarantees. eps in (0, 1) - error parameter delta in (0, 1) - confidence parameter :::note Memory: O(1/eps * log(1/delta)) counters ::: :::note Update: O(log(1/delta)) operations ::: :::note Query: O(log(1/delta)) operations ::: :::warning Returned estimate is always >= true count (upper bound) :::

Public Methods


CountMinSketch

inline
Construct a Count-Min sketch.

Parameters

  • eps Error parameter (epsilon). Error <= eps * N with probability delta Smaller eps = more memory, more accuracy
  • delta Confidence parameter. Error guarantee holds with probability (1 - delta) Smaller delta = more memory, higher confidence

Exceptions

  • std::invalid_argument If eps <= 0 or eps >= 1
  • std::invalid_argument If delta <= 0 or delta >= 1

Example:


increment

inline
Increment count for a key.

Parameters

  • key String identifier to count
  • count Amount to add (default: 1)
Count for key is incremented by count :::note Updates all d hash function buckets :::

estimate

const
Estimate frequency of a key.

Parameters

  • key Key to estimate count for

Returns

Estimated count (guaranteed >= true count)

Parameters

  • >= Actual frequency (upper bound)
  • <= eps * N (theoretical upper bound)
:::note Returns minimum across all hash function buckets ::: :::note Always returns estimate >= true count :::

clear

inline
Reset all counters to zero.

Private Attributes


table_

Table of counters [hash_function][bucket].

w_

Number of buckets (w)

d_

Number of hash functions (d)

Private Methods


hash_fn

const
Compute hash using double hashing technique.