Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Sep 16, 2023
1 parent ee55724 commit 5dfd4c5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
7 changes: 2 additions & 5 deletions fastfilter/src/main/java/org/fastfilter/xor/Xor16.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Xor16(long[] keys) {
byte[] reverseH = new byte[size];
int reverseOrderPos;
long seed;
mainloop:
do {
seed = Hash.randomSeed();
byte[] t2count = new byte[arrayLength];
Expand All @@ -54,11 +55,7 @@ public Xor16(long[] keys) {
t2[h] ^= k;
if (t2count[h] > 120) {
// probably something wrong with the hash function
// let us not crash the system:
for(int i = 0; i < fingerprints.length; i++) {
fingerprints[i] = (short)0xFFFF;
}
return;
continue mainloop;
}
t2count[h]++;
}
Expand Down
7 changes: 2 additions & 5 deletions fastfilter/src/main/java/org/fastfilter/xor/Xor8.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Xor8(long[] keys) {
byte[] reverseH = new byte[size];
int reverseOrderPos;
long seed;
mainloop:
do {
seed = Hash.randomSeed();
byte[] t2count = new byte[m];
Expand All @@ -59,11 +60,7 @@ public Xor8(long[] keys) {
t2[h] ^= k;
if (t2count[h] > 120) {
// probably something wrong with the hash function
// let us not crash the system:
for(int i = 0; i < fingerprints.length; i++) {
fingerprints[i] = (byte)0xFF;
}
return;
continue mainloop;
}
t2count[h]++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private void addAll(long[] keys) {
blockBits++;
}
int block = 1 << blockBits;
mainloop:
while (true) {
reverseOrder[size] = 1;
int[] startPos = new int[block];
Expand Down Expand Up @@ -145,12 +146,7 @@ private void addAll(long[] keys) {
startPos = null;
if (countMask < 0) {
// we have a possible counter overflow
// this branch is never taken except if there is a problem in the hash code
// in which case construction fails
for(int i = 0; i < fingerprints.length; i++) {
fingerprints[i] = (byte)0xFF;
}
return;
continue mainloop;
}

reverseOrderPos = 0;
Expand Down
5 changes: 2 additions & 3 deletions fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public XorPlus8(long[] keys) {
// then we try again, with a new random seed.
long seed = 0;
int attempts = 0;
mainloop:
do {
attempts++;
if (attempts >= 100) {
Expand All @@ -145,9 +146,7 @@ public XorPlus8(long[] keys) {
int h = getHash(k, seed, hi);
t2[h] ^= k;
if (t2count[h] > 120) {
// probably something wrong with the hash function; or, the keys[] array contains many copies
// of the same value
throw new IllegalArgumentException("More than 120 keys hashed to the same location; indicates duplicate keys, or a bad hash function");
continue mainloop;
}
t2count[h]++;
}
Expand Down

3 comments on commit 5dfd4c5

@catap
Copy link
Contributor

@catap catap commented on 5dfd4c5 Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemire any chance to release a new version which includes this fix?

@lemire
Copy link
Member Author

@lemire lemire commented on 5dfd4c5 Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomasmueller has to do it. I don’t think I have the sonatype access.

@thomasmueller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - I'm currently on vacation and will work on it in two weeks. Regards, Thomas

Please sign in to comment.