|
Aleph-w 7.10.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. | |
| Count_Min_Sketch (const Count_Min_Sketch &other)=default | |
| Copy the dimensions and the counters of another sketch. | |
| Count_Min_Sketch (Count_Min_Sketch &&other) | |
| Take the counters of another sketch, which is left as an empty sketch of the same dimensions. | |
| Count_Min_Sketch & | operator= (const Count_Min_Sketch &other)=default |
| Copy the dimensions and the counters of another sketch. | |
| Count_Min_Sketch & | operator= (Count_Min_Sketch &&other) noexcept |
| Exchange this sketch with another, which is left with the previous state of this one. | |
| void | swap (Count_Min_Sketch &other) noexcept |
| Exchange in O(1) the state of this sketch and another. | |
| 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::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_.
|
default |
Copy the dimensions and the counters of another sketch.
| [in] | other | sketch to copy. |
| std::bad_alloc | if the counters cannot be allocated. |
|
inline |
Take the counters of another sketch, which is left as an empty sketch of the same dimensions.
The implicit move took the counters but copied the dimensions: the moved-from sketch then indexed counters that it no longer had.
| [in,out] | other | sketch to move from. |
| std::bad_alloc | if the counters left to other cannot be allocated; other is then unchanged. |
other. Definition at line 117 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::swap().
|
inline |
Clear all counters.
Definition at line 249 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::table_, and Aleph::Count_Min_Sketch< T, CounterT >::total_count_.
Referenced by Moved_From_Case< Count_Min_Sketch< int > >::use().
|
inlinenoexcept |
Number of hash functions (independent counter rows).
| none |
Definition at line 268 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::d_.
|
inline |
Estimate frequency of an element.
Definition at line 209 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::d_, 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_.
Referenced by TEST(), TEST(), TEST(), and Moved_From_Case< Count_Min_Sketch< int > >::use().
|
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 163 of file count-min-sketch.H.
References ah_domain_error_if.
Referenced by TEST().
|
inline |
Merge another sketch into this one.
| std::domain_error | if dimensions or seeds mismatch. |
Definition at line 223 of file count-min-sketch.H.
References ah_domain_error_if, Aleph::Count_Min_Sketch< T, CounterT >::d_, 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_.
|
default |
Copy the dimensions and the counters of another sketch.
| [in] | other | sketch to copy. |
| std::bad_alloc | if the counters cannot be allocated. |
|
inlinenoexcept |
Exchange this sketch with another, which is left with the previous state of this one.
| [in,out] | other | sketch to move from. |
Definition at line 135 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::swap().
|
inlinenoexcept |
Exchange in O(1) the state of this sketch and another.
| [in,out] | other | sketch to exchange with. |
Definition at line 144 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::d_, Aleph::Count_Min_Sketch< T, CounterT >::seeds_, Aleph::Array< T >::swap(), Aleph::Count_Min_Sketch< T, CounterT >::table_, Aleph::Count_Min_Sketch< T, CounterT >::total_count_, and Aleph::Count_Min_Sketch< T, CounterT >::w_.
Referenced by Aleph::Count_Min_Sketch< T, CounterT >::Count_Min_Sketch(), and Aleph::Count_Min_Sketch< T, CounterT >::operator=().
|
inlinenoexcept |
Sum of all event weights inserted so far.
| none |
Definition at line 275 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::total_count_.
Referenced by Moved_From_Case< Count_Min_Sketch< int > >::is_empty().
|
inline |
Increment count for an element.
| [in] | val | Element to update. |
| [in] | count | Increment value (defaults to 1). |
Definition at line 184 of file count-min-sketch.H.
References Aleph::count(), Aleph::Count_Min_Sketch< T, CounterT >::d_, 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_.
Referenced by Moved_From_Case< Count_Min_Sketch< int > >::make(), TEST(), TEST(), TEST(), and Moved_From_Case< Count_Min_Sketch< int > >::use().
|
inlinenoexcept |
Number of counter columns (hash buckets per row).
| none |
Definition at line 261 of file count-min-sketch.H.
References Aleph::Count_Min_Sketch< T, CounterT >::w_.
Referenced by TEST().
|
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(), Aleph::Count_Min_Sketch< T, CounterT >::swap(), 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(), Aleph::Count_Min_Sketch< T, CounterT >::swap(), 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(), Aleph::Count_Min_Sketch< T, CounterT >::swap(), 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 >::swap(), 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 >::swap(), Aleph::Count_Min_Sketch< T, CounterT >::update(), and Aleph::Count_Min_Sketch< T, CounterT >::width().