Skip to content

Guava BloomFilter

The Guava BloomFilter is an implementation of the Bloom filter probabilistic data structure provided by the Google Guava library^[600-developer__principle__bloomfilter.md]. It is commonly used to address issues such as cache penetration (緩存穿透)^[600-developer__principle__bloomfilter.md].

Usage

The filter is created using the BloomFilter.create() method, specifying a funnel (for type serialization), the expected number of insertions, and the desired false positive probability^[600-developer__principle__bloomfilter.md].

API Methods

  • put(T): Adds an element to the filter^[600-developer__principle__bloomfilter.md].
  • mightContain(T): Checks for the potential presence of an element^[600-developer__principle__bloomfilter.md].
  • putAll(BloomFilter): Merges the contents of another BloomFilter into the current one^[600-developer__principle__bloomfilter.md].

Sources

^[600-developer__principle__bloomfilter.md]