Skip to content

Commit d90cbf3

Browse files
committed
Minor conflict due to comments.
2 parents 1bfd3ff + 8c7c8b3 commit d90cbf3

File tree

4 files changed

+31
-45
lines changed

4 files changed

+31
-45
lines changed

src/xorfilter.h

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,8 @@ inline uint32_t reduce(uint32_t hash, uint32_t n) {
3232
}
3333

3434
size_t getHashFromHash(uint64_t hash, int index, int blockLength) {
35-
uint32_t r;
36-
switch(index) {
37-
case 0:
38-
r = (uint32_t) (hash);
39-
break;
40-
case 1:
41-
r = (uint32_t) rotl64(hash, 21);
42-
break;
43-
default:
44-
r = (uint32_t) rotl64(hash, 42);
45-
break;
46-
}
47-
r = reduce(r, blockLength);
48-
r = r + index * blockLength;
49-
return (size_t) r;
35+
uint32_t r = rotl64(hash, index * 21);
36+
return (size_t) reduce(r, blockLength) + index * blockLength;
5037
}
5138

5239
template <typename ItemType, typename FingerprintType,
@@ -68,7 +55,7 @@ class XorFilter {
6855
explicit XorFilter(const size_t size) {
6956
hasher = new HashFamily();
7057
this->size = size;
71-
this->arrayLength = 3 + 1.23 * size;
58+
this->arrayLength = 32 + 1.23 * size;
7259
this->blockLength = arrayLength / 3;
7360
fingerprints = new FingerprintType[arrayLength]();
7461
std::fill_n(fingerprints, arrayLength, 0);
@@ -154,41 +141,40 @@ Status XorFilter<ItemType, FingerprintType, HashFamily>::AddAll(
154141
delete[] tmpc;
155142

156143
reverseOrderPos = 0;
144+
157145
int* alone = new int[arrayLength];
158146
int alonePos = 0;
147+
for (int i = 0; i < arrayLength; i++) {
148+
if (t2vals[i].t2count == 1) {
149+
alone[alonePos++] = i;
150+
}
151+
}
159152
reverseOrderPos = 0;
160-
for(size_t nextAloneCheck = 0; nextAloneCheck < arrayLength;) {
161-
while (nextAloneCheck < arrayLength) {
162-
if (t2vals[nextAloneCheck].t2count == 1) {
163-
alone[alonePos++] = nextAloneCheck;
164-
}
165-
nextAloneCheck++;
153+
while (alonePos > 0 && reverseOrderPos < size) {
154+
int i = alone[--alonePos];
155+
if (t2vals[i].t2count == 0) {
156+
continue;
166157
}
167-
while (alonePos > 0) {
168-
int i = alone[--alonePos];
169-
if (t2vals[i].t2count == 0) {
170-
continue;
171-
}
172-
long hash = t2vals[i].t2;
173-
uint8_t found = -1;
174-
for (int hi = 0; hi < 3; hi++) {
175-
int h = getHashFromHash(hash, hi, blockLength);
176-
int newCount = -- t2vals[h].t2count;
177-
if (newCount == 0) {
178-
found = (uint8_t) hi;
179-
} else {
180-
if (newCount == 1) {
181-
alone[alonePos++] = h;
182-
}
183-
t2vals[h].t2 ^= hash;
158+
long hash = t2vals[i].t2;
159+
uint8_t found = -1;
160+
for (int hi = 0; hi < 3; hi++) {
161+
int h = getHashFromHash(hash, hi, blockLength);
162+
int newCount = --t2vals[h].t2count;
163+
if (newCount == 0) {
164+
found = (uint8_t) hi;
165+
} else {
166+
if (newCount == 1) {
167+
alone[alonePos++] = h;
184168
}
169+
t2vals[h].t2 ^= hash;
185170
}
186-
reverseOrder[reverseOrderPos] = hash;
187-
reverseH[reverseOrderPos] = found;
188-
reverseOrderPos++;
189171
}
172+
reverseOrder[reverseOrderPos] = hash;
173+
reverseH[reverseOrderPos] = found;
174+
reverseOrderPos++;
190175
}
191176
delete [] alone;
177+
192178
if (reverseOrderPos == size) {
193179
break;
194180
}

src/xorfilter_2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class XorFilter2 {
7171
explicit XorFilter2(const size_t size) {
7272
hasher = new HashFamily();
7373
this->size = size;
74-
this->arrayLength = 3 + 1.23 * size;
74+
this->arrayLength = 32 + 1.23 * size;
7575
this->blockLength = arrayLength / 3;
7676
fingerprints = new FingerprintStorageType(arrayLength);
7777
}

src/xorfilter_2n.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class XorFilter2n {
6666
explicit XorFilter2n(const size_t size) {
6767
hasher = new HashFamily();
6868
this->size = size;
69-
this->arrayLength = 3 + 1.23 * size;
69+
this->arrayLength = 32 + 1.23 * size;
7070
this->blockLength = 1;
7171
while (this->blockLength < arrayLength / 3) {
7272
this->blockLength *= 2;

src/xorfilter_plus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class XorFilterPlus {
179179
explicit XorFilterPlus(const size_t size) {
180180
hasher = new HashFamily();
181181
this->size = size;
182-
this->arrayLength = 3 + 1.23 * size;
182+
this->arrayLength = 32 + 1.23 * size;
183183
this->blockLength = arrayLength / 3;
184184
}
185185

0 commit comments

Comments
 (0)