Interface BloomFilter
 All Superinterfaces:
BitMapProducer
,IndexProducer
 All Known Subinterfaces:
CountingBloomFilter
 All Known Implementing Classes:
ArrayCountingBloomFilter
,LayeredBloomFilter
,SimpleBloomFilter
,SparseBloomFilter
,WrappedBloomFilter
See implementation notes for BitMapProducer and IndexProducer.
 Since:
 4.5
 See Also:

Field Summary
Modifier and TypeFieldDescriptionstatic final int
The sparse characteristic used to determine the best method for matching. 
Method Summary
Modifier and TypeMethodDescriptionint
Gets the cardinality (number of enabled bits) of this Bloom filter.int
Returns the characteristics of the filter.void
clear()
Resets the filter to its initial, unpopulated state.default boolean
contains
(BitMapProducer bitMapProducer) Returnstrue
if this filter contains the bits specified in the bit maps produced by the bitMapProducer.default boolean
contains
(BloomFilter other) Returnstrue
if this filter contains the specified filter.default boolean
Returnstrue
if this filter contains the bits specified in the hasher.boolean
contains
(IndexProducer indexProducer) Returnstrue
if this filter contains the indices specified IndexProducer.copy()
Creates a new instance of the BloomFilter with the same properties as the current one.default int
estimateIntersection
(BloomFilter other) Estimates the number of items in the intersection of this Bloom filter with the other bloom filter.default int
Estimates the number of items in the Bloom filter.default int
estimateUnion
(BloomFilter other) Estimates the number of items in the union of this Bloom filter with the other bloom filter.getShape()
Gets the shape that was used when the filter was built.default boolean
isEmpty()
Determines if all the bits are off.default boolean
isFull()
Determines if the bloom filter is "full".boolean
merge
(BitMapProducer bitMapProducer) Merges the specified hasher into this Bloom filter.default boolean
merge
(BloomFilter other) Merges the specified Bloom filter into this Bloom filter.default boolean
Merges the specified hasher into this Bloom filter.boolean
merge
(IndexProducer indexProducer) Merges the specified IndexProducer into this Bloom filter.default IndexProducer
Most Bloom filters create unique IndexProducers.Methods inherited from interface org.apache.commons.collections4.bloomfilter.BitMapProducer
asBitMapArray, forEachBitMap, forEachBitMapPair
Methods inherited from interface org.apache.commons.collections4.bloomfilter.IndexProducer
asIndexArray, forEachIndex

Field Details

SPARSE
The sparse characteristic used to determine the best method for matching.For `sparse` implementations the
forEachIndex(IntConsumer consumer)
method is more efficient. For non `sparse` implementations theforEachBitMap(LongConsumer consumer)
is more efficient. Implementers should determine if it is easier for the implementation to produce indexes of bit map blocks. See Also:


Method Details

cardinality
int cardinality()Gets the cardinality (number of enabled bits) of this Bloom filter.This is also known as the Hamming value or Hamming number.
 Returns:
 the cardinality of this filter

characteristics
int characteristics()Returns the characteristics of the filter.Characteristics are defined as bits within the characteristics integer.
 Returns:
 the characteristics for this bloom filter.

clear
void clear()Resets the filter to its initial, unpopulated state. 
contains
Returnstrue
if this filter contains the bits specified in the bit maps produced by the bitMapProducer. Parameters:
bitMapProducer
 theBitMapProducer
to provide the bit maps. Returns:
true
if this filter is enabled for all bits specified by the bit maps

contains
Returnstrue
if this filter contains the specified filter.Specifically this returns
true
if this filter is enabled for all bits that are enabled in theother
filter. Using the bit representations this is effectively(this AND other) == other
. Parameters:
other
 the other Bloom filter Returns:
 true if all enabled bits in the other filter are enabled in this filter.

contains
Returnstrue
if this filter contains the bits specified in the hasher.Specifically this returns
true
if this filter is enabled for all bit indexes identified by thehasher
. Using the bit map representations this is effectively(this AND hasher) == hasher
. Parameters:
hasher
 the hasher to provide the indexes Returns:
 true if this filter is enabled for all bits specified by the hasher

contains
Returnstrue
if this filter contains the indices specified IndexProducer.Specifically this returns
true
if this filter is enabled for all bit indexes identified by theIndexProducer
. Parameters:
indexProducer
 the IndexProducer to provide the indexes Returns:
true
if this filter is enabled for all bits specified by the IndexProducer

copy
Creates a new instance of the BloomFilter with the same properties as the current one. Returns:
 a copy of this BloomFilter

