Class BloomFilter
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.simulator.membership.bloom.BloomFilter
-
- All Implemented Interfaces:
Membership
public final class BloomFilter extends Object implements Membership
A Bloom filter is a space and time efficient probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. Elements can be added to the set, but not removed. The more elements that are added the higher the probability of false positives. While risking false positives, Bloom filters have a space advantage over other data structures for representing sets by not storing the items.
-
-
Constructor Summary
Constructors Constructor Description BloomFilter()Creates a lazily initialized membership sketch, requiringensureCapacity(@org.checkerframework.checker.index.qual.NonNegative long, @org.checkerframework.checker.index.qual.NonNegative double)be called when the expected number of insertions and the false positive probability have been determined.BloomFilter(Config config)Creates a membership sketch based on the expected number of insertions and the false positive probability.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes the elements from this collection.voidensureCapacity(@org.checkerframework.checker.index.qual.NonNegative long expectedInsertions, @org.checkerframework.checker.index.qual.NonNegative double fpp)Initializes and increases the capacity of this BloomFilter instance, if necessary, to ensure that it can accurately estimate the membership of elements given the expected number of insertions.booleanmightContain(long e)Returns if the element might have been put in this Bloom filter,falseif this is definitely not the case.booleanput(long e)Puts an element into this collection so that subsequent queries with the same element will returntrue.
-
-
-
Constructor Detail
-
BloomFilter
public BloomFilter()
Creates a lazily initialized membership sketch, requiringensureCapacity(@org.checkerframework.checker.index.qual.NonNegative long, @org.checkerframework.checker.index.qual.NonNegative double)be called when the expected number of insertions and the false positive probability have been determined.
-
BloomFilter
public BloomFilter(Config config)
Creates a membership sketch based on the expected number of insertions and the false positive probability.
-
-
Method Detail
-
ensureCapacity
public void ensureCapacity(@org.checkerframework.checker.index.qual.NonNegative long expectedInsertions, @org.checkerframework.checker.index.qual.NonNegative double fpp)Initializes and increases the capacity of this BloomFilter instance, if necessary, to ensure that it can accurately estimate the membership of elements given the expected number of insertions. This operation forgets all previous memberships when resizing.- Parameters:
expectedInsertions- the number of expected insertionsfpp- the false positive probability, where 0.0 > fpp < 1.0
-
mightContain
public boolean mightContain(long e)
Description copied from interface:MembershipReturns if the element might have been put in this Bloom filter,falseif this is definitely not the case.- Specified by:
mightContainin interfaceMembership- Parameters:
e- the element whose presence is to be tested- Returns:
- if the element might be present
-
clear
public void clear()
Description copied from interface:MembershipRemoves the elements from this collection.- Specified by:
clearin interfaceMembership
-
put
public boolean put(long e)
Description copied from interface:MembershipPuts an element into this collection so that subsequent queries with the same element will returntrue.- Specified by:
putin interfaceMembership- Parameters:
e- the element to add- Returns:
- if the membership changed as a result of this operation
-
-