From 1c88c5941b2392d3592583f8e99a9c05c8d0b2e2 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 28 Mar 2014 12:15:39 +0100 Subject: [PATCH] HLL_(SET|GET)_REGISTER types fixed. --- src/hyperloglog.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hyperloglog.c b/src/hyperloglog.c index 2b307a703..2b722c393 100644 --- a/src/hyperloglog.c +++ b/src/hyperloglog.c @@ -149,25 +149,27 @@ /* Store the value of the register at position 'regnum' into variable 'target'. * 'p' is an array of unsigned bytes. */ #define HLL_GET_REGISTER(target,p,regnum) do { \ + uint8_t *_p = (uint8_t*) p; \ int _byte = regnum*REDIS_HLL_BITS/8; \ int _leftshift = regnum*REDIS_HLL_BITS&7; \ int _rightshift = 8 - _leftshift; \ - target = ((p[_byte] << _leftshift) | \ - (p[_byte+1] >> _rightshift)) & \ + target = ((_p[_byte] << _leftshift) | \ + (_p[_byte+1] >> _rightshift)) & \ ((1<> _leftshift; \ - p[_byte+1] &= ~(m2 << _rightshift); \ - p[_byte+1] |= val << _rightshift; \ + uint8_t m1 = 255, m2 = REDIS_HLL_REGISTER_MAX; \ + _p[_byte] &= m1 << _rightshift; \ + _p[_byte] |= val >> _leftshift; \ + _p[_byte+1] &= ~(m2 << _rightshift); \ + _p[_byte+1] |= val << _rightshift; \ } while(0) /* ========================= HyperLogLog algorithm ========================= */