Skip to content

Commit 8100b1c

Browse files
committed
Avoid uint128 (optional)
1 parent 88cc01c commit 8100b1c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/xorfilter/xor_fuse_filter.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ inline uint32_t reduce(uint32_t hash, uint32_t n) {
3131
return (uint32_t) (((uint64_t) hash * n) >> 32);
3232
}
3333

34+
// #define H128
3435
const size_t segmentLengthBits = 13;
3536
const size_t segmentLength = 1 << segmentLengthBits;
3637

3738
size_t getHashFromHash(uint64_t hash, int index, int segmentCount) {
39+
#ifdef H128
3840
__uint128_t x = (__uint128_t) hash * (__uint128_t) segmentCount;
3941
int seg = (uint64_t)(x >> 64);
40-
int h = (seg + index) * segmentLength + (size_t)((hash >> (index * segmentLengthBits)) & (segmentLength - 1));
42+
uint64_t hh = hash;
43+
#else
44+
uint64_t seg = reduce(hash, segmentCount);
45+
uint64_t hh = (hash ^ (hash >> 32));
46+
#endif
47+
int h = (seg + index) * segmentLength + (size_t)((hh >> (index * segmentLengthBits)) & (segmentLength - 1));
4148
return h;
4249
}
4350

@@ -54,7 +61,8 @@ class XorFuseFilter {
5461
HashFamily* hasher;
5562

5663
inline FingerprintType fingerprint(const uint64_t hash) const {
57-
return (FingerprintType) hash ^ (hash >> 32);
64+
return (FingerprintType) hash;
65+
// return (FingerprintType) hash ^ (hash >> 32);
5866
}
5967

6068
explicit XorFuseFilter(const size_t size) {
@@ -306,11 +314,17 @@ Status XorFuseFilter<ItemType, FingerprintType, HashFamily>::Contain(
306314
const ItemType &key) const {
307315
uint64_t hash = (*hasher)(key);
308316
FingerprintType f = fingerprint(hash);
317+
#ifdef H128
309318
__uint128_t x = (__uint128_t) hash * (__uint128_t) segmentCount;
310319
int seg = (uint64_t)(x >> 64);
311-
int h0 = (seg + 0) * segmentLength + (size_t)((hash >> (0 * segmentLengthBits)) & (segmentLength - 1));
312-
int h1 = (seg + 1) * segmentLength + (size_t)((hash >> (1 * segmentLengthBits)) & (segmentLength - 1));
313-
int h2 = (seg + 2) * segmentLength + (size_t)((hash >> (2 * segmentLengthBits)) & (segmentLength - 1));
320+
uint64_t hh = hash;
321+
#else
322+
uint64_t seg = reduce(hash, segmentCount);
323+
uint64_t hh = (hash ^ (hash >> 32));
324+
#endif
325+
int h0 = (seg + 0) * segmentLength + (size_t)((hh >> (0 * segmentLengthBits)) & (segmentLength - 1));
326+
int h1 = (seg + 1) * segmentLength + (size_t)((hh >> (1 * segmentLengthBits)) & (segmentLength - 1));
327+
int h2 = (seg + 2) * segmentLength + (size_t)((hh >> (2 * segmentLengthBits)) & (segmentLength - 1));
314328
f ^= fingerprints[h0] ^ fingerprints[h1] ^ fingerprints[h2];
315329
return f == 0 ? Ok : NotFound;
316330
}

0 commit comments

Comments
 (0)