Count-min sketch https://en.wikipedia.org/wiki/Count%E2%80%93min_sketch.
More...
#include <stdint.h>
Go to the source code of this file.
sa_cm_sketch* sa_create_cms |
( |
double |
epsilon, |
|
|
double |
delta |
|
) |
| |
Allocate and initialize the data structure.
- Parameters
-
epsilon | Approximation factor |
delta | Probability of failure |
- Returns
- Count-min sketch struct
int sa_deserialize_cms |
( |
sa_cm_sketch * |
cms, |
|
|
const char * |
buf, |
|
|
size_t |
len |
|
) |
| |
Restore the internal state from the serialized output.
- Parameters
-
cms | Count-min sketch struct |
buf | Buffer containing the output of serialize_cms |
len | Length of the buffer |
- Returns
- 0 = success 1 = invalid buffer length
Free the associated memory.
- Parameters
-
cms | Count-min sketch struct |
Zero out the data structure.
- Parameters
-
cms | Count-min sketch struct |
Return the total number of items added to the sketch.
- Parameters
-
cms | Count-min sketch struct |
- Returns
- size_t Number of items added to the sketch
uint32_t sa_point_query_cms |
( |
sa_cm_sketch * |
cms, |
|
|
void * |
item, |
|
|
size_t |
len |
|
) |
| |
Point query the frequency count of item.
- Parameters
-
cms | Count-min sketch struct |
item | Item to query |
len | Length of the item in bytes |
- Returns
- int Estimated count
Serialize the internal state to a buffer.
- Parameters
-
cms | Count-min sketch struct |
len | Length of the returned buffer |
- Returns
- char* Serialized representation MUST be freed by the caller
Return the total number of unique items added to the sketch.
- Parameters
-
cms | Count-min sketch struct |
- Returns
- size_t Number of unique items added to the sketch
uint32_t sa_update_cms |
( |
sa_cm_sketch * |
cms, |
|
|
void * |
item, |
|
|
size_t |
len, |
|
|
int |
n |
|
) |
| |
Increment/Decrement the Count-min sketch with the specified item and value.
- Parameters
-
cms | Count-min sketch struct |
item | Item to add |
len | Length of the item in bytes |
n | Number of items to add/remove |
- Returns
- int Estimated count