Skip to content

Commit

Permalink
Merge pull request #41 from FastFilter/dlemire/issue40
Browse files Browse the repository at this point in the history
Fixing issue 40.
  • Loading branch information
thomasmueller committed Oct 10, 2023
2 parents 7947763 + 746ea5b commit 18dd1a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fastfilter/src/main/java/org/fastfilter/utils/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static long randomSeed() {
*/
public static int reduce(int hash, int n) {
// http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
return (int) (((hash & 0xffffffffL) * n) >>> 32);
return (int) (((hash & 0xffffffffL) * (n & 0xffffffffL)) >>> 32);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions fastfilter/src/test/java/org/fastfilter/RegressionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ public void regressionTest() {
assertTrue(filter.mayContain(key));
}
}

@Test
public void issue40() {
long hash = 4282432426L;
long n = 2400000016L; // important: exceeds 2147483647
long r = (long)(Hash.reduce((int)hash, (int)n) & 0xffffffffL);
assertTrue(r < n);
}
}
3 changes: 0 additions & 3 deletions fastfilter/src/test/java/org/fastfilter/TestAllFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ private static void test(TestFilterType type, int len, int seed, boolean log) {
}
time = System.nanoTime() - time;
nanosPerRemove = time / len;
if (f.cardinality() != 0) {
System.out.println(f.cardinality());
}
assertEquals(f.toString(), 0, f.cardinality());
}
if (log) {
Expand Down

0 comments on commit 18dd1a7

Please sign in to comment.