redis中hyperloglog的实现问题

62lalag4  于 2021-06-08  发布在  Redis
关注(0)|答案(0)|浏览(264)

我正在读redis中hyperloglog的实现。有一个函数 hllPatLen ```
int hllPatLen(unsigned char *ele, size_t elesize, long *regp) {
uint64_t hash, bit, index;
int count;

/* Count the number of zeroes starting from bit HLL_REGISTERS
 * (that is a power of two corresponding to the first bit we don't use
 * as index). The max run can be 64-P+1 bits.
 *
 * Note that the final "1" ending the sequence of zeroes must be
 * included in the count, so if we find "001" the count is 3, and
 * the smallest count possible is no zeroes at all, just a 1 bit
 * at the first position, that is a count of 1.
 *
 * This may sound like inefficient, but actually in the average case
 * there are high probabilities to find a 1 after a few iterations. */
hash = MurmurHash64A(ele,elesize,0xadc83b19ULL);
index = hash & HLL_P_MASK; /* Register index. */
hash |= ((uint64_t)1<<63); /* Make sure the loop terminates. */
bit = HLL_REGISTERS; /* First bit not used to address the register. */
count = 1; /* Initialized to 1 since we count the "00000...1" pattern. */
while((hash & bit) == 0) {
    count++;
    bit <<= 1;
}
*regp = (int) index;
return count;

}

我感兴趣的是 `count` 是计算出来的。我认为代码实际上是最右边的1,因为当我打印的时候 `hash` 出去,我找到一个 `"100"` 模式将导致 `count = 3` .
评论说 `"001"` 的计数是3,但是我认为应该是1,因为它的代码实际上是从右边而不是左边计数位。
我在这里犯错误了吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题