Skip to content

Commit e4aca7b

Browse files
committed
Succinct counting Bloom filter: tiny improvment
1 parent 5b5a198 commit e4aca7b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/counting_bloom.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ inline int select64(uint64_t x, int n) {
2424
// with this, "add" is around 310 ns/key at 10000000 keys
2525
// from http://bitmagic.io/rank-select.html
2626
// https://github.com/Forceflow/libmorton/issues/6
27-
// This is a rather unusual usage of the bit deposit operation,
27+
// This is a rather unusual usage of the pdep (bit deposit) operation,
2828
// as we use the x as the mask, and we use n as the value.
29-
// We deposit (move) the bits of x = 1 << n to the locations
29+
// We deposit (move) the bits of 1 << n to the locations
3030
// defined by x.
3131
uint64_t d = _pdep_u64(1ULL << n, x);
3232
// and now we count the trailing zeroes, to find out
3333
// where the '1' was deposited
3434
return __builtin_ctzl(d);
3535
// return _tzcnt_u64(d);
3636
#else
37-
// slow implementation
37+
// alternative implementation
3838
// with this, "add" is around 680 ns/key at 10000000 keys
3939
for(int i = 0; i < 64; i++) {
4040
if ((x & 1) == 1) {
@@ -50,7 +50,7 @@ inline int select64(uint64_t x, int n) {
5050

5151
inline int numberOfLeadingZeros64(uint64_t x) {
5252
// If x is 0, the result is undefined.
53-
return x == 0 ? 64 : __builtin_clzl(x);
53+
return __builtin_clzl(x);
5454
}
5555

5656
enum Status {
@@ -186,7 +186,6 @@ void SuccinctCountingBloomFilter<ItemType, bits_per_item, branchless, HashFamily
186186
Increment(size_t group, int bit) {
187187
// realCount[(group << 6) + bit]++;
188188
uint64_t m = data[group];
189-
int d = (m >> bit) & 1;
190189
uint64_t c = counts[group];
191190
if ((c & 0xc000000000000000L) != 0) {
192191
// an overflow entry, or overflowing now
@@ -226,6 +225,7 @@ void SuccinctCountingBloomFilter<ItemType, bits_per_item, branchless, HashFamily
226225
data[group] |= 1ULL << bit;
227226
int bitsBefore = bitCount64(m & (0xffffffffffffffffL >> (63 - bit)));
228227
int before = select64((c << 1) | 1, bitsBefore);
228+
int d = (m >> bit) & 1;
229229
int insertAt = before - d;
230230
uint64_t mask = (1ULL << insertAt) - 1;
231231
uint64_t left = c & ~mask;

0 commit comments

Comments
 (0)