Class BloomFilter

java.lang.Object
org.eclipse.lemminx.extensions.index.BloomFilter

public final class BloomFilter extends Object
A compact, immutable bloom filter for fast set-membership testing.

Used in the cross-file index to answer the question "does this XML file possibly reference grammar X?" without reading the file. Each indexed file gets its own BloomFilter containing the grammar names and symbols it references (see XMLReferenceCollector).

Use case (UC19): When a user triggers "Find References" on a grammar file like schema.xsd, the WorkspaceIndex iterates all BloomFilters and calls mightContain("schema.xsd") to instantly identify candidate files — without opening any of them.

Guarantees:

Hashing: Uses double-hashing with FNV-1a (hash1) and a murmur-ish mix (hash2). Inspired by the IdentifierBloomFilter from java-ls (MIT License, Thomas Mäder / Castle Ridge Software).

See Also:
  • Method Details

    • create

      public static BloomFilter create(Collection<? extends CharSequence> names)
      Build a filter from the given names.
      Parameters:
      names - the names to add to the filter.
      Returns:
      the bloom filter.
    • mightContain

      public boolean mightContain(CharSequence name)
      Returns true if the given name might have been added to this filter. False negatives never occur; false positives are possible at a low rate.
      Parameters:
      name - the name to test.
      Returns:
      true if the name might be in the filter, false if definitely not.
    • getBits

      public long[] getBits()
      Returns the underlying bit array for serialization.
      Returns:
      the bit array.
    • getBitCount

      public int getBitCount()
      Returns the number of bits in the filter.
      Returns:
      the bit count.
    • getHashCount

      public int getHashCount()
      Returns the number of hash functions used.
      Returns:
      the hash count.
    • fromBits

      public static BloomFilter fromBits(long[] bits, int bitCount, int hashCount)
      Reconstruct a filter from serialized data.
      Parameters:
      bits - the bit array.
      bitCount - the number of bits.
      hashCount - the number of hash functions.
      Returns:
      the bloom filter.