Add ndpi_hll_reset() API call
Fixes bug in ndpi_data_window_average() with zero points
This commit is contained in:
@@ -1059,6 +1059,7 @@ extern "C" {
|
|||||||
/* Memory lifecycle */
|
/* Memory lifecycle */
|
||||||
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits);
|
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits);
|
||||||
void ndpi_hll_destroy(struct ndpi_hll *hll);
|
void ndpi_hll_destroy(struct ndpi_hll *hll);
|
||||||
|
void ndpi_hll_reset(struct ndpi_hll *hll);
|
||||||
|
|
||||||
/* Add values */
|
/* Add values */
|
||||||
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len);
|
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len);
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
|
|||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
|
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
|
||||||
|
|
||||||
|
if(n == 0)
|
||||||
|
return(0);
|
||||||
|
|
||||||
for(i=0; i<n; i++)
|
for(i=0; i<n; i++)
|
||||||
sum += s->values[i];
|
sum += s->values[i];
|
||||||
|
|
||||||
@@ -228,6 +231,10 @@ void ndpi_hll_destroy(struct ndpi_hll *hll) {
|
|||||||
hll_destroy(hll);
|
hll_destroy(hll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len) {
|
||||||
hll_add(hll, (const void *)data, data_len);
|
hll_add(hll, (const void *)data, data_len);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
@@ -67,6 +67,10 @@ void hll_destroy(struct ndpi_hll *hll) {
|
|||||||
hll->registers = NULL;
|
hll->registers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
static __inline void _hll_add_hash(struct ndpi_hll *hll, u_int32_t hash) {
|
||||||
u_int32_t index = hash >> (32 - hll->bits);
|
u_int32_t index = hash >> (32 - hll->bits);
|
||||||
u_int8_t rank = _hll_rank(hash, hll->bits);
|
u_int8_t rank = _hll_rank(hash, hll->bits);
|
||||||
|
|||||||
Reference in New Issue
Block a user