Class BloomFilter
java.lang.Object
org.eclipse.lemminx.extensions.index.BloomFilter
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:
- No false negatives: if
mightContain(java.lang.CharSequence)returnsfalse, the item was definitely not added - False positives at ~1% rate with default sizing (10 bits/element)
- Thread-safe for concurrent
mightContain(java.lang.CharSequence)queries after construction - Memory: ~12 KB for 10,000 indexed files
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 Summary
Modifier and TypeMethodDescriptionstatic BloomFiltercreate(Collection<? extends CharSequence> names) Build a filter from the given names.static BloomFilterfromBits(long[] bits, int bitCount, int hashCount) Reconstruct a filter from serialized data.intReturns the number of bits in the filter.long[]getBits()Returns the underlying bit array for serialization.intReturns the number of hash functions used.booleanmightContain(CharSequence name) Returns true if the given name might have been added to this filter.
-
Method Details
-
create
Build a filter from the given names.- Parameters:
names- the names to add to the filter.- Returns:
- the bloom filter.
-
mightContain
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
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.
-