Skip to content

Commit 9a045ad

Browse files
capture more failures, leave GCS2 broken
1 parent 9cac300 commit 9a045ad

File tree

8 files changed

+56
-49
lines changed

8 files changed

+56
-49
lines changed

fastfilter/src/main/java/org/fastfilter/bloom/count/SuccinctCountingBlockedBloomRanked.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void add(long key) {
8989
if (a2 != a1) {
9090
increment(start, a2);
9191
}
92-
int second = start + 1 + (int) (hash >>> 60);
92+
int second = start + (int) (hash >>> 60);
9393
int a3 = (int) ((hash >> 12) & 63);
9494
int a4 = (int) ((hash >> 18) & 63);
9595
increment(second, a3);
@@ -114,7 +114,7 @@ public void remove(long key) {
114114
if (a2 != a1) {
115115
decrement(start, a2);
116116
}
117-
int second = start + 1 + (int) (hash >>> 60);
117+
int second = start + (int) (hash >>> 60);
118118
int a3 = (int) ((hash >> 12) & 63);
119119
int a4 = (int) ((hash >> 18) & 63);
120120
decrement(second, a3);
@@ -144,7 +144,7 @@ public boolean mayContain(long key) {
144144
int start = Hash.reduce((int) hash, buckets);
145145
hash = hash ^ Long.rotateLeft(hash, 32);
146146
long a = data[start];
147-
long b = data[start + 1 + (int) (hash >>> 60)];
147+
long b = data[start + (int) (hash >>> 60)];
148148
long m1 = (1L << hash) | (1L << (hash >> 6));
149149
long m2 = (1L << (hash >> 12)) | (1L << (hash >> 18));
150150
return ((m1 & a) == m1) && ((m2 & b) == m2);

fastfilter/src/main/java/org/fastfilter/cuckoo/Cuckoo16.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static Cuckoo16 construct(long[] keys) {
3939

4040
public Cuckoo16(int capacity) {
4141
// bucketCount needs to be even for bucket2 to work
42-
bucketCount = (int) Math.ceil((double) capacity / ENTRIES_PER_BUCKET) / 2 * 2;
42+
bucketCount = Math.max(1, (int) Math.ceil((double) capacity / ENTRIES_PER_BUCKET) / 2 * 2);
4343
this.data = new long[bucketCount];
4444
this.seed = Hash.randomSeed();
4545
}

fastfilter/src/main/java/org/fastfilter/cuckoo/Cuckoo8.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static Cuckoo8 construct(long[] keys) {
3939

4040
public Cuckoo8(int capacity) {
4141
// bucketCount needs to be even for bucket2 to work
42-
bucketCount = (int) Math.ceil((double) capacity / ENTRIES_PER_BUCKET) / 2 * 2;
42+
bucketCount = Math.max(1, (int) Math.ceil((double) capacity / ENTRIES_PER_BUCKET) / 2 * 2);
4343
this.data = new int[bucketCount];
4444
this.seed = Hash.randomSeed();
4545
}

fastfilter/src/main/java/org/fastfilter/xor/XorSimple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ boolean map(long[] keys, long seed, long[] stack) {
5151
}
5252
}
5353
int si = 0;
54-
while (si < 2 * keys.length) {
54+
while (si < 2 * keys.length && qi > 0) {
5555
int i = Q[--qi];
5656
if (C[i] == 1) {
5757
long x = H[i];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.fastfilter;
2+
3+
import org.fastfilter.utils.Hash;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.junit.runners.Parameterized;
7+
8+
import static org.fastfilter.FilterType.*;
9+
import static org.junit.Assert.assertTrue;
10+
11+
@RunWith(Parameterized.class)
12+
public class RegressionTests {
13+
14+
15+
@Parameterized.Parameters(name = "{0}/{1}/*")
16+
public static Object[][] regressionCases() {
17+
return new Object[][] {
18+
{BLOCKED_BLOOM, 872153271794238865L, new long[]{1, 2, 3}},
19+
{SUCCINCT_COUNTING_BLOCKED_BLOOM_RANKED, -401700599714690558L, new long[]{1, 2, 3}},
20+
{SUCCINCT_COUNTING_BLOCKED_BLOOM, 6049486880293779298L, new long[]{1, 2, 3}},
21+
// actual this one is impossible to reproduce because of the volatile seed
22+
{XOR_SIMPLE, 6831634639270950343L, new long[]{1, 2, 3}},
23+
{CUCKOO_8, 6335419348330489927L, new long[]{1, 2, 3}},
24+
{CUCKOO_16, -9087718164446355442L, new long[]{1, 2, 3}},
25+
{GCS2, -2130647756636796307L, new long[]{1, 2, 3}}
26+
};
27+
}
28+
29+
private final FilterType type;
30+
private final long seed;
31+
private final long[] keys;
32+
33+
public RegressionTests(FilterType type, long seed, long[] keys) {
34+
this.type = type;
35+
this.seed = seed;
36+
this.keys = keys;
37+
}
38+
39+
@Test
40+
public void regressionTest() {
41+
Hash.setSeed(seed);
42+
Filter filter = type.construct(keys, 8);
43+
for (long key : keys) {
44+
assertTrue(filter.mayContain(key));
45+
}
46+
}
47+
}

fastfilter/src/test/java/org/fastfilter/SimpleFuzzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public void fuzzTest() {
2121
seed = ThreadLocalRandom.current().nextLong();
2222
Hash.setSeed(seed);
2323
Filter filter = type.construct(keys, 8);
24-
assertTrue(filter.mayContain(1));
25-
assertTrue(filter.mayContain(2));
26-
assertTrue(filter.mayContain(3));
24+
assertTrue(seed + "/" + type, filter.mayContain(1));
25+
assertTrue(seed + "/" + type, filter.mayContain(2));
26+
assertTrue(seed + "/" + type, filter.mayContain(3));
2727
}
2828
} catch (Exception e) {
2929
System.out.println(seed + "/" + type);

fastfilter/src/test/java/org/fastfilter/bloom/BlockedBloomTest.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

fastfilter/src/test/java/org/fastfilter/bloom/count/SuccinctCountingBlockedBloomTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)