Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
3610af42
Commit
3610af42
authored
Mar 28, 2014
by
antirez
Browse files
HLL_(SET|GET)_REGISTER types fixed.
parent
c7344144
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
3610af42
...
@@ -149,25 +149,27 @@
...
@@ -149,25 +149,27 @@
/* Store the value of the register at position 'regnum' into variable 'target'.
/* Store the value of the register at position 'regnum' into variable 'target'.
* 'p' is an array of unsigned bytes. */
* 'p' is an array of unsigned bytes. */
#define HLL_GET_REGISTER(target,p,regnum) do { \
#define HLL_GET_REGISTER(target,p,regnum) do { \
uint8_t *_p = (uint8_t*) p; \
int _byte = regnum*REDIS_HLL_BITS/8; \
int _byte = regnum*REDIS_HLL_BITS/8; \
int _leftshift = regnum*REDIS_HLL_BITS&7; \
int _leftshift = regnum*REDIS_HLL_BITS&7; \
int _rightshift = 8 - _leftshift; \
int _rightshift = 8 - _leftshift; \
target = ((p[_byte] << _leftshift) | \
target = ((
_
p[_byte] << _leftshift) | \
(p[_byte+1] >> _rightshift)) & \
(
_
p[_byte+1] >> _rightshift)) & \
((1<<REDIS_HLL_BITS)-1); \
((1<<REDIS_HLL_BITS)-1); \
} while(0)
} while(0)
/* Set the value of the register at position 'regnum' to 'val'.
/* Set the value of the register at position 'regnum' to 'val'.
* 'p' is an array of unsigned bytes. */
* 'p' is an array of unsigned bytes. */
#define HLL_SET_REGISTER(p,regnum,val) do { \
#define HLL_SET_REGISTER(p,regnum,val) do { \
uint8_t *_p = (uint8_t*) p; \
int _byte = regnum*REDIS_HLL_BITS/8; \
int _byte = regnum*REDIS_HLL_BITS/8; \
int _leftshift = regnum*REDIS_HLL_BITS&7; \
int _leftshift = regnum*REDIS_HLL_BITS&7; \
int _rightshift = 8 - _leftshift; \
int _rightshift = 8 - _leftshift; \
u
nsigned in
t m1 = 255, m2 = REDIS_HLL_REGISTER_MAX; \
u
int8_
t m1 = 255, m2 = REDIS_HLL_REGISTER_MAX; \
p[_byte] &= m1 << _rightshift; \
_
p[_byte] &= m1 << _rightshift; \
p[_byte] |= val >> _leftshift; \
_
p[_byte] |= val >> _leftshift; \
p[_byte+1] &= ~(m2 << _rightshift); \
_
p[_byte+1] &= ~(m2 << _rightshift); \
p[_byte+1] |= val << _rightshift; \
_
p[_byte+1] |= val << _rightshift; \
} while(0)
} while(0)
/* ========================= HyperLogLog algorithm ========================= */
/* ========================= HyperLogLog algorithm ========================= */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment