|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Count-Min Sketch frequency estimator. More...
#include <count-min-sketch.H>
Public Member Functions | |
| Count_Min_Sketch (const size_t w, const size_t d) | |
| Construct with explicit dimensions. | |
| void | update (const T &val, CounterT count=1) |
| Increment count for an element. | |
| CounterT | estimate (const T &val) const |
| Estimate frequency of an element. | |
| void | merge (const Count_Min_Sketch &other) |
| Merge another sketch into this one. | |
| void | clear () |
| Clear all counters. | |
| size_t | width () const noexcept |
| Number of counter columns (hash buckets per row). | |
| size_t | depth () const noexcept |
| Number of hash functions (independent counter rows). | |
| CounterT | total_count () const noexcept |
| Sum of all event weights inserted so far. | |
Static Public Member Functions | |
| static Count_Min_Sketch | from_error_bounds (const double epsilon, const double delta) |
| Create a sketch with target error bounds. | |
Private Attributes | |
| size_t | w_ |
| Width of the sketch. | |
| size_t | d_ |
| Depth (number of hash functions). | |
| Array< CounterT > | table_ |
| Flat array for counters [d_ x w_]. | |
| Array< uint32_t > | seeds_ |
| Random seeds for hash functions. | |
| CounterT | total_count_ = 0 |
| Total updates processed. | |
Count-Min Sketch frequency estimator.
Provides approximate frequency queries for elements in a stream. The estimate is always an upper bound (no false negatives).
Memory complexity is O(w * d), where:
| T | Type of elements to count. |
| CounterT | Unsigned integral type for counters (default: size_t). |
Definition at line 70 of file count-min-sketch.H.
|
inline |
Construct with explicit dimensions.
| [in] | w | Width (columns). |
| [in] | d | Depth (rows / hash functions). |
Definition at line 83 of file count-min-sketch.H.
References ah_domain_error_if, Aleph::Array< T >::append(), Aleph::Count_Min_Sketch< T, CounterT >::d_, Aleph::dft_hash_fct(), Aleph::divide_and_conquer_partition_dp(), Aleph::Array< T >::reserve(), Aleph::Count_Min_Sketch< T, CounterT >::seeds_, Aleph::Count_Min_Sketch< T, CounterT >::table_, w, and Aleph::Count_Min_Sketch< T, CounterT >::w_.
|
inline |
Clear all counters.
Definition at line 196 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::table_, and Aleph::Count_Min_Sketch< T, CounterT >::total_count_.
|
inlinenoexcept |
Number of hash functions (independent counter rows).
| none |
Definition at line 215 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::d_.
Estimate frequency of an element.
Definition at line 156 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::d_, Aleph::divide_and_conquer_partition_dp(), h, Aleph::murmur3hash(), Aleph::Count_Min_Sketch< T, CounterT >::seeds_, Aleph::Count_Min_Sketch< T, CounterT >::table_, and Aleph::Count_Min_Sketch< T, CounterT >::w_.
|
inlinestatic |
Create a sketch with target error bounds.
Calculates optimal w and d for given epsilon and delta. Estimate will be within epsilon * total_count from actual with probability at least 1 - delta.
| [in] | epsilon | Relative error bound (must be > 0). |
| [in] | delta | Confidence bound (error probability, must be in (0, 1)). |
Definition at line 110 of file count-min-sketch.H.
References ah_domain_error_if, and Aleph::divide_and_conquer_partition_dp().
Referenced by TEST().
|
inline |
Merge another sketch into this one.
| std::domain_error | if dimensions or seeds mismatch. |
Definition at line 170 of file count-min-sketch.H.
References ah_domain_error_if, Aleph::Count_Min_Sketch< T, CounterT >::d_, Aleph::divide_and_conquer_partition_dp(), Aleph::Count_Min_Sketch< T, CounterT >::seeds_, Aleph::Count_Min_Sketch< T, CounterT >::table_, Aleph::Count_Min_Sketch< T, CounterT >::total_count_, and Aleph::Count_Min_Sketch< T, CounterT >::w_.
|
inlinenoexcept |
Sum of all event weights inserted so far.
| none |
Definition at line 222 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::total_count_.
Increment count for an element.
| [in] | val | Element to update. |
| [in] | count | Increment value (defaults to 1). |
Definition at line 131 of file count-min-sketch.H.
References Aleph::count(), Aleph::Count_Min_Sketch< T, CounterT >::d_, Aleph::divide_and_conquer_partition_dp(), h, Aleph::murmur3hash(), Aleph::Count_Min_Sketch< T, CounterT >::seeds_, Aleph::Count_Min_Sketch< T, CounterT >::table_, Aleph::Count_Min_Sketch< T, CounterT >::total_count_, and Aleph::Count_Min_Sketch< T, CounterT >::w_.
|
inlinenoexcept |
Number of counter columns (hash buckets per row).
| none |
Definition at line 208 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::w_.
|
private |
Depth (number of hash functions).
Definition at line 73 of file count-min-sketch.H.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::Count_Min_Sketch(), Aleph::Count_Min_Sketch< T, CounterT >::depth(), Aleph::Count_Min_Sketch< T, CounterT >::estimate(), Aleph::Count_Min_Sketch< T, CounterT >::merge(), and Aleph::Count_Min_Sketch< T, CounterT >::update().
|
private |
Random seeds for hash functions.
Definition at line 75 of file count-min-sketch.H.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::Count_Min_Sketch(), Aleph::Count_Min_Sketch< T, CounterT >::estimate(), Aleph::Count_Min_Sketch< T, CounterT >::merge(), and Aleph::Count_Min_Sketch< T, CounterT >::update().
|
private |
Flat array for counters [d_ x w_].
Definition at line 74 of file count-min-sketch.H.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::Count_Min_Sketch(), Aleph::Count_Min_Sketch< T, CounterT >::clear(), Aleph::Count_Min_Sketch< T, CounterT >::estimate(), Aleph::Count_Min_Sketch< T, CounterT >::merge(), and Aleph::Count_Min_Sketch< T, CounterT >::update().
|
private |
Total updates processed.
Definition at line 76 of file count-min-sketch.H.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::clear(), Aleph::Count_Min_Sketch< T, CounterT >::merge(), Aleph::Count_Min_Sketch< T, CounterT >::total_count(), and Aleph::Count_Min_Sketch< T, CounterT >::update().
|
private |
Width of the sketch.
Definition at line 72 of file count-min-sketch.H.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::Count_Min_Sketch(), Aleph::Count_Min_Sketch< T, CounterT >::estimate(), Aleph::Count_Min_Sketch< T, CounterT >::merge(), Aleph::Count_Min_Sketch< T, CounterT >::update(), and Aleph::Count_Min_Sketch< T, CounterT >::width().