public class HyperLogLog extends Object implements ICardinality
Note that this implementation does not include the long range correction function defined in the original paper. Empirical evidence shows that the correction function causes more harm than good.
Users have different motivations to use different types of hashing functions. Rather than try to keep up with all available hash functions and to remove the concern of causing future binary incompatibilities this class allows clients to offer the value in hashed int or long form. This way clients are free to change their hash function on their own time line. We recommend using Google's Guava Murmur3_128 implementation as it provides good performance and speed when high precision is required. In our tests the 32bit MurmurHash function included in this project is faster and produces better results than the 32 bit murmur3 implementation google provides.
Modifier and Type | Class and Description |
---|---|
static class |
HyperLogLog.Builder |
protected static class |
HyperLogLog.HyperLogLogMergeException |
Constructor and Description |
---|
HyperLogLog(double rsd)
Create a new HyperLogLog instance using the specified standard deviation.
|
HyperLogLog(int log2m)
Create a new HyperLogLog instance.
|
HyperLogLog(int log2m,
RegisterSet registerSet)
Creates a new HyperLogLog instance using the given registers.
|
Modifier and Type | Method and Description |
---|---|
void |
addAll(HyperLogLog other)
Add all the elements of the other set to this set.
|
long |
cardinality() |
byte[] |
getBytes() |
ICardinality |
merge(ICardinality... estimators)
Merges estimators to produce a new estimator for the combined streams
of this estimator and those passed as arguments.
|
boolean |
offer(Object o) |
boolean |
offerHashed(int hashedValue)
Offer the value as a hashed long value
|
boolean |
offerHashed(long hashedValue)
Offer the value as a hashed long value
|
int |
sizeof() |
public HyperLogLog(double rsd)
rsd
- - the relative standard deviation for the counter.
smaller values create counters that require more space.public HyperLogLog(int log2m)
log2m
- - the number of bits to use as the basis for the HLL instancepublic HyperLogLog(int log2m, RegisterSet registerSet)
registerSet
- - the initial values for the register setpublic boolean offerHashed(long hashedValue)
ICardinality
offerHashed
in interface ICardinality
hashedValue
- - the hash of the item to offer to the estimatorpublic boolean offerHashed(int hashedValue)
ICardinality
offerHashed
in interface ICardinality
hashedValue
- - the hash of the item to offer to the estimatorpublic boolean offer(Object o)
offer
in interface ICardinality
o
- stream elementpublic long cardinality()
cardinality
in interface ICardinality
public int sizeof()
sizeof
in interface ICardinality
public byte[] getBytes() throws IOException
getBytes
in interface ICardinality
IOException
public void addAll(HyperLogLog other) throws CardinalityMergeException
other
- A compatible Hyperloglog instance (same log2m)CardinalityMergeException
- if other is not compatiblepublic ICardinality merge(ICardinality... estimators) throws CardinalityMergeException
ICardinality
merge
in interface ICardinality
estimators
- Zero or more compatible estimatorsCardinalityMergeException
- If at least one of the estimators is not compatible with this oneCopyright © 2019. All rights reserved.