diff options
author | antirez <antirez@gmail.com> | 2016-12-16 10:58:19 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-12-16 11:07:30 +0100 |
commit | 0224be881124343bd4ad7696848f9fd6c51b11d0 (patch) | |
tree | 3e39afa666f98525de63621154eb70e4b487556b /src/hyperloglog.c | |
parent | 47dea01c853e075ee591ded515eecffefd535425 (diff) | |
download | redis-0224be881124343bd4ad7696848f9fd6c51b11d0.tar.gz |
Use llroundl() before converting loglog-beta output to integer.
Otherwise for small cardinalities the algorithm will output something
like, for example, 4.99 for a candinality of 5, that will be converted
to 4 producing a huge error.
Diffstat (limited to 'src/hyperloglog.c')
-rw-r--r-- | src/hyperloglog.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/hyperloglog.c b/src/hyperloglog.c index 67a928729..6dde6298a 100644 --- a/src/hyperloglog.c +++ b/src/hyperloglog.c @@ -993,9 +993,9 @@ uint64_t hllCount(struct hllhdr *hdr, int *invalid) { } else { serverPanic("Unknown HyperLogLog encoding in hllCount()"); } - + if(server.hll_use_loglogbeta) { - /* For loglog-beta there is a single formula to compute + /* For loglog-beta there is a single formula to compute * cardinality for the enture range */ @@ -1008,8 +1008,8 @@ uint64_t hllCount(struct hllhdr *hdr, int *invalid) { 0.03738027*pow(zl,5) + -0.005384159*pow(zl,6) + 0.00042419*pow(zl,7); - - E = alpha*m*(m-ez)*(1/(E+beta)); + + E = llroundl(alpha*m*(m-ez)*(1/(E+beta))); } else { /* Muliply the inverse of E for alpha_m * m^2 to have the raw estimate. */ E = (1/E)*alpha*m*m; |