Class SparseBloomFilter
- java.lang.Object
-
- org.apache.commons.collections4.bloomfilter.SparseBloomFilter
-
- All Implemented Interfaces:
BitMapExtractor,BloomFilter<SparseBloomFilter>,IndexExtractor
public final class SparseBloomFilter extends java.lang.Object implements BloomFilter<SparseBloomFilter>
A bloom filter using a TreeSet of integers to track enabled bits. This is a standard implementation and should work well for most low cardinality Bloom filters.- Since:
- 4.5.0-M1
-
-
Field Summary
-
Fields inherited from interface org.apache.commons.collections4.bloomfilter.BloomFilter
SPARSE
-
-
Constructor Summary
Constructors Constructor Description SparseBloomFilter(Shape shape)Constructs an empty BitSetBloomFilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long[]asBitMapArray()Return a copy of the BitMapExtractor data as a bit map array.intcardinality()Gets the cardinality (number of enabled bits) of this Bloom filter.intcharacteristics()Gets the characteristics of the filter.voidclear()Clears the filter to by resetting it to its initial, unpopulated state.booleancontains(BitMapExtractor bitMapExtractor)Returnstrueif this filter contains the bits specified in the bit maps produced by the bitMapExtractor.booleancontains(IndexExtractor indexExtractor)Returnstrueif this filter contains the indices specified IndexExtractor.SparseBloomFiltercopy()Creates a new instance of thisSparseBloomFilterwith the same properties as the current one.ShapegetShape()Gets the shape that was used when the filter was built.booleanisEmpty()Determines if all the bits are off.booleanmerge(BitMapExtractor bitMapExtractor)Merges the specified hasher into this Bloom filter.booleanmerge(BloomFilter<?> other)Merges the specified Bloom filter into this Bloom filter.booleanmerge(Hasher hasher)Merges the specified hasher into this Bloom filter.booleanmerge(IndexExtractor indexExtractor)Merges the specified IndexExtractor into this Bloom filter.booleanprocessBitMaps(java.util.function.LongPredicate consumer)Each bit map is passed to the predicate in order.booleanprocessIndices(java.util.function.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 Detail
-
SparseBloomFilter
public SparseBloomFilter(Shape shape)
Constructs an empty BitSetBloomFilter.- Parameters:
shape- The shape of the filter.
-
-
Method Detail
-
asBitMapArray
public long[] asBitMapArray()
Description copied from interface:BitMapExtractorReturn 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:
asBitMapArrayin interfaceBitMapExtractor- Returns:
- An array of bit map data.
-
cardinality
public int cardinality()
Description copied from interface:BloomFilterGets the cardinality (number of enabled bits) of this Bloom filter.This is also known as the Hamming value or Hamming number.
- Specified by:
cardinalityin interfaceBloomFilter<SparseBloomFilter>- Returns:
- the cardinality of this filter
-
characteristics
public int characteristics()
Description copied from interface:BloomFilterGets the characteristics of the filter.Characteristics are defined as bits within the characteristics integer.
- Specified by:
characteristicsin interfaceBloomFilter<SparseBloomFilter>- Returns:
- the characteristics for this bloom filter.
-
clear
public void clear()
Description copied from interface:BloomFilterClears the filter to by resetting it to its initial, unpopulated state.- Specified by:
clearin interfaceBloomFilter<SparseBloomFilter>
-
contains
public boolean contains(BitMapExtractor bitMapExtractor)
Description copied from interface:BloomFilterReturnstrueif this filter contains the bits specified in the bit maps produced by the bitMapExtractor.- Specified by:
containsin interfaceBloomFilter<SparseBloomFilter>- Parameters:
bitMapExtractor- theBitMapExtractorto provide the bit maps.- Returns:
trueif this filter is enabled for all bits specified by the bit maps
-
contains
public boolean contains(IndexExtractor indexExtractor)
Description copied from interface:BloomFilterReturnstrueif this filter contains the indices specified IndexExtractor.Specifically this returns
trueif this filter is enabled for all bit indexes identified by theIndexExtractor.- Specified by:
containsin interfaceBloomFilter<SparseBloomFilter>- Parameters:
indexExtractor- the IndexExtractor to provide the indexes- Returns:
trueif this filter is enabled for all bits specified by the IndexExtractor
-
copy
public SparseBloomFilter copy()
Creates a new instance of thisSparseBloomFilterwith the same properties as the current one.- Specified by:
copyin interfaceBloomFilter<SparseBloomFilter>- Returns:
- a copy of this
SparseBloomFilter.
-
getShape
public Shape getShape()
Description copied from interface:BloomFilterGets the shape that was used when the filter was built.- Specified by:
getShapein interfaceBloomFilter<SparseBloomFilter>- Returns:
- The shape the filter was built with.
-
isEmpty
public boolean isEmpty()
Description copied from interface:BloomFilterDetermines if all the bits are off. This is equivalent tocardinality() == 0.Note: This method is optimized for non-sparse filters. Implementers are encouraged to implement faster checks if possible.
- Specified by:
isEmptyin interfaceBloomFilter<SparseBloomFilter>- Returns:
trueif no bits are enabled,falseotherwise.
-
merge
public boolean merge(BitMapExtractor bitMapExtractor)
Description copied from interface:BloomFilterMerges the specified hasher into this Bloom filter. Specifically all bit indexes that are identified by thebitMapExtractorwill be enabled in this filter.Note: This method should return
trueeven if no additional bit indexes were enabled. Afalseresult 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:
mergein interfaceBloomFilter<SparseBloomFilter>- Parameters:
bitMapExtractor- The BitMapExtractor to merge.- Returns:
- true if the merge was successful
-
merge
public boolean merge(BloomFilter<?> other)
Description copied from interface:BloomFilterMerges the specified Bloom filter into this Bloom filter.Specifically all bit indexes that are identified by the
otherwill be enabled in this filter.Note: This method should return
trueeven if no additional bit indexes were enabled. Afalseresult indicates that this filter may or may not contain theotherBloom filter. This state may occur in complex Bloom filter implementations like counting Bloom filters.- Specified by:
mergein interfaceBloomFilter<SparseBloomFilter>- Parameters:
other- The bloom filter to merge into this one.- Returns:
- true if the merge was successful
-
merge
public boolean merge(Hasher hasher)
Description copied from interface:BloomFilterMerges the specified hasher into this Bloom filter. Specifically all bit indexes that are identified by thehasherwill be enabled in this filter.Note: This method should return
trueeven if no additional bit indexes were enabled. Afalseresult indicates that this filter may or may not contain thehashervalues. This state may occur in complex Bloom filter implementations like counting Bloom filters.- Specified by:
mergein interfaceBloomFilter<SparseBloomFilter>- Parameters:
hasher- The hasher to merge.- Returns:
- true if the merge was successful
-
merge
public boolean merge(IndexExtractor indexExtractor)
Description copied from interface:BloomFilterMerges the specified IndexExtractor into this Bloom filter. Specifically all bit indexes that are identified by theindexExtractorwill be enabled in this filter.Note: This method should return
trueeven if no additional bit indexes were enabled. Afalseresult 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:
mergein interfaceBloomFilter<SparseBloomFilter>- Parameters:
indexExtractor- The IndexExtractor to merge.- Returns:
- true if the merge was successful
-
processBitMaps
public boolean processBitMaps(java.util.function.LongPredicate consumer)
Description copied from interface:BitMapExtractorEach bit map is passed to the predicate in order. The predicate is applied to each bit map value, if the predicate returnsfalsethe execution is stopped,falseis 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:
processBitMapsin interfaceBitMapExtractor- Parameters:
consumer- the function to execute- Returns:
trueif all bit maps returnedtrue,falseotherwise.
-
processIndices
public boolean processIndices(java.util.function.IntPredicate consumer)
Description copied from interface:IndexExtractorEach index is passed to the predicate. The predicate is applied to each index value, if the predicate returnsfalsethe execution is stopped,falseis 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:
processIndicesin interfaceIndexExtractor- Parameters:
consumer- the action to be performed for each non-zero bit index.- Returns:
trueif all indexes return true from consumer,falseotherwise.
-
-