Skip to content

Commit 4a01f70

Browse files
committed
Xor filter: add a 10 bit variant (for comparison; it wastes space)
1 parent bc14aef commit 4a01f70

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

benchmarks/bulk-insert-and-query.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,13 @@ int main(int argc, char * argv[]) {
782782
cout << setw(NAME_WIDTH) << "Xor-14" << cf << endl;
783783
}
784784

785+
if (algorithmId == 24 || algorithmId < 0) {
786+
auto cf = FilterBenchmark<
787+
XorFilter2<uint64_t, uint32_t, UInt10Array, SimpleMixSplit>>(
788+
add_count, to_add, to_lookup, seed);
789+
cout << setw(NAME_WIDTH) << "Xor10.x" << cf << endl;
790+
}
791+
785792

786793
// broken algorithms (don't always find all key)
787794
/*

src/nbit_array.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,43 @@ class UInt12Array {
9191
}
9292
};
9393

94+
class UInt10Array {
95+
size_t byteCount;
96+
uint64_t* data;
97+
public:
98+
UInt10Array(size_t size) {
99+
byteCount = size / 6 * 8;
100+
data = new uint64_t[(byteCount + 7) / 8]();
101+
}
102+
~UInt10Array() {
103+
delete[] data;
104+
}
105+
// the returned value may contain other high-order bits;
106+
// call mask() to clear them
107+
inline uint32_t get(size_t index) {
108+
uint64_t x = data[index / 6];
109+
// return (x >> (10 * (index % 6)));
110+
int m = 3 * (index % 2) + (index % 3);
111+
return x >> (10 * m);
112+
}
113+
void bulkSet(uint16_t* source, size_t length) {
114+
for(size_t index = 0; index < length; index++) {
115+
set(index, source[index]);
116+
}
117+
}
118+
inline void set(size_t index, uint32_t value) {
119+
// data[index / 6] |= ((uint64_t) value & 0x3ff) << (10 * (index % 6));
120+
int m = 3 * (index % 2) + (index % 3);
121+
data[index / 6] |= ((uint64_t) value & 0x3ff) << (10 * m);
122+
}
123+
inline uint32_t mask(uint32_t fingerprint) {
124+
return fingerprint & 0x3ff;
125+
}
126+
size_t getByteCount() {
127+
return byteCount;
128+
}
129+
};
130+
94131
template <typename ItemType, size_t bitsPerEntry, uint32_t bitMask = (1 << bitsPerEntry) - 1>
95132
class NBitArray {
96133
size_t byteCount;

0 commit comments

Comments
 (0)