diff options
author | Luca Deri <deri@ntop.org> | 2020-06-10 23:43:35 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2020-06-10 23:43:35 +0200 |
commit | 60aaa80570b48b15c14c2a5133d9b73f7578b21a (patch) | |
tree | 9615961ce54a59adb3ed993f58d5f125a58380b4 /example/ndpiReader.c | |
parent | 0b9e46e65a8be9b30de96ec2e9f6061e2b4034b8 (diff) |
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);
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r-- | example/ndpiReader.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 3409500ef..fd55c3290 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -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(); |