E - the type of instances that the BloomFilter accepts.public final class BloomFilter<E> extends Object implements ProbabilisticFilter<E>, Serializable
E that implements the ProbabilisticFilter
interface.
This implementation is backed by Google Guava's
BloomFilter.
From Guava:
A Bloom filter offers an approximate containment test with one-sided error: if it claims that an element is contained in it, this might be in error, but if it claims that an element is not contained in it, then this is definitely true.If you are unfamiliar with Bloom filters, this nice tutorial may help you understand how they work.
The false positive probability (
FPP) of a bloom filter is defined as the probability thatcontains(Object)will erroneously returntruefor an object that has not actually been put in theBloomFilter.
ProbabilisticFilter,
Serialized Form| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Adds the specified element to this filter.
|
boolean |
addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this filter.
|
boolean |
addAll(ProbabilisticFilter<E> f)
Combines
this filter with another compatible filter. |
long |
capacity()
Returns the number of elements this filter can represent at its requested
FPP. |
void |
clear()
Removes all of the elements from this filter.
|
boolean |
contains(E e)
Returns
true if this filter might contain the specified element, false
if this is definitely not the case. |
boolean |
containsAll(Collection<? extends E> c)
Returns
true if this filter might contain all of the elements of the specified
collection (optional operation). |
boolean |
containsAll(ProbabilisticFilter<E> f)
Not supported.
|
static <T> BloomFilter<T> |
copyOf(BloomFilter<T> f)
Creates a new
BloomFilter that's a copy of this instance. |
static <T> BloomFilter<T> |
create(com.google.common.hash.Funnel<T> funnel,
long capacity)
Creates a
BloomFilter with the expected number of insertions and a
default expected false positive probability of 3%. |
static <T> BloomFilter<T> |
create(com.google.common.hash.Funnel<T> funnel,
long capacity,
double fpp)
Creates a
BloomFilter with the expected number of insertions and expected false
positive probability. |
double |
currentFpp()
Returns the current false positive probability (
FPP) of this filter. |
boolean |
equals(Object object) |
double |
fpp()
Returns the intended
FPP limit of this filter. |
int |
hashCode() |
boolean |
isCompatible(ProbabilisticFilter<E> f)
Returns
true if the specified filter is compatible with this filter. |
boolean |
isEmpty()
Returns
true if this filter contains no elements. |
boolean |
remove(E e)
Not supported.
|
boolean |
removeAll(Collection<? extends E> c)
Not supported.
|
boolean |
removeAll(ProbabilisticFilter<E> f)
Not supported.
|
long |
size()
Returns the number of elements contained in this filter (its cardinality).
|
long |
sizeLong()
Returns the number of elements contained in this filter (its cardinality).
|
@CheckReturnValue public static <T> BloomFilter<T> create(com.google.common.hash.Funnel<T> funnel, long capacity, double fpp)
BloomFilter with the expected number of insertions and expected false
positive probability.
Note that overflowing a BloomFilter with significantly more elements than specified,
will result in its saturation, and a sharp deterioration of its false positive probability.
The constructed BloomFilter will be serializable if the provided Funnel is.
It is recommended that the funnel be implemented as a Java enum. This has the benefit of
ensuring proper serialization and deserialization, which is important since equals(Object) also relies on object identity of funnels.
funnel - the funnel of T's that the constructed BloomFilter will usecapacity - the number of expected insertions to the constructed BloomFilter; must
be positivefpp - the desired false positive probability (must be positive and less than 1.0)BloomFilter@CheckReturnValue public static <T> BloomFilter<T> create(com.google.common.hash.Funnel<T> funnel, long capacity)
BloomFilter with the expected number of insertions and a
default expected false positive probability of 3%.
Note that overflowing a BloomFilter with significantly more objects than specified,
will result in its saturation, and a sharp deterioration of its false positive probability.
The constructed BloomFilter will be serializable if the provided Funnel<T>
is.
It is recommended that the funnel be implemented as a Java enum. This has the benefit of
ensuring proper serialization and deserialization, which is important since equals(java.lang.Object)
also relies on object identity of funnels.
funnel - the funnel of T's that the constructed BloomFilter will usecapacity - the number of expected insertions to the constructed BloomFilter; must
be positiveBloomFilterpublic boolean add(E e)
true ensures that contains(Object) given e will also return true.add in interface ProbabilisticFilter<E>e - element to be added to this filtertrue as com.google.common.hash.BloomFilter cannot fail to add an
objectNullPointerException - if the specified element is nullcontains(Object),
addAll(Collection),
addAll(ProbabilisticFilter),
com.google.common.hash.BloomFilter#put(T)public boolean addAll(ProbabilisticFilter<E> f)
this filter with another compatible filter. The mutations happen to this instance. Callers must ensure this filter is appropriately sized to avoid
saturating it or running out of space.addAll in interface ProbabilisticFilter<E>f - filter to be combined into this filter - f is not mutatedtrue if the operation was successful, false otherwiseNullPointerException - if the specified filter is nullIllegalArgumentException - if isCompatible(ProbabilisticFilter) ==
falseadd(Object),
addAll(Collection),
contains(Object)public boolean addAll(Collection<? extends E> c)
addAll in interface ProbabilisticFilter<E>c - collection containing elements to be added to this filtertrue if all elements of the collection were successfully added, false
otherwiseNullPointerException - if the specified collection contains a null element, or if the
specified collection is nulladd(Object),
addAll(ProbabilisticFilter),
contains(Object)public boolean contains(E e)
true if this filter might contain the specified element, false
if this is definitely not the case.contains in interface ProbabilisticFilter<E>e - element whose containment in this filter is to be testedtrue if this filter might contain the specified element, false
if this is definitely not the case.ClassCastException - if the type of the specified element is incompatible with this
filter (optional)NullPointerException - if the specified element is null and this filter does not
permit null elementscontainsAll(Collection),
containsAll(ProbabilisticFilter),
add(Object),
remove(Object),
com.google.common.hash.BloomFilter#mightContain(T)public double currentFpp()
FPP) of this filter.currentFpp in interface ProbabilisticFilter<E>contains(Object) will erroneously return true
given an element that has not actually been added to the filter.fpp(),
com.google.common.hash.BloomFilter#put(T)public boolean isCompatible(ProbabilisticFilter<E> f)
true if the specified filter is compatible with this filter. f
is considered compatible if this filter can use it in combinatoric operations (e.g.
addAll(ProbabilisticFilter), containsAll(ProbabilisticFilter)).
For two bloom filters to be compatible, they must:
isCompatible in interface ProbabilisticFilter<E>f - filter to check for compatibility with this filtertrue if the specified filter is compatible with this filterNullPointerException - if the specified filter is nulladdAll(ProbabilisticFilter),
containsAll(ProbabilisticFilter),
removeAll(ProbabilisticFilter),
com.google.common.hash.BloomFilter#isCompatible(com.google.common.hash.BloomFilter)public boolean containsAll(Collection<? extends E> c)
true if this filter might contain all of the elements of the specified
collection (optional operation). More formally, returns true if contains(Object) == true for all of the elements of the specified collection.containsAll in interface ProbabilisticFilter<E>c - collection containing elements to be checked for containment in this filtertrue if this filter might contain all elements of the specified
collectionNullPointerException - if the specified collection contains one or more null
elements, or if the specified collection is nullcontains(Object),
containsAll(ProbabilisticFilter)public boolean containsAll(ProbabilisticFilter<E> f)
containsAll in interface ProbabilisticFilter<E>f - filter containing elements to be checked for probable containment in this filtertrue if this filter might contain all elements contained in the
specified filter, false if this is definitely not the case.UnsupportedOperationExceptionProbabilisticFilter.contains(Object),
ProbabilisticFilter.containsAll(Collection)public boolean isEmpty()
true if this filter contains no elements.isEmpty in interface ProbabilisticFilter<E>true if this filter contains no elementssizeLong()public long sizeLong()
Long.MAX_VALUE elements, returns Long.MAX_VALUE.sizeLong in interface ProbabilisticFilter<E>capacity(),
isEmpty()public long size()
Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.size in interface ProbabilisticFilter<E>capacity(),
isEmpty(),
sizeLong()public long capacity()
FPP. This is
not be a hard limit of the filter implementation. It is permissible for a filter to contain
more elements than its requested capacity, though its FPP will suffer.capacity in interface ProbabilisticFilter<E>FPP.fpp(),
currentFpp(),
sizeLong()public double fpp()
FPP limit of this filter. This is not a hard limit of the filter
implementation. It is permissible for a filter's FPP to degrade (e.g. via saturation)
beyond its intended limit.fpp in interface ProbabilisticFilter<E>FPP limit of this filter.currentFpp()public static <T> BloomFilter<T> copyOf(BloomFilter<T> f)
BloomFilter that's a copy of this instance. The returned instance equals(f) == true but shares no mutable state.public void clear()
clear in interface ProbabilisticFilter<E>sizeLong(),
isEmpty()public boolean remove(E e)
remove in interface ProbabilisticFilter<E>e - element to be removed from this filtertrue if this filter probably contained the specified element, false
otherwiseUnsupportedOperationExceptionProbabilisticFilter.contains(Object),
ProbabilisticFilter.removeAll(Collection),
ProbabilisticFilter.removeAll(ProbabilisticFilter)public boolean removeAll(Collection<? extends E> c)
removeAll in interface ProbabilisticFilter<E>c - collection containing elements to be removed from this filtertrue if all of the elements of the specified collection were successfully
removed from the filter, false if any of the elements was not successfully removedUnsupportedOperationExceptionProbabilisticFilter.contains(Object),
ProbabilisticFilter.remove(Object),
ProbabilisticFilter.removeAll(ProbabilisticFilter)public boolean removeAll(ProbabilisticFilter<E> f)
removeAll in interface ProbabilisticFilter<E>f - filter containing elements to remove from this filter. f is not
mutatedtrue if the operation was successful, false otherwiseUnsupportedOperationExceptionProbabilisticFilter.contains(Object),
ProbabilisticFilter.remove(Object),
ProbabilisticFilter.removeAll(Collection)Copyright © 2016. All rights reserved.