Skip to content

Commit 64b9e06

Browse files
committed
Minor tweaks.
1 parent 7d77a4c commit 64b9e06

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

.github/java.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Java 17 CI
2+
3+
on: [push,pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up JDK 17
12+
uses: actions/setup-java@v1
13+
with:
14+
java-version: 17
15+
- name: Build
16+
run: mvn build
17+
- name: Test
18+
run: mvn test

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public Xor16(long[] keys) {
5353
int h = getHash(k, seed, hi);
5454
t2[h] ^= k;
5555
if (t2count[h] > 120) {
56-
throw new IllegalArgumentException();
56+
// probably something wrong with the hash function
57+
// let us not crash the system:
58+
for(int i = 0; i < fingerprints.length; i++) {
59+
fingerprints[i] = (short)0xFFFF;
60+
}
61+
return;
5762
}
5863
t2count[h]++;
5964
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public Xor8(long[] keys) {
5959
t2[h] ^= k;
6060
if (t2count[h] > 120) {
6161
// probably something wrong with the hash function
62-
throw new IllegalArgumentException();
62+
// let us not crash the system:
63+
for(int i = 0; i < fingerprints.length; i++) {
64+
fingerprints[i] = (byte)0xFF;
65+
}
66+
return;
6367
}
6468
t2count[h]++;
6569
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ private void addAll(long[] keys) {
147147
// we have a possible counter overflow
148148
// this branch is never taken except if there is a problem in the hash code
149149
// in which case construction fails
150-
break;
150+
for(int i = 0; i < fingerprints.length; i++) {
151+
fingerprints[i] = (byte)0xFF;
152+
}
153+
return;
151154
}
152155

153156
reverseOrderPos = 0;
@@ -199,25 +202,21 @@ private void addAll(long[] keys) {
199202
Arrays.fill(t2hash, 0);
200203
Arrays.fill(reverseOrder, 0);
201204

202-
// TODO
203-
// if (hashIndex > 10) {
204-
// System.out.println("WARNING: hashIndex " + hashIndex + "\n");
205-
// System.out.println(size + " keys; arrayLength " + arrayLength + " reverseOrderPos " + reverseOrderPos + " segmentLength " + segmentLength + " segmentCount " + segmentCount);
206-
// }
207205
if (hashIndex > 100) {
208206
// if construction doesn't succeed eventually,
209207
// then there is likely a problem with the hash function
210-
throw new IllegalArgumentException("Construction failed after " + hashIndex + " retries for size " + size);
208+
// let us not crash the system:
209+
for(int i = 0; i < fingerprints.length; i++) {
210+
fingerprints[i] = (byte)0xFF;
211+
}
212+
return;
211213
}
212214
// use a new random numbers
213215
seed = Hash.randomSeed();
214216
}
215217
alone = null;
216218
t2count = null;
217219
t2hash = null;
218-
if (reverseOrderPos != size) {
219-
throw new IllegalStateException();
220-
}
221220

222221
for (int i = reverseOrderPos - 1; i >= 0; i--) {
223222
long hash = reverseOrder[i];

fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ public XorPlus8(long[] keys) {
123123
attempts++;
124124
if (attempts >= 100) {
125125
// if the same key appears more than once in the keys array, every attempt to build the table will yield a collision
126-
throw new IllegalArgumentException("Unable to construct the table after 100 attempts; likely indicates duplicate keys");
126+
for(int i = 0; i < fingerprints.length; i++) {
127+
fingerprints[i] = (byte)0xFF;
128+
}
129+
return;
127130
}
128131

129132
seed = Hash.randomSeed();

0 commit comments

Comments
 (0)