Interface BloomFilter
-
- All Known Implementing Classes:
BlockSplitBloomFilter
public interface BloomFilterA Bloom filter is a compact structure to indicate whether an item is not in a set or probably in a set. The Bloom filter usually consists of a bit set that represents a elements set, a hash strategy and a Bloom filter algorithm.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classBloomFilter.Algorithmstatic classBloomFilter.Compressionstatic classBloomFilter.HashStrategy
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleancanMergeFrom(BloomFilter otherBloomFilter)Determines whether a given Bloom filter can be merged into this Bloom filter.booleanequals(Object object)Compare this Bloom filter to the specified object.booleanfindHash(long hash)Determine whether an element is in set or not.BloomFilter.AlgorithmgetAlgorithm()Return the algorithm that the bloom filter apply.intgetBitsetSize()Get the number of bytes for bitset in this Bloom filter.BloomFilter.CompressiongetCompression()Return the compress algorithm that the bloom filter apply.BloomFilter.HashStrategygetHashStrategy()Return the hash strategy that the bloom filter apply.longhash(double value)Compute hash for double value by using its plain encoding result.longhash(float value)Compute hash for float value by using its plain encoding result.longhash(int value)Compute hash for int value by using its plain encoding result.longhash(long value)Compute hash for long value by using its plain encoding result.longhash(Object value)Compute hash for Object value by using its plain encoding result.longhash(Binary value)Compute hash for Binary value by using its plain encoding result.voidinsertHash(long hash)Insert an element to the Bloom filter, the element content is represented by the hash value of its plain encoding result.default voidmerge(BloomFilter otherBloomFilter)Merges this Bloom filter with another Bloom filter by performing a bitwise OR of the underlying bitsetsvoidwriteTo(OutputStream out)Write the Bloom filter to an output stream.
-
-
-
Method Detail
-
writeTo
void writeTo(OutputStream out) throws IOException
Write the Bloom filter to an output stream. It writes the Bloom filter header including the bitset's length in bytes, the hash strategy, the algorithm, and the bitset.- Parameters:
out- the output stream to write- Throws:
IOException
-
insertHash
void insertHash(long hash)
Insert an element to the Bloom filter, the element content is represented by the hash value of its plain encoding result.- Parameters:
hash- the hash result of element.
-
findHash
boolean findHash(long hash)
Determine whether an element is in set or not.- Parameters:
hash- the hash value of element plain encoding result.- Returns:
- false if element is must not in set, true if element probably in set.
-
getBitsetSize
int getBitsetSize()
Get the number of bytes for bitset in this Bloom filter.- Returns:
- The number of bytes for bitset in this Bloom filter.
-
equals
boolean equals(Object object)
Compare this Bloom filter to the specified object.
-
hash
long hash(int value)
Compute hash for int value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
hash
long hash(long value)
Compute hash for long value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
hash
long hash(double value)
Compute hash for double value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
hash
long hash(float value)
Compute hash for float value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
hash
long hash(Binary value)
Compute hash for Binary value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
hash
long hash(Object value)
Compute hash for Object value by using its plain encoding result.- Parameters:
value- the value to hash- Returns:
- hash result
-
getHashStrategy
BloomFilter.HashStrategy getHashStrategy()
Return the hash strategy that the bloom filter apply.- Returns:
- hash strategy that the bloom filter apply
-
getAlgorithm
BloomFilter.Algorithm getAlgorithm()
Return the algorithm that the bloom filter apply.- Returns:
- algorithm that the bloom filter apply
-
getCompression
BloomFilter.Compression getCompression()
Return the compress algorithm that the bloom filter apply.- Returns:
- compress algorithm that the bloom filter apply
-
canMergeFrom
default boolean canMergeFrom(BloomFilter otherBloomFilter)
Determines whether a given Bloom filter can be merged into this Bloom filter. For two Bloom filters to merge, they must:- have the same bit size
- have the same algorithm
- have the same hash strategy
- Parameters:
otherBloomFilter- The Bloom filter to merge this Bloom filter with.
-
merge
default void merge(BloomFilter otherBloomFilter) throws IOException
Merges this Bloom filter with another Bloom filter by performing a bitwise OR of the underlying bitsets- Parameters:
otherBloomFilter- The Bloom filter to merge this Bloom filter with.- Throws:
IOException
-
-