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(int bitSetSize,
int expectedNumberOfFilterElements)
Constructs an empty Bloom filter.
|
| 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,
String 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.
|
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.
|
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(int bitSetSize,
int expectedNumberOfFilterElements)
bitSetSize - defines how many bits should be used for the filter.expectedNumberOfFilterElements - defines the maximum number of elements the filter is expected to contain.public static long createHash(String val, String charset) throws UnsupportedEncodingException
val - specifies the input data.charset - specifies the encoding of the input data.UnsupportedEncodingException - if the charset is unsupported.public static long createHash(String val) throws UnsupportedEncodingException
val - specifies the input data. The encoding is expected to be UTF-8.UnsupportedEncodingException - if UTF-8 is not supported.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) throws UnsupportedEncodingException
element - is an element to register in the Bloom filter.UnsupportedEncodingException - if UTF-8 is unsupported.public void addAll(Collection<? extends E> c) throws UnsupportedEncodingException
c - Collection of elements.UnsupportedEncodingException - if UTF-8 is unsupported.public boolean contains(E element) throws UnsupportedEncodingException
element - element to check.UnsupportedEncodingException - if UTF-8 is unsupported.public boolean containsAll(Collection<? extends E> c) throws UnsupportedEncodingException
c - elements to check.UnsupportedEncodingException - if UTF-8 is unsupported.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 int size()
public int count()
Copyright © 2018. All rights reserved.