diff options
author | Luca Deri <deri@ntop.org> | 2022-08-17 16:25:10 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2022-08-17 16:25:10 +0200 |
commit | a53f4765858285f520b8a2645da80aed2b1487b1 (patch) | |
tree | f86a674351755e578c1955cb5a5bf4f9c0699490 /src | |
parent | 82c83ef75e3a6a88dcfb9a9ad1bc1b888d893751 (diff) |
Modified definition of hll_add
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_api.h.in | 4 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 9 | ||||
-rw-r--r-- | src/lib/third_party/include/hll.h | 8 | ||||
-rw-r--r-- | src/lib/third_party/src/hll/hll.c | 16 |
4 files changed, 22 insertions, 15 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 9064ac627..2e8690203 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1692,8 +1692,8 @@ extern "C" { void ndpi_hll_reset(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) ; + int ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len); + int ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) ; /* Get cardinality estimation */ double ndpi_hll_count(struct ndpi_hll *hll); diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index a3c518051..2b5d46a90 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -290,12 +290,13 @@ void ndpi_hll_reset(struct ndpi_hll *hll) { hll_reset(hll); } -void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len) { - hll_add(hll, (const void *)data, data_len); +int ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len) { + return(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)); +/* 1 = rank changed, 0 = no changes in rank */ +int ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) { + return(hll_add(hll, (const void *)&value, sizeof(value))); } double ndpi_hll_count(struct ndpi_hll *hll) { diff --git a/src/lib/third_party/include/hll.h b/src/lib/third_party/include/hll.h index 00975ec36..4b094a63e 100644 --- a/src/lib/third_party/include/hll.h +++ b/src/lib/third_party/include/hll.h @@ -21,7 +21,7 @@ */ -extern int hll_init(struct ndpi_hll *hll, u_int8_t bits); -extern void hll_destroy(struct ndpi_hll *hll); -extern void hll_add(struct ndpi_hll *hll, const void *buf, size_t size); -extern double hll_count(const struct ndpi_hll *hll); +extern int hll_init(struct ndpi_hll *hll, u_int8_t bits); +extern void hll_destroy(struct ndpi_hll *hll); +extern int hll_add(struct ndpi_hll *hll, const void *buf, size_t size); +extern double hll_count(const struct ndpi_hll *hll); diff --git a/src/lib/third_party/src/hll/hll.c b/src/lib/third_party/src/hll/hll.c index c526c6af0..ad7284411 100644 --- a/src/lib/third_party/src/hll/hll.c +++ b/src/lib/third_party/src/hll/hll.c @@ -97,20 +97,26 @@ void hll_reset(struct ndpi_hll *hll) { memset(hll->registers, 0, hll->size); } -static __inline void _hll_add_hash(struct ndpi_hll *hll, u_int32_t hash) { +/* Return: 0 = nothing changed, 1 = ranking changed */ +static __inline int _hll_add_hash(struct ndpi_hll *hll, u_int32_t hash) { if(hll->registers) { u_int32_t index = hash >> (32 - hll->bits); /* Use the first 'hll->bits' bits as bucket index */ u_int8_t rank = _hll_rank(hash, hll->bits); /* Count the number of leading 0 */ - if(rank > hll->registers[index]) - hll->registers[index] = rank; /* Store the largest number of lesding zeros for the bucket */ + if(rank > hll->registers[index]) { + hll->registers[index] = rank; /* Store the largest number of lesding zeros for the bucket */ + return(1); + } } + + return(0); } -void hll_add(struct ndpi_hll *hll, const void *buf, size_t size) { +/* Return: 0 = nothing changed, 1 = ranking changed */ +int hll_add(struct ndpi_hll *hll, const void *buf, size_t size) { u_int32_t hash = MurmurHash3_x86_32((const char *)buf, (u_int32_t)size, 0x5f61767a); - _hll_add_hash(hll, hash); + return(_hll_add_hash(hll, hash)); } double hll_count(const struct ndpi_hll *hll) { |