public interface BloomFilter<T>
extends java.lang.Cloneable, java.io.Serializable
Modifier and Type | Method and Description |
---|---|
boolean |
add(byte[] element)
Adds the passed value to the filter.
|
default boolean |
add(T element)
Adds the passed value to the filter.
|
default java.util.List<java.lang.Boolean> |
addAll(java.util.Collection<T> elements)
Performs a bulk add operation for a collection of elements.
|
default java.lang.String |
asString()
Prints the Bloom filter: metadata and data
|
void |
clear()
Removes all elements from the filter (i.e. resets all bits to zero).
|
BloomFilter<T> |
clone()
Constructs a deep copy of the Bloom filter
|
default boolean |
compatible(BloomFilter<T> other)
Checks if two Bloom filters are compatible, i.e. have compatible parameters (hash function, size, etc.)
|
default boolean |
compatible(BloomFilter<T> bloomFilter,
BloomFilter<T> other)
Deprecated.
|
FilterBuilder |
config()
Returns the configuration/builder of the Bloom filter.
|
boolean |
contains(byte[] element)
Tests whether an element is present in the filter (subject to the specified false positive rate).
|
default java.util.List<java.lang.Boolean> |
contains(java.util.Collection<T> elements)
Bulk-tests elements for existence in the filter.
|
default boolean |
contains(T element)
Tests whether an element is present in the filter (subject to the specified false positive rate).
|
default boolean |
containsAll(java.util.Collection<T> elements)
Bulk-tests elements for existence in the filter.
|
java.util.BitSet |
getBitSet()
Return the underyling bit vector of the Bloom filter.
|
default double |
getBitsPerElement(int n)
Calculates the numbers of Bits per element, based on the expected number of inserted elements
expectedElements.
|
default double |
getBitZeroProbability(int n)
Returns the probability that a bit is zero.
|
default double |
getEstimatedFalsePositiveProbability()
Returns the probability of a false positive (approximated) using an estimation of how many elements are currently in the filter
|
default java.lang.Double |
getEstimatedPopulation()
Estimates the current population of the Bloom filter (see: http://en.wikipedia.org/wiki/Bloom_filter#Approximating_the_number_of_items_in_a_Bloom_filter
)
|
default int |
getExpectedElements()
Returns the expected number of elements (called n in the literature)
|
default double |
getFalsePositiveProbability()
Returns the expected false positive probability for the expected amounts of elements.
|
default double |
getFalsePositiveProbability(double insertedElements)
Returns the probability of a false positive (approximated):
(1 - e^(-hashes * insertedElements /
size)) ^ hashes |
default int |
getHashes()
Returns the number of hash functions (called k in the literature)
|
default int |
getSize()
Return the size of the Bloom filter, i.e. the number of positions in the underlyling bit vector (called m in the
literature).
|
default int[] |
hash(byte[] bytes)
Returns the k hash values for an inputs element in byte array form
|
default int[] |
hash(java.lang.String value)
Dispatches the hash function for a string value
|
boolean |
intersect(BloomFilter<T> other)
Performs the intersection operation on two compatible bloom filters.
|
boolean |
isEmpty()
Returns
true if the Bloom filter does not contain any elements |
static java.lang.Double |
population(java.util.BitSet bitSet,
FilterBuilder config) |
default void |
remove()
Destroys the Bloom filter by deleting its contents and metadata
|
default byte[] |
toBytes(T element)
Converts an element to the byte array representation used for hashing.
|
boolean |
union(BloomFilter<T> other)
Performs the union operation on two compatible bloom filters.
|
boolean add(byte[] element)
element
- value to addtrue
if the value did not previously exist in the filter. Note, that a false positive may occur,
thus the value may not have already been in the filter, but it hashed to a set of bits already in the filter.default boolean add(T element)
element
- value to addtrue
if the value did not previously exist in the filter. Note, that a false positive may occur,
thus the value may not have already been in the filter, but it hashed to a set of bits already in the filter.default java.util.List<java.lang.Boolean> addAll(java.util.Collection<T> elements)
elements
- to addvoid clear()
boolean contains(byte[] element)
element
- to testtrue
if the element is containeddefault boolean contains(T element)
element
- to testtrue
if the element is containeddefault java.util.List<java.lang.Boolean> contains(java.util.Collection<T> elements)
elements
- a collection of elements to testdefault boolean containsAll(java.util.Collection<T> elements)
elements
- a collection of elements to testtrue
if all elements are present in the filterjava.util.BitSet getBitSet()
FilterBuilder config()
BloomFilter<T> clone()
default int getSize()
default int getExpectedElements()
default int getHashes()
default double getFalsePositiveProbability()
getFalsePositiveProbability(double)
for that purpose.default byte[] toBytes(T element)
element
- the element to convert@Deprecated default boolean compatible(BloomFilter<T> bloomFilter, BloomFilter<T> other)
bloomFilter
- the bloomfilterother
- the other bloomfiltertrue
if this bloomfilter is compatible with the other onecompatible(BloomFilter)
default boolean compatible(BloomFilter<T> other)
other
- the other bloomfiltertrue
if this bloomfilter is compatible with the other onedefault void remove()
default int[] hash(byte[] bytes)
bytes
- input elementdefault int[] hash(java.lang.String value)
value
- the value to be hashedboolean union(BloomFilter<T> other)
other
- the other bloom filterboolean intersect(BloomFilter<T> other)
other
- the other bloom filterboolean isEmpty()
true
if the Bloom filter does not contain any elementstrue
if the Bloom filter does not contain any elementsdefault double getFalsePositiveProbability(double insertedElements)
(1 - e^(-hashes * insertedElements /
size)) ^ hashes
insertedElements
- The number of elements already inserted into the Bloomfilteradd(byte[])
operationsdefault double getEstimatedFalsePositiveProbability()
default double getBitsPerElement(int n)
n
- The number of elements already inserted into the Bloomfilterdefault double getBitZeroProbability(int n)
n
- The number of elements already inserted into the Bloomfilteradd(byte[])
operationsdefault java.lang.Double getEstimatedPopulation()
static java.lang.Double population(java.util.BitSet bitSet, FilterBuilder config)
default java.lang.String asString()