Class CountingBloomFilter
- All Implemented Interfaces:
Writable
A counting Bloom filter is an improvement to standard a Bloom filter as it allows dynamic additions and deletions of set membership information. This is achieved through the use of a counting vector instead of a bit vector.
Originally created by European Commission One-Lab Project 034819.
-
Field Summary
Fields inherited from class org.apache.hadoop.util.bloom.Filter
hash, hashType, nbHash, vectorSize -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor - use with readFieldsCountingBloomFilter(int vectorSize, int nbHash, int hashType) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a key to this filter.voidPeforms a logical AND between this filter and a specified filter.intapproximateCount(Key key) This method calculates an approximate count of the key, i.e. how many times the key was added to the filter.voidRemoves a specified key from this counting Bloom filter.booleanmembershipTest(Key key) Determines wether a specified key belongs to this filter.voidnot()Performs a logical NOT on this filter.voidPeforms a logical OR between this filter and a specified filter.voidreadFields(DataInput in) Deserialize the fields of this object fromin.toString()voidwrite(DataOutput out) Serialize the fields of this object toout.voidPeforms a logical XOR between this filter and a specified filter.
-
Constructor Details
-
CountingBloomFilter
public CountingBloomFilter()Default constructor - use with readFields -
CountingBloomFilter
public CountingBloomFilter(int vectorSize, int nbHash, int hashType) Constructor- Parameters:
vectorSize- The vector size of this filter.nbHash- The number of hash function to consider.hashType- type of the hashing function (seeHash).
-
-
Method Details
-
add
Description copied from class:FilterAdds a key to this filter. -
delete
Removes a specified key from this counting Bloom filter.Invariant: nothing happens if the specified key does not belong to this counter Bloom filter.
- Parameters:
key- The key to remove.
-
and
Description copied from class:FilterPeforms a logical AND between this filter and a specified filter.Invariant: The result is assigned to this filter.
-
membershipTest
Description copied from class:FilterDetermines wether a specified key belongs to this filter.- Specified by:
membershipTestin classFilter- Parameters:
key- The key to test.- Returns:
- boolean True if the specified key belongs to this filter. False otherwise.
-
approximateCount
This method calculates an approximate count of the key, i.e. how many times the key was added to the filter. This allows the filter to be used as an approximatekey -> countmap.NOTE: due to the bucket size of this filter, inserting the same key more than 15 times will cause an overflow at all filter positions associated with this key, and it will significantly increase the error rate for this and other keys. For this reason the filter can only be used to store small count values
0 <= N << 15.- Parameters:
key- key to be tested- Returns:
- 0 if the key is not present. Otherwise, a positive value v will
be returned such that
v == countwith probability equal to the error rate of this filter, andv > countotherwise. Additionally, if the filter experienced an underflow as a result ofdelete(Key)operation, the return value may be lower than thecountwith the probability of the false negative rate of such filter.
-
not
public void not()Description copied from class:FilterPerforms a logical NOT on this filter.The result is assigned to this filter.
-
or
Description copied from class:FilterPeforms a logical OR between this filter and a specified filter.Invariant: The result is assigned to this filter.
-
xor
Description copied from class:FilterPeforms a logical XOR between this filter and a specified filter.Invariant: The result is assigned to this filter.
-
toString
-
write
Description copied from interface:WritableSerialize the fields of this object toout.- Specified by:
writein interfaceWritable- Overrides:
writein classFilter- Parameters:
out-DataOuputto serialize this object into.- Throws:
IOException- any other problem for write.
-
readFields
Description copied from interface:WritableDeserialize the fields of this object fromin.For efficiency, implementations should attempt to re-use storage in the existing object where possible.
- Specified by:
readFieldsin interfaceWritable- Overrides:
readFieldsin classFilter- Parameters:
in-DataInputto deseriablize this object from.- Throws:
IOException- any other problem for readFields.
-