class UniformTimeReservoir extends java.lang.Object implements TimeReservoir<java.lang.Long>
longs. Uses Vitter's Algorithm R to produce a statistically representative
sample.| Modifier and Type | Field and Description |
|---|---|
private static int |
BITS_PER_LONG |
private java.util.concurrent.atomic.AtomicLong |
count |
private static int |
DEFAULT_SIZE |
private long |
startTime |
private java.util.concurrent.TimeUnit |
startTimeUnit |
private java.util.concurrent.atomic.AtomicLongArray |
values |
| Constructor and Description |
|---|
UniformTimeReservoir(int size,
long startTime,
java.util.concurrent.TimeUnit startTimeUnit)
Creates a new
UniformTimeReservoir instance. |
UniformTimeReservoir(long startTime,
java.util.concurrent.TimeUnit startTimeUnit)
Creates a new
UniformTimeReservoir instance of 1024 elements, which offers a 99.9% confidence level
with a 5% margin of error assuming a normal distribution. |
| Modifier and Type | Method and Description |
|---|---|
UniformTimeSnapshot |
getSnapshot(long time,
java.util.concurrent.TimeUnit timeUnit)
Returns a snapshot of the reservoir's values at given time or newer.
|
long |
interval(java.util.concurrent.TimeUnit timeUnit)
The time interval this reservoir stores data of.
|
private static long |
nextLong(long n)
Get a pseudo-random long uniformly between 0 and n-1.
|
int |
size(long time,
java.util.concurrent.TimeUnit timeUnit)
Returns the number of values recorded at given time or newer.
|
void |
update(java.lang.Long value,
long time,
java.util.concurrent.TimeUnit timeUnit)
Adds a new recorded value to the reservoir bound to a given time.
|
private final long startTime
private final java.util.concurrent.TimeUnit startTimeUnit
private static final int DEFAULT_SIZE
private static final int BITS_PER_LONG
private final java.util.concurrent.atomic.AtomicLong count
private final java.util.concurrent.atomic.AtomicLongArray values
public UniformTimeReservoir(long startTime,
java.util.concurrent.TimeUnit startTimeUnit)
UniformTimeReservoir instance of 1024 elements, which offers a 99.9% confidence level
with a 5% margin of error assuming a normal distribution.startTime - The start timestartTimeUnit - The start time unitpublic UniformTimeReservoir(int size,
long startTime,
java.util.concurrent.TimeUnit startTimeUnit)
UniformTimeReservoir instance.size - the number of samples to keep in the sampling reservoirstartTime - The start timestartTimeUnit - The start time unitpublic int size(long time,
java.util.concurrent.TimeUnit timeUnit)
TimeReservoirsize in interface TimeReservoir<java.lang.Long>time - The time to get the size fortimeUnit - Time unit of the provided timepublic void update(java.lang.Long value,
long time,
java.util.concurrent.TimeUnit timeUnit)
TimeReservoirupdate in interface TimeReservoir<java.lang.Long>value - a new recorded valuetime - The time the recorded value occurred attimeUnit - Time unit of the provided timeprivate static long nextLong(long n)
Random.nextInt().n - the bound[0..n).public UniformTimeSnapshot getSnapshot(long time, java.util.concurrent.TimeUnit timeUnit)
TimeReservoirgetSnapshot in interface TimeReservoir<java.lang.Long>time - The time for which to get the snapshottimeUnit - Time unit of the provided timepublic long interval(java.util.concurrent.TimeUnit timeUnit)
TimeReservoirinterval in interface TimeReservoir<java.lang.Long>timeUnit - The time unit in which to get the interval