Skip to content

Commit

Permalink
Replace bit shift with __builtin_ctzll in HyperLogLog
Browse files Browse the repository at this point in the history
  • Loading branch information
panzhongxian committed Apr 17, 2024
1 parent 804110a commit f9ef3b0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/hyperloglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ uint64_t MurmurHash64A (const void * key, int len, unsigned int seed) {
* of the pattern 000..1 of the element hash. As a side effect 'regp' is
* set to the register index this element hashes to. */
int hllPatLen(unsigned char *ele, size_t elesize, long *regp) {
uint64_t hash, bit, index;
uint64_t hash, index;
int count;

/* Count the number of zeroes starting from bit HLL_REGISTERS
Expand All @@ -448,12 +448,10 @@ int hllPatLen(unsigned char *ele, size_t elesize, long *regp) {
hash >>= HLL_P; /* Remove bits used to address the register. */
hash |= ((uint64_t)1<<HLL_Q); /* Make sure the loop terminates
and count will be <= Q+1. */
bit = 1;
count = 1; /* Initialized to 1 since we count the "00000...1" pattern. */
while((hash & bit) == 0) {
count++;
bit <<= 1;
}

/* Initialized to 1 since we count the "00000...1" pattern. */
count = __builtin_ctzll(hash) + 1;

*regp = (int) index;
return count;
}
Expand Down

0 comments on commit f9ef3b0

Please sign in to comment.