Package org.apache.hadoop.hbase.util
Class BloomFilterChunk
java.lang.Object
org.apache.hadoop.hbase.util.BloomFilterChunk
- All Implemented Interfaces:
BloomFilterBase
The basic building block for the
CompoundBloomFilter
-
Field Summary
Modifier and TypeFieldDescriptionprotected ByteBuffer
Bloom bitsprotected BloomType
The type of bloomprotected long
Bytes (B) in the array.protected final Hash
Hash Functionprotected int
Number of hash functionsprotected final int
Hash typeprotected int
Keys currently in the bloomprotected int
Max Keys expected for the bloom -
Constructor Summary
ConstructorDescriptionBloomFilterChunk
(int maxKeys, double errorRate, int hashType, int foldFactor) Determines & initializes bloom filter meta data from user config.BloomFilterChunk
(int hashType, BloomType bloomType) BloomFilterChunk
(DataInput meta) Loads bloom filter meta data from file input. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Computes the error rate for this Bloom filter, taking into account the actual number of hash functions and keys inserted.(package private) void
add
(byte[] buf, int offset, int len) void
void
(package private) void
bloomCheck
(ByteBuffer bloom) void
Creates another similar Bloom filter.(package private) static boolean
get
(int pos, ByteBuffer bloomBuf, int bloomOffset) Check if bit at specified index is 1.long
Returns Size of the bloom, in bytesint
int
long
Returns The number of keys added to the bloomlong
Returns The max number of keys that can be inserted to maintain the desired error rate(package private) void
(package private) void
set
(long pos) Set the bit at the specified index to 1.private void
setHashLoc
(int hash1, int hash2) toString()
void
writeBloom
(DataOutput out) Writes just the bloom filter to the output array
-
Field Details
-
byteSize
Bytes (B) in the array. This actually has to fit into an int. -
hashCount
Number of hash functions -
hashType
Hash type -
hash
Hash Function -
keyCount
Keys currently in the bloom -
maxKeys
Max Keys expected for the bloom -
bloom
Bloom bits -
bloomType
The type of bloom
-
-
Constructor Details
-
BloomFilterChunk
Loads bloom filter meta data from file input.- Parameters:
meta
- stored bloom meta data- Throws:
IllegalArgumentException
- meta data is invalidIOException
-
BloomFilterChunk
-
BloomFilterChunk
public BloomFilterChunk(int maxKeys, double errorRate, int hashType, int foldFactor) throws IllegalArgumentException Determines & initializes bloom filter meta data from user config. CallallocBloom()
to allocate bloom filter data.- Parameters:
maxKeys
- Maximum expected number of keys that will be stored in this bloomerrorRate
- Desired false positive error rate. Lower rate = more storage requiredhashType
- Type of hash function to usefoldFactor
- When finished adding entries, you may be able to 'fold' this bloom to save space. Tradeoff potentially excess bytes in bloom for ability to fold if keyCount is exponentially greater than maxKeys.- Throws:
IllegalArgumentException
-
-
Method Details
-
actualErrorRate
Computes the error rate for this Bloom filter, taking into account the actual number of hash functions and keys inserted. The return value of this function changes as a Bloom filter is being populated. Used for reporting the actual error rate of compound Bloom filters when writing them out.- Returns:
- error rate for this particular Bloom filter
-
createAnother
Creates another similar Bloom filter. Does not copy the actual bits, and sets the new filter's key count to zero.- Returns:
- a Bloom filter with the same configuration as this
-
allocBloom
-
sanityCheck
- Throws:
IllegalArgumentException
-
bloomCheck
- Throws:
IllegalArgumentException
-
add
-
add
-
setHashLoc
-
set
Set the bit at the specified index to 1.- Parameters:
pos
- index of bit
-
get
Check if bit at specified index is 1.- Parameters:
pos
- index of bit- Returns:
- true if bit at specified index is 1, false if 0.
-
getKeyCount
Description copied from interface:BloomFilterBase
Returns The number of keys added to the bloom- Specified by:
getKeyCount
in interfaceBloomFilterBase
-
getMaxKeys
Description copied from interface:BloomFilterBase
Returns The max number of keys that can be inserted to maintain the desired error rate- Specified by:
getMaxKeys
in interfaceBloomFilterBase
-
getByteSize
Description copied from interface:BloomFilterBase
Returns Size of the bloom, in bytes- Specified by:
getByteSize
in interfaceBloomFilterBase
-
getHashType
-
compactBloom
-
writeBloom
Writes just the bloom filter to the output array- Parameters:
out
- OutputStream to place bloom- Throws:
IOException
- Error writing bloom array
-
getHashCount
-
toString
-