|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.tomp2p.rpc.SimpleBloomFilter<E>
E
- The type of object the BloomFilter should containpublic class SimpleBloomFilter<E>
A simple Bloom Filter (see http://en.wikipedia.org/wiki/Bloom_filter) that uses java.util.Random as a primitive hash function, and which implements Java's Set interface for convenience. Only the add(), addAll(), contains(), and containsAll() methods are implemented. Calling any other method will yield an UnsupportedOperationException. This code may be used, modified, and redistributed provided that the author tag below remains intact.
Constructor Summary | |
---|---|
SimpleBloomFilter(byte[] rawBitArray)
Constructs a SimpleBloomFilter out of existing data. |
|
SimpleBloomFilter(byte[] rawBitArray,
int offset,
int length)
Constructs a SimpleBloomFilter out of existing data. |
|
SimpleBloomFilter(org.jboss.netty.buffer.ChannelBuffer channelBuffer,
int length)
|
|
SimpleBloomFilter(int bitArraySize,
int expectedElements)
Construct an empty SimpleBloomFilter. |
|
SimpleBloomFilter(int bitArraySize,
int expectedElements,
BitSet bitSet)
Constructs a SimpleBloomFilter out of existing data. |
Method Summary | ||
---|---|---|
boolean |
add(E o)
|
|
boolean |
addAll(Collection<? extends E> c)
|
|
static int |
byteArrayToInt(byte[] me,
int offset)
|
|
void |
clear()
Clear the Bloom Filter |
|
boolean |
contains(Object o)
|
|
boolean |
containsAll(Collection<?> c)
|
|
boolean |
equals(Object obj)
|
|
double |
expectedFalsePositiveProbability()
Calculates the approximate probability of the contains() method returning true for an object that had not previously been inserted into the bloom filter. |
|
BitSet |
getBitSet()
Returns the bitset that backs the bloom filter |
|
int |
getExpectedElements()
Returns the expected elements that was provided by the user. |
|
int |
hashCode()
|
|
static byte[] |
intToByteArray(int value1,
int value2,
byte[] me)
|
|
boolean |
isEmpty()
Not implemented |
|
Iterator<E> |
iterator()
Not implemented |
|
SimpleBloomFilter<E> |
merge(SimpleBloomFilter<E> toMerge)
|
|
boolean |
remove(Object o)
Not implemented |
|
boolean |
removeAll(Collection<?> c)
Not implemented |
|
boolean |
retainAll(Collection<?> c)
Not implemented |
|
int |
size()
Not implemented |
|
Object[] |
toArray()
Not implemented |
|
|
toArray(T[] a)
Not implemented |
|
byte[] |
toByteArray()
Returns a byte array of at least length 8. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SimpleBloomFilter(int bitArraySize, int expectedElements)
bitArraySize
- The number of bits in the bit array (often called 'm' in the context of bloom filters).expectedElements
- The typical number of items you expect to be added to the SimpleBloomFilter (often called
'n').public SimpleBloomFilter(byte[] rawBitArray)
bitArraySize
- The number of bits in the bit array (often called 'm' in the context of bloom filters).expectedElements
- The typical number of items you expect to be added to the SimpleBloomFilter (often called
'n').rawBitArray
- The data that will be used in the backing BitSetpublic SimpleBloomFilter(org.jboss.netty.buffer.ChannelBuffer channelBuffer, int length)
public SimpleBloomFilter(byte[] rawBitArray, int offset, int length)
bitArraySize
- The number of bits in the bit array (often called 'm' in the context of bloom filters).expectedElements
- The typical number of items you expect to be added to the SimpleBloomFilter (often called
'n').rawBitArray
- The data that will be used in the backing BitSetoffset
- The offset of the arraylength
- The length of the arraypublic SimpleBloomFilter(int bitArraySize, int expectedElements, BitSet bitSet)
bitArraySize
- The number of bits in the bit array (often called 'm' in the context of bloom filters).expectedElements
- he typical number of items you expect to be added to the SimpleBloomFilter (often called
'n').bitSet
- The data that will be used in the backing BitSet
RuntimeException
- If bitArraySize is not a multiple of eight.Method Detail |
---|
public double expectedFalsePositiveProbability()
public int getExpectedElements()
public boolean add(E o)
add
in interface Collection<E>
add
in interface Set<E>
public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
addAll
in interface Set<E>
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface Set<E>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
containsAll
in interface Set<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface Set<E>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E>
removeAll
in interface Set<E>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<E>
retainAll
in interface Set<E>
public int size()
size
in interface Collection<E>
size
in interface Set<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface Set<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in interface Set<E>
public BitSet getBitSet()
public byte[] toByteArray()
public static final byte[] intToByteArray(int value1, int value2, byte[] me)
public static final int byteArrayToInt(byte[] me, int offset)
public SimpleBloomFilter<E> merge(SimpleBloomFilter<E> toMerge)
public boolean equals(Object obj)
equals
in interface Collection<E>
equals
in interface Set<E>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in interface Set<E>
hashCode
in class Object
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |