From 60aaa80570b48b15c14c2a5133d9b73f7578b21a Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Wed, 10 Jun 2020 23:43:35 +0200 Subject: 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); --- example/ndpiReader.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'example') 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(); -- cgit v1.2.3