Skip to content

Commit 7be7c18

Browse files
committed
Guard against infinite loop in table construction
1 parent 6341041 commit 7be7c18

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ public XorPlus8(long[] keys) {
118118
// we usually execute this loop just once. If we detect a cycle (which is extremely unlikely)
119119
// then we try again, with a new random seed.
120120
long seed = 0;
121+
int attempts = 0;
121122
do {
123+
attempts++;
124+
if (attempts >= 100) {
125+
// 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");
127+
}
128+
122129
seed = Hash.randomSeed();
123130
// we use an second table t2 to keep the list of all keys that map
124131
// to a given entry (with a broken hash function, all keys could map

0 commit comments

Comments
 (0)