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 AdaptiveCounting| Modifier 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 - IOExceptionClassNotFoundExceptionpublic long cardinality()
cardinality in interface ICardinalitypublic boolean offerHashed(long hashedLong)
ICardinalityofferHashed in interface ICardinalityhashedLong - - the hash of the item to offer to the estimatorpublic boolean offerHashed(int hashedInt)
ICardinalityofferHashed in interface ICardinalityhashedInt - - the hash of the item to offer to the estimatorpublic boolean offer(Object o)
offer in interface ICardinalityo - stream elementpublic int sizeof()
sizeof in interface ICardinalitypublic boolean tipped()
public byte[] getBytes()
throws IOException
getBytes in interface ICardinalityIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic ICardinality merge(ICardinality... estimators) throws CardinalityMergeException
ICardinalitymerge in interface ICardinalityestimators - 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)CardinalityMergeExceptionCopyright © 2014. All Rights Reserved.