estimateIntersection
Estimates the number of items in the intersection of this Bloom filter with the other bloom filter.This method produces estimate is roughly equivalent to the number of unique Hashers that have been merged into both of the filters by rounding the value from the calculation described in the
Shape
class Javadoc.estimateIntersection
should only be called with Bloom filters of the same Shape. If called on Bloom filters of differing shape this method is not symmetric. Ifother
has more bits anIllegalArgumentException
may be thrown. Parameters:
other
 The other Bloom filter Returns:
 an estimate of the number of items in the intersection. If the calculated estimate is larger than Integer.MAX_VALUE then MAX_VALUE is returned.
 Throws:
IllegalArgumentException
 if the estimated N for the union of the filters is infinite. See Also:

estimateN
Estimates the number of items in the Bloom filter.By default this is the rounding of the
Shape.estimateN(cardinality)
calculation for the shape and cardinality of this filter.This produces an estimate roughly equivalent to the number of Hashers that have been merged into the filter by rounding the value from the calculation described in the
Shape
class Javadoc.Note:
 if cardinality == numberOfBits, then result is Integer.MAX_VALUE.
 if cardinality > numberOfBits, then an IllegalArgumentException is thrown.
 Returns:
 an estimate of the number of items in the bloom filter. Will return Integer.MAX_VALUE if the estimate is larger than Integer.MAX_VALUE.
 Throws:
IllegalArgumentException
 if the cardinality is > numberOfBits as defined in Shape. See Also:

estimateUnion
Estimates the number of items in the union of this Bloom filter with the other bloom filter.This produces an estimate roughly equivalent to the number of unique Hashers that have been merged into either of the filters by rounding the value from the calculation described in the
Shape
class Javadoc.estimateUnion
should only be called with Bloom filters of the same Shape. If called on Bloom filters of differing shape this method is not symmetric. Ifother
has more bits anIllegalArgumentException
may be thrown. Parameters:
other
 The other Bloom filter Returns:
 an estimate of the number of items in the union. Will return Integer.MAX_VALUE if the estimate is larger than Integer.MAX_VALUE.
 See Also:

getShape
Gets the shape that was used when the filter was built. Returns:
 The shape the filter was built with.

isEmpty
Determines if all the bits are off. This is equivalent tocardinality() == 0
.Note: This method is optimised for nonsparse filters. Implementers are encouraged to implement faster checks if possible.
 Returns:
true
if no bits are enabled,false
otherwise.

isFull
Determines if the bloom filter is "full".Full is defined as having no unset bits.
 Returns:
true
if the filter is full,false
otherwise.

merge
Merges the specified hasher into this Bloom filter. Specifically all bit indexes that are identified by theproducer
will be enabled in this filter.Note: This method should return
true
even if no additional bit indexes were enabled. Afalse
result indicates that this filter may or may not contain all the indexes enabled in theproducer
. This state may occur in complex Bloom filter implementations like counting Bloom filters. Parameters:
bitMapProducer
 The producer to merge. Returns:
 true if the merge was successful
 Throws:
IllegalArgumentException
 if producer sends illegal value.

merge
Merges the specified Bloom filter into this Bloom filter.Specifically all bit indexes that are identified by the
other
will be enabled in this filter.Note: This method should return
true
even if no additional bit indexes were enabled. Afalse
result indicates that this filter may or may not contain theother
Bloom filter. This state may occur in complex Bloom filter implementations like counting Bloom filters. Parameters:
other
 The bloom filter to merge into this one. Returns:
 true if the merge was successful

merge
Merges the specified hasher into this Bloom filter. Specifically all bit indexes that are identified by thehasher
will be enabled in this filter.Note: This method should return
true
even if no additional bit indexes were enabled. Afalse
result indicates that this filter may or may not contain thehasher
values. This state may occur in complex Bloom filter implementations like counting Bloom filters. Parameters:
hasher
 The hasher to merge. Returns:
 true if the merge was successful
 Throws:
IllegalArgumentException
 if hasher produces an illegal value.

merge
Merges the specified IndexProducer into this Bloom filter. Specifically all bit indexes that are identified by theproducer
will be enabled in this filter.Note: This method should return
true
even if no additional bit indexes were enabled. Afalse
result indicates that this filter may or may not contain all the indexes of theproducer
. This state may occur in complex Bloom filter implementations like counting Bloom filters. Parameters:
indexProducer
 The IndexProducer to merge. Returns:
 true if the merge was successful
 Throws:
IllegalArgumentException
 if producer sends illegal value.

uniqueIndices
Most Bloom filters create unique IndexProducers. Specified by:
uniqueIndices
in interfaceIndexProducer
 Returns:
 the IndexProducer of unique values.
