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); --- src/lib/ndpi_analyze.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/lib/ndpi_analyze.c') diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index f648e92ae..2d7e11abc 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -200,8 +200,36 @@ float ndpi_data_ratio(u_int32_t sent, u_int32_t rcvd) { return((s == 0) ? 0 : (d/s)); } +/* ********************************************************************************* */ + const char* ndpi_data_ratio2str(float ratio) { if(ratio < -0.2) return("Download"); else if(ratio > 0.2) return("Upload"); else return("Mixed"); } + +/* ********************************************************************************* */ +/* ********************************************************************************* */ + +#include "third_party/src/hll/hll.c" +#include "third_party/src/hll/MurmurHash3.c" + +int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits) { + return(hll_init(hll, bits)); +} + +void ndpi_hll_destroy(struct ndpi_hll *hll) { + hll_destroy(hll); +} + +void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len) { + hll_add(hll, (const void *)data, data_len); +} + +void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) { + hll_add(hll, (const void *)&value, sizeof(value)); +} + +double ndpi_hll_count(struct ndpi_hll *hll) { + return(hll_count(hll)); +} -- cgit v1.2.3