Added HyperLogLog cardinality estimator API calls

/* Memory lifecycle */
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits);
void ndpi_hll_destroy(struct ndpi_hll *hll);

/* Add values */
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len);
void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) ;

/* Get cardinality estimation */
double ndpi_hll_count(struct ndpi_hll *hll);
This commit is contained in:
Luca Deri
2020-06-10 23:43:35 +02:00
parent 0b9e46e65a
commit 60aaa80570
9 changed files with 296 additions and 0 deletions
+18
View File
@@ -3048,6 +3048,23 @@ void test_lib() {
/* *********************************************** */
static void hllUnitTest() {
struct ndpi_hll h;
u_int8_t bits = 8; /* >= 4, <= 16 */
u_int32_t i;
assert(ndpi_hll_init(&h, bits) == 0);
for(i=0; i<21320; i++)
ndpi_hll_add_number(&h, i);
/* printf("Count estimate: %f\n", ndpi_hll_count(&h)); */
ndpi_hll_destroy(&h);
}
/* *********************************************** */
static void bitmapUnitTest() {
u_int32_t val, i, j;
@@ -3341,6 +3358,7 @@ int orginal_main(int argc, char **argv) {
}
/* Internal checks */
hllUnitTest();
bitmapUnitTest();
automataUnitTest();
serializerUnitTest();