Skip to content

Commit 18dd1a7

Browse files
Merge pull request #41 from FastFilter/dlemire/issue40
Fixing issue 40.
2 parents 7947763 + 746ea5b commit 18dd1a7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

fastfilter/src/main/java/org/fastfilter/utils/Hash.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static long randomSeed() {
3232
*/
3333
public static int reduce(int hash, int n) {
3434
// http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
35-
return (int) (((hash & 0xffffffffL) * n) >>> 32);
35+
return (int) (((hash & 0xffffffffL) * (n & 0xffffffffL)) >>> 32);
3636
}
3737

3838
/**

fastfilter/src/test/java/org/fastfilter/RegressionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@ public void regressionTest() {
7979
assertTrue(filter.mayContain(key));
8080
}
8181
}
82+
83+
@Test
84+
public void issue40() {
85+
long hash = 4282432426L;
86+
long n = 2400000016L; // important: exceeds 2147483647
87+
long r = (long)(Hash.reduce((int)hash, (int)n) & 0xffffffffL);
88+
assertTrue(r < n);
89+
}
8290
}

fastfilter/src/test/java/org/fastfilter/TestAllFilters.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ private static void test(TestFilterType type, int len, int seed, boolean log) {
183183
}
184184
time = System.nanoTime() - time;
185185
nanosPerRemove = time / len;
186-
if (f.cardinality() != 0) {
187-
System.out.println(f.cardinality());
188-
}
189186
assertEquals(f.toString(), 0, f.cardinality());
190187
}
191188
if (log) {

0 commit comments

Comments
 (0)