Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace bit shift with __builtin_ctzll in HyperLogLog #13218

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/hyperloglog.c
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. */
panzhongxian marked this conversation as resolved.
Show resolved Hide resolved
count = __builtin_ctzll(hash) + 1;

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