Class SparseBloomFilter
- All Implemented Interfaces:
BitMapExtractor
,BloomFilter
,IndexExtractor
- Since:
- 4.5
-
Field Summary
Fields inherited from interface org.apache.commons.collections4.bloomfilter.BloomFilter
SPARSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong[]
Return a copy of the BitMapExtractor data as a bit map array.int
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.boolean
contains
(BitMapExtractor bitMapExtractor) Returnstrue
if this filter contains the bits specified in the bit maps produced by the bitMapExtractor.boolean
contains
(IndexExtractor indexExtractor) Returnstrue
if this filter contains the indices specified IndexExtractor.copy()
Creates a new instance of the BloomFilter with the same properties as the current one.getShape()
Gets the shape that was used when the filter was built.boolean
isEmpty()
Determines if all the bits are off.boolean
merge
(BitMapExtractor bitMapExtractor) Merges the specified hasher into this Bloom filter.boolean
merge
(BloomFilter other) Merges the specified Bloom filter into this Bloom filter.boolean
Merges the specified hasher into this Bloom filter.boolean
merge
(IndexExtractor indexExtractor) Merges the specified IndexExtractor into this Bloom filter.boolean
processBitMaps
(LongPredicate consumer) Each bit map is passed to the predicate in order.boolean
processIndices
(IntPredicate consumer) Each index is passed to the predicate.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.collections4.bloomfilter.BitMapExtractor
processBitMapPairs
Methods inherited from interface org.apache.commons.collections4.bloomfilter.BloomFilter
contains, contains, estimateIntersection, estimateN, estimateUnion, isFull, uniqueIndices
Methods inherited from interface org.apache.commons.collections4.bloomfilter.IndexExtractor
asIndexArray
-
Constructor Details
-
SparseBloomFilter
Constructs an empty BitSetBloomFilter.- Parameters:
shape
- The shape of the filter.
-
-
Method Details
-
asBitMapArray
Description copied from interface:BitMapExtractor
Return a copy of the BitMapExtractor data as a bit map array.The default implementation of this method is slow. It is recommended that implementing classes reimplement this method.
- Specified by:
asBitMapArray
in interfaceBitMapExtractor
- Returns:
- An array of bit map data.
-
cardinality
Description copied from interface:BloomFilter
Gets the cardinality (number of enabled bits) of this Bloom filter.This is also known as the Hamming value or Hamming number.
- Specified by:
cardinality
in interfaceBloomFilter
- Returns:
- the cardinality of this filter
-
characteristics
Description copied from interface:BloomFilter
Returns the characteristics of the filter.Characteristics are defined as bits within the characteristics integer.
- Specified by:
characteristics
in interfaceBloomFilter
- Returns:
- the characteristics for this bloom filter.
-
clear
Description copied from interface:BloomFilter
Resets the filter to its initial, unpopulated state.- Specified by:
clear
in interfaceBloomFilter
-
contains
Description copied from interface:BloomFilter
Returnstrue
if this filter contains the bits specified in the bit maps produced by the bitMapExtractor.- Specified by:
contains
in interfaceBloomFilter
- Parameters:
bitMapExtractor
- theBitMapExtractor
to provide the bit maps.- Returns:
true
if this filter is enabled for all bits specified by the bit maps
-
contains
Description copied from interface:BloomFilter
Returnstrue
if this filter contains the indices specified IndexExtractor.Specifically this returns
true
if this filter is enabled for all bit indexes identified by theIndexExtractor
.- Specified by:
contains
in interfaceBloomFilter
- Parameters:
indexExtractor
- the IndexExtractor to provide the indexes- Returns:
true
if this filter is enabled for all bits specified by the IndexExtractor
-
copy
Description copied from interface:BloomFilter
Creates a new instance of the BloomFilter with the same properties as the current one.- Specified by:
copy
in interfaceBloomFilter
- Returns:
- a copy of this BloomFilter
-
processBitMaps
Description copied from interface:BitMapExtractor
Each bit map is passed to the predicate in order. The predicate is applied to each bit map value, if the predicate returnsfalse
the execution is stopped,false
is returned, and no further bit maps are processed.If the extractor is empty this method will return true.
Any exceptions thrown by the action are relayed to the caller.
- Specified by:
processBitMaps
in interfaceBitMapExtractor
- Parameters:
consumer
- the function to execute- Returns:
true
if all bit maps returnedtrue
,false
otherwise.
-
processIndices
Description copied from interface:IndexExtractor
Each index is passed to the predicate. The predicate is applied to each index value, if the predicate returnsfalse
the execution is stopped,false
is returned, and no further indices are processed.Any exceptions thrown by the action are relayed to the caller.
Indices ordering and uniqueness is not guaranteed.
- Specified by:
processIndices
in interfaceIndexExtractor
- Parameters:
consumer
- the action to be performed for each non-zero bit index.- Returns:
true
if all indexes return true from consumer,false
otherwise.
-
getShape
Description copied from interface:BloomFilter
Gets the shape that was used when the filter was built.- Specified by:
getShape
in interfaceBloomFilter
- Returns:
- The shape the filter was built with.
-
isEmpty
Description copied from interface:BloomFilter
Determines if all the bits are off. This is equivalent tocardinality() == 0
.Note: This method is optimised for non-sparse filters. Implementers are encouraged to implement faster checks if possible.
- Specified by:
isEmpty
in interfaceBloomFilter
- Returns:
true
if no bits are enabled,false
otherwise.
-
merge
Description copied from interface:BloomFilter
Merges the specified hasher into this Bloom filter. Specifically all bit indexes that are identified by thebitMapExtractor
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 thebitMapExtractor
. This state may occur in complex Bloom filter implementations like counting Bloom filters.- Specified by:
merge
in interfaceBloomFilter
- Parameters:
bitMapExtractor
- The BitMapExtractor to merge.- Returns:
- true if the merge was successful
-
merge
Description copied from interface:BloomFilter
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.- Specified by:
merge
in interfaceBloomFilter
- Parameters:
other
- The bloom filter to merge into this one.- Returns:
- true if the merge was successful
-
merge
Description copied from interface:BloomFilter
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.- Specified by:
merge
in interfaceBloomFilter
- Parameters:
hasher
- The hasher to merge.- Returns:
- true if the merge was successful
-
merge
Description copied from interface:BloomFilter
Merges the specified IndexExtractor into this Bloom filter. Specifically all bit indexes that are identified by theindexExtractor
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 theindexExtractor
. This state may occur in complex Bloom filter implementations like counting Bloom filters.- Specified by:
merge
in interfaceBloomFilter
- Parameters:
indexExtractor
- The IndexExtractor to merge.- Returns:
- true if the merge was successful
-