public class CountThenEstimate extends Object implements ICardinality, Externalizable
Avoids allocating a large block of memory for cardinality estimation until a specified "tipping point" cardinality is reached.
Currently supports serialization with LinearCounting or AdaptiveCountingModifier and Type | Class and Description |
---|---|
protected static class |
CountThenEstimate.CountThenEstimateMergeException |
Modifier and Type | Field and Description |
---|---|
protected static byte |
AC |
protected IBuilder<ICardinality> |
builder
Factory for instantiating estimator after the tipping point is reached
|
protected Set<Object> |
counter
Cardinality counter
Null after tipping point is reached
|
protected ICardinality |
estimator
Cardinality estimator
Null until tipping point is reached
|
protected static byte |
HLC |
protected static byte |
HLPC |
protected static byte |
LC |
protected static byte |
LLC |
protected boolean |
tipped
True after switching to estimation
|
protected int |
tippingPoint
Cardinality after which exact counting gives way to estimation
|
Constructor and Description |
---|
CountThenEstimate()
Default constructor
Exact counts up to 1000, estimation done with default Builder
|
CountThenEstimate(byte[] bytes)
Deserialization constructor
|
CountThenEstimate(int tippingPoint,
IBuilder<ICardinality> builder) |
Modifier and Type | Method and Description |
---|---|
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.
|
static CountThenEstimate |
mergeEstimators(CountThenEstimate... estimators)
Merges estimators to produce an estimator for their combined streams
|
boolean |
offer(Object o) |
boolean |
offerHashed(int hashedInt)
Offer the value as a hashed long value
|
boolean |
offerHashed(long hashedLong)
Offer the value as a hashed long value
|
void |
readExternal(ObjectInput in) |
int |
sizeof() |
boolean |
tipped() |
void |
writeExternal(ObjectOutput out) |
protected static final byte LC
protected static final byte AC
protected static final byte HLC
protected static final byte LLC
protected static final byte HLPC
protected int tippingPoint
protected boolean tipped
protected IBuilder<ICardinality> builder
protected ICardinality estimator
public CountThenEstimate()
public CountThenEstimate(int tippingPoint, IBuilder<ICardinality> builder)
tippingPoint
- Cardinality at which exact counting gives way to estimationbuilder
- Factory for instantiating estimator after the tipping point is reachedpublic CountThenEstimate(byte[] bytes) throws IOException, ClassNotFoundException
bytes
- IOException
ClassNotFoundException
public long cardinality()
cardinality
in interface ICardinality
public boolean offerHashed(long hashedLong)
ICardinality
offerHashed
in interface ICardinality
hashedLong
- - the hash of the item to offer to the estimatorpublic boolean offerHashed(int hashedInt)
ICardinality
offerHashed
in interface ICardinality
hashedInt
- - the hash of the item to offer to the estimatorpublic boolean offer(Object o)
offer
in interface ICardinality
o
- stream elementpublic int sizeof()
sizeof
in interface ICardinality
public boolean tipped()
public byte[] getBytes() throws IOException
getBytes
in interface ICardinality
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public 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 onepublic static CountThenEstimate mergeEstimators(CountThenEstimate... estimators) throws CardinalityMergeException
estimators
- CountThenEstimate.CountThenEstimateMergeException
- if estimators are not mergeable (all must be CountThenEstimate made with the same builder)CardinalityMergeException
Copyright © 2019. All rights reserved.