Class ExponentialHistogram
- java.lang.Object
-
- org.terracotta.statistics.derived.histogram.ExponentialHistogram
-
public class ExponentialHistogram extends Object
An implementation of the Exponential Histogram sketch as outlined by Datar et al.This class is *not thread-safe*, safe consumption in a multi-threaded environment will require some form of external locking.
-
-
Constructor Summary
Constructors Constructor Description ExponentialHistogram(double epsilon, long window)Creates an exponential histogram maintaining a count overwindowto within @{epsilon} fractional accuracy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcount()Returns the approximate current count.doubleepsilon()Return the fractional accuracy of this exponential histogramlongexpire(long time)Expire old events.voidinsert(long time)Insert a single event attimevoidinsert(long time, long count)Bulk insertcountevents attime.voidmerge(ExponentialHistogram b)Merge the supplied ExponentialHistogram in to this one.ExponentialHistogramsplit(double fraction)Split an exponential histogram off this one.StringtoString()
-
-
-
Method Detail
-
merge
public void merge(ExponentialHistogram b)
Merge the supplied ExponentialHistogram in to this one.- Parameters:
b- histogram to merge- Throws:
IllegalArgumentException- if the two merge-thresholds are not equals
-
insert
public void insert(long time, long count) throws IllegalArgumentExceptionBulk insertcountevents attime.- Parameters:
time- event timecount- event count- Throws:
IllegalArgumentException- if count is negative
-
insert
public void insert(long time)
Insert a single event attime- Parameters:
time- event timestamp
-
expire
public long expire(long time)
Expire old events.- Parameters:
time- current timestamp- Returns:
- the count following expiry
-
count
public long count()
Returns the approximate current count.- Returns:
- the approximate count
-
split
public ExponentialHistogram split(double fraction)
Split an exponential histogram off this one.The returned histogram will contain {code fraction} of the events in this one.
- Parameters:
fraction- splitting fraction- Returns:
- the new histogram
-
epsilon
public double epsilon()
Return the fractional accuracy of this exponential histogram- Returns:
- fractional accuracy
-
-