E
- Object type that is to be inserted into the Bloom filter, e.g. String or Integer.public class BloomFilter<E> extends Object implements Serializable
Constructor and Description |
---|
BloomFilter(double falsePositiveProbability,
int expectedNumberOfElements)
Constructs an empty Bloom filter with a given false positive probability.
|
BloomFilter(double c,
int n,
int k)
Constructs an empty Bloom filter.
|
BloomFilter(int bitSetSize,
int expectedNumberOElements)
Constructs an empty Bloom filter.
|
BloomFilter(int bitSetSize,
int expectedNumberOfFilterElements,
int actualNumberOfFilterElements,
BitSet filterData)
Construct a new Bloom filter based on existing Bloom filter data.
|
Modifier and Type | Method and Description |
---|---|
void |
add(E element)
Adds an object to the Bloom filter.
|
void |
addAll(Collection<? extends E> c)
Adds all elements from a Collection to the Bloom filter.
|
void |
clear()
Sets all bits to false in the Bloom filter.
|
boolean |
contains(E element)
Returns true if the element could have been inserted into the Bloom filter.
|
boolean |
containsAll(Collection<? extends E> c)
Returns true if all the elements of a Collection could have been inserted
into the Bloom filter.
|
int |
count()
Returns the number of elements added to the Bloom filter after it
was constructed or after clear() was called.
|
static long |
createHash(byte[] data)
Generates a digest based on the contents of an array of bytes.
|
static long |
createHash(String val)
Generates a digest based on the contents of a String.
|
static long |
createHash(String val,
Charset charset)
Generates a digest based on the contents of a String.
|
boolean |
equals(Object obj)
Compares the contents of two instances to see if they are equal.
|
double |
expectedFalsePositiveProbability()
Calculates the expected probability of false positives based on
the number of expected filter elements and the size of the Bloom filter.
|
boolean |
getBit(int bit)
Read a single bit from the Bloom filter.
|
BitSet |
getBitSet()
Return the bit set used to store the Bloom filter.
|
double |
getBitsPerElement()
Get actual number of bits per element based on the number of elements that have currently been inserted and the length
of the Bloom filter.
|
double |
getExpectedBitsPerElement()
Get expected number of bits per element when the Bloom filter is full.
|
int |
getExpectedNumberOfElements()
Returns the expected number of elements to be inserted into the filter.
|
double |
getFalsePositiveProbability()
Get the current probability of a false positive.
|
double |
getFalsePositiveProbability(double numberOfElements)
Calculate the probability of a false positive given the specified
number of inserted elements.
|
int |
getK()
Returns the value chosen for K.
K is the optimal number of hash functions based on the size of the Bloom filter and the expected number of inserted elements. |
int |
hashCode()
Calculates a hash code for this class.
|
Collection<E> |
intersection(Collection<E> c) |
void |
setBit(int bit,
boolean value)
Set a single bit in the Bloom filter.
|
int |
size()
Returns the number of bits in the Bloom filter.
|
public BloomFilter(double c, int n, int k)
c
- is the number of bits used per element.n
- is the expected number of elements the filter will contain.k
- is the number of hash functions used.public BloomFilter(int bitSetSize, int expectedNumberOElements)
bitSetSize
- defines how many bits should be used in total for the filter.expectedNumberOElements
- defines the maximum number of elements the filter is expected to contain.public BloomFilter(double falsePositiveProbability, int expectedNumberOfElements)
falsePositiveProbability
- is the desired false positive probability.expectedNumberOfElements
- is the expected number of elements in the Bloom filter.public BloomFilter(int bitSetSize, int expectedNumberOfFilterElements, int actualNumberOfFilterElements, BitSet filterData)
bitSetSize
- defines how many bits should be used for the filter.expectedNumberOfFilterElements
- defines the maximum number of elements the filter is expected to contain.actualNumberOfFilterElements
- specifies how many elements have been inserted into the filterData
BitSet.filterData
- a BitSet representing an existing Bloom filter.public static long createHash(String val, Charset charset)
val
- specifies the input data.charset
- specifies the encoding of the input data.public static long createHash(String val)
val
- specifies the input data. The encoding is expected to be UTF-8.public static long createHash(byte[] data)
data
- specifies input data.public boolean equals(Object obj)
public int hashCode()
public double expectedFalsePositiveProbability()
public double getFalsePositiveProbability(double numberOfElements)
numberOfElements
- number of inserted elements.public double getFalsePositiveProbability()
public int getK()
public void clear()
public void add(E element)
element
- is an element to register in the Bloom filter.public void addAll(Collection<? extends E> c)
c
- Collection of elements.public boolean contains(E element)
element
- element to check.public boolean containsAll(Collection<? extends E> c)
c
- elements to check.public Collection<E> intersection(Collection<E> c)
c
- public boolean getBit(int bit)
bit
- the bit to read.public void setBit(int bit, boolean value)
bit
- is the bit to set.value
- If true, the bit is set. If false, the bit is cleared.public BitSet getBitSet()
public int size()
public int count()
public int getExpectedNumberOfElements()
public double getExpectedBitsPerElement()
public double getBitsPerElement()
Copyright © 2010–2015. All rights reserved.