Skip to content

Commit f49dc79

Browse files
committed
Counting Bloom filters changes
1 parent 7af6b52 commit f49dc79

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/main/java/org/fastfilter/bloom/CountingBloom.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void add(long key) {
5252
int a = (int) (hash >>> 32);
5353
int b = (int) hash;
5454
for (int i = 0; i < k; i++) {
55-
int index = Hash.reduce(a, arraySize * 16);
56-
counts[index / 16] += getBit(index);
55+
int index = Hash.reduce(a, arraySize << 4);
56+
counts[index >>> 4] += getBit(index);
5757
a += b;
5858
}
5959
}
@@ -69,14 +69,14 @@ public void remove(long key) {
6969
int a = (int) (hash >>> 32);
7070
int b = (int) hash;
7171
for (int i = 0; i < k; i++) {
72-
int index = Hash.reduce(a, arraySize * 16);
73-
counts[index / 16] -= getBit(index);
72+
int index = Hash.reduce(a, arraySize << 4);
73+
counts[index >>> 4] -= getBit(index);
7474
a += b;
7575
}
7676
}
7777

7878
private static long getBit(int index) {
79-
return 1L << (index * 4);
79+
return 1L << (index << 2);
8080
}
8181

8282
@Override
@@ -85,8 +85,8 @@ public boolean mayContain(long key) {
8585
int a = (int) (hash >>> 32);
8686
int b = (int) hash;
8787
for (int i = 0; i < k; i++) {
88-
int index = Hash.reduce(a, arraySize * 16);
89-
if ((counts[index / 16] & (0xf * getBit(index))) == 0) {
88+
int index = Hash.reduce(a, arraySize << 4);
89+
if (((counts[index >>> 4] >>> (index << 2)) & 0xf) == 0) {
9090
return false;
9191
}
9292
a += b;

src/main/java/org/fastfilter/bloom/SuccinctCountingBloom.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.fastfilter.bloom;
22

3+
import java.math.BigInteger;
4+
35
import org.fastfilter.Filter;
46
import org.fastfilter.utils.Hash;
57

@@ -73,7 +75,7 @@ public long getBitCount() {
7375
arraySize = (int) ((bits + 63) / 64);
7476
data = new BitField(64 * (arraySize + 10));
7577
counts = new BitField(64 * (arraySize + 10));
76-
overflow = new long[100 + arraySize / 100 * 4];
78+
overflow = new long[100 + arraySize / 100 * 12];
7779
for (int i = 0; i < overflow.length; i += 4) {
7880
overflow[i] = i + 4;
7981
}
@@ -91,7 +93,7 @@ public void add(long key) {
9193
int a = (int) (hash >>> 32);
9294
int b = (int) hash;
9395
for (int i = 0; i < k; i++) {
94-
int index = Hash.reduce(a, arraySize) * 64 + (a & 63);
96+
int index = (Hash.reduce(a, arraySize) << 6) + (a & 63);
9597
if (VERIFY_COUNTS) {
9698
realCounts[index]++;
9799
}
@@ -111,7 +113,7 @@ public void remove(long key) {
111113
int a = (int) (hash >>> 32);
112114
int b = (int) hash;
113115
for (int i = 0; i < k; i++) {
114-
int index = Hash.reduce(a, arraySize) * 64 + (a & 63);
116+
int index = (Hash.reduce(a, arraySize) << 6) + (a & 63);
115117
if (VERIFY_COUNTS) {
116118
realCounts[index]--;
117119
}

0 commit comments

Comments
 (0)