jbapple / libfilter

High-speed Bloom filters and taffy filters for C, C++, and Java
Apache License 2.0
32 stars 6 forks source link

[Java] Block filter has high fpp #6

Closed thomasmueller closed 2 years ago

thomasmueller commented 2 years ago

I noticed the com.github.jbapple.libfilter.TaffyBlockFilter has a high fpp (100% at some point). Likely there is a simple bug:

private void MakeMask(long hash, int[] result) {
    // The loops are done individually for easier auto-vectorization by the JIT
    for (int i = 0; i < 8; ++i) {
      result[0] = (int) hash * INTERNAL_HASH_SEEDS[i]; <== BUG HERE
    }
    for (int i = 0; i < 8; ++i) {
      result[i] = result[i] >>> (32 - 5);
    }
    for (int i = 0; i < 8; ++i) {
      result[i] = 1 << result[i];
    }
  }

To me it looks like it should be result[i] instead of result[0].

jbapple commented 2 years ago

Thank you for the bug report and diagnosis! Fixed now.