public class ExponentiallyDecayingSample extends Object implements Sample
long
s. Uses Cormode et al's forward-decaying
priority reservoir sampling method to produce a statistically representative sample,
exponentially biased towards newer entries.Constructor and Description |
---|
ExponentiallyDecayingSample(int reservoirSize,
double alpha)
Creates a new
ExponentiallyDecayingSample . |
ExponentiallyDecayingSample(int reservoirSize,
double alpha,
Clock clock)
Creates a new
ExponentiallyDecayingSample . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all recorded values.
|
Snapshot |
getSnapshot()
Returns a snapshot of the sample's values.
|
int |
size()
Returns the number of values recorded.
|
void |
update(long value)
Adds a new recorded value to the sample.
|
void |
update(long value,
long timestamp)
Adds an old value with a fixed timestamp to the sample.
|
public ExponentiallyDecayingSample(int reservoirSize, double alpha)
ExponentiallyDecayingSample
.reservoirSize
- the number of samples to keep in the sampling reservoiralpha
- the exponential decay factor; the higher this is, the more biased the
sample will be towards newer valuespublic ExponentiallyDecayingSample(int reservoirSize, double alpha, Clock clock)
ExponentiallyDecayingSample
.reservoirSize
- the number of samples to keep in the sampling reservoiralpha
- the exponential decay factor; the higher this is, the more biased the
sample will be towards newer valuesclock
- clockpublic void clear()
Sample
public int size()
Sample
public void update(long value)
Sample
public void update(long value, long timestamp)
value
- the value to be addedtimestamp
- the epoch timestamp of value
in secondspublic Snapshot getSnapshot()
Sample
getSnapshot
in interface Sample
Copyright © 2005–2021. All rights reserved.