diff --git a/fastfilter/src/main/java/org/fastfilter/xor/Xor16.java b/fastfilter/src/main/java/org/fastfilter/xor/Xor16.java index c20b470..b2c0c20 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/Xor16.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/Xor16.java @@ -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]; @@ -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]++; } diff --git a/fastfilter/src/main/java/org/fastfilter/xor/Xor8.java b/fastfilter/src/main/java/org/fastfilter/xor/Xor8.java index d23be08..848ce2a 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/Xor8.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/Xor8.java @@ -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]; @@ -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]++; } diff --git a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java index 12a4445..dfd5f45 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java @@ -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]; @@ -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; diff --git a/fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java b/fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java index 0c7955d..173709c 100644 --- a/fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java +++ b/fastfilter/src/main/java/org/fastfilter/xorplus/XorPlus8.java @@ -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) { @@ -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]++; }