public class BloomFilter
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.util.BitSet |
bs
The bit set.
|
protected int |
k
The number of hash (functions).
|
protected int |
m
The number of bits in the bit set
|
protected int |
n
The number of expected entries.
|
| Constructor and Description |
|---|
BloomFilter()
Create a new BloomFilter with default
p = 0.01 and n = 1000.
|
BloomFilter(double p,
int n)
Create a new BloomFilter.
|
BloomFilter(int m,
int k,
int n)
Create a new BloomFilter.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(byte[] value)
Add a value to the filter.
|
void |
clear()
Clear the filter content.
|
static int |
computeAcceptableN(long k,
long m)
Compute acceptable amount of elements with given
number of hashes and size of filter in bits.
|
static int |
computeOptimalK(long n,
long m)
Compute optimal number of hash functions using expected number
of elements and size of filter in bits.
|
static int |
computeOptimalM(long n,
double p)
Compute optimal size of bloom filter in bits by expected
number of elements and acceptable false positive rate.
|
static double |
computeP(long k,
long m,
double insertedElements)
Compute best-case (uniform hash function) false positive probability.
|
static int[] |
hashK(byte[] value,
int m,
int k)
Compute k hashes based on two hashes using
(hash1+i*hash2)%m;
|
static void |
main(java.lang.String[] args)
Main for testing.
|
boolean |
mightContain(byte[] value)
Test if a value is contained in the filter.
|
static int |
murmur3(byte[] data,
int seed)
Compute the murmur hash for a byte array.
|
java.lang.String |
toString()
Get the string representation.
|
protected java.util.BitSet bs
protected int k
protected int m
protected int n
public BloomFilter()
public BloomFilter(double p,
int n)
p - The acceptable false positive rate.n - The expected number of entries.public BloomFilter(int m,
int k,
int n)
m - The number of bits in the filter.k - The number of hashes used.n - The expected number of values in the filter.public boolean add(byte[] value)
value - The value.public void clear()
public boolean mightContain(byte[] value)
value - The value.public static int computeOptimalM(long n,
double p)
n - Expected number of elements.p - Acceptable false positive rate.public static int computeOptimalK(long n,
long m)
n - Expected number of elements inserted in the bloom filterm - The size of the bloom filter in bits.public static int computeAcceptableN(long k,
long m)
k - Number of hashes.m - The size of the bloom filter in bits.public static double computeP(long k,
long m,
double insertedElements)
k - Number of hashes.m - The size of the bloom filter in bits.n - Number of elements inserted in the filter.public static int[] hashK(byte[] value,
int m,
int k)
value - The byte array.m - The maximum number of values.k - The number of hash values to compute.public static int murmur3(byte[] data,
int seed)
public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)