Package org.apache.hadoop.util.bloom
Class Filter
java.lang.Object
org.apache.hadoop.util.bloom.Filter
- All Implemented Interfaces:
Writable
- Direct Known Subclasses:
BloomFilter,CountingBloomFilter,DynamicBloomFilter
@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
public abstract class Filter
extends Object
implements Writable
Defines the general behavior of a filter.
A filter is a data structure which aims at offering a lossy summary of a set A. The
key idea is to map entries of A (also called keys) into several positions
in a vector through the use of several hash functions.
Typically, a filter will be implemented as a Bloom filter (or a Bloom filter extension).
It must be extended in order to define the real behavior.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashFunctionThe hash function used to map a key to several positions in the vector.protected intType of hashing function to use.protected intThe number of hash function to consider.protected intThe vector size of this filter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Collection<Key> keys) Adds a collection of keys to this filter.voidAdds a list of keys to this filter.abstract voidAdds a key to this filter.voidAdds an array of keys to this filter.abstract voidPeforms a logical AND between this filter and a specified filter.abstract booleanmembershipTest(Key key) Determines wether a specified key belongs to this filter.abstract voidnot()Performs a logical NOT on this filter.abstract voidPeforms a logical OR between this filter and a specified filter.voidreadFields(DataInput in) Deserialize the fields of this object fromin.voidwrite(DataOutput out) Serialize the fields of this object toout.abstract voidPeforms a logical XOR between this filter and a specified filter.
-
Field Details
-
vectorSize
protected int vectorSizeThe vector size of this filter. -
hash
The hash function used to map a key to several positions in the vector. -
nbHash
protected int nbHashThe number of hash function to consider. -
hashType
protected int hashTypeType of hashing function to use.
-
-
Constructor Details
-
Filter
protected Filter() -
Filter
protected Filter(int vectorSize, int nbHash, int hashType) Constructor.- Parameters:
vectorSize- The vector size of this filter.nbHash- The number of hash functions to consider.hashType- type of the hashing function (seeHash).
-
-
Method Details
-
add
Adds a key to this filter.- Parameters:
key- The key to add.
-
membershipTest
Determines wether a specified key belongs to this filter.- Parameters:
key- The key to test.- Returns:
- boolean True if the specified key belongs to this filter. False otherwise.
-
and
Peforms a logical AND between this filter and a specified filter.Invariant: The result is assigned to this filter.
- Parameters:
filter- The filter to AND with.
-
or
Peforms a logical OR between this filter and a specified filter.Invariant: The result is assigned to this filter.
- Parameters:
filter- The filter to OR with.
-
xor
Peforms a logical XOR between this filter and a specified filter.Invariant: The result is assigned to this filter.
- Parameters:
filter- The filter to XOR with.
-
not
public abstract void not()Performs a logical NOT on this filter.The result is assigned to this filter.
-
add
Adds a list of keys to this filter.- Parameters:
keys- The list of keys.
-
add
Adds a collection of keys to this filter.- Parameters:
keys- The collection of keys.
-
add
Adds an array of keys to this filter.- Parameters:
keys- The array of keys.
-
write
Description copied from interface:WritableSerialize the fields of this object toout.- Specified by:
writein interfaceWritable- 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- Parameters:
in-DataInputto deseriablize this object from.- Throws:
IOException- any other problem for readFields.
-