Package com.codahale.metrics
Class UniformReservoir
java.lang.Object
com.codahale.metrics.UniformReservoir
- All Implemented Interfaces:
Reservoir
A random sampling reservoir of a stream of
longs. Uses Vitter's Algorithm R to produce a
statistically representative sample.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final AtomicLongprivate static final intprivate final AtomicLongArray -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newUniformReservoirof 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution.UniformReservoir(int size) Creates a newUniformReservoir. -
Method Summary
-
Field Details
-
DEFAULT_SIZE
private static final int DEFAULT_SIZE- See Also:
-
BITS_PER_LONG
private static final int BITS_PER_LONG- See Also:
-
count
-
values
-
-
Constructor Details
-
UniformReservoir
public UniformReservoir()Creates a newUniformReservoirof 1028 elements, which offers a 99.9% confidence level with a 5% margin of error assuming a normal distribution. -
UniformReservoir
public UniformReservoir(int size) Creates a newUniformReservoir.- Parameters:
size- the number of samples to keep in the sampling reservoir
-
-
Method Details
-
size
public int size()Description copied from interface:ReservoirReturns the number of values recorded. -
update
public void update(long value) Description copied from interface:ReservoirAdds a new recorded value to the reservoir. -
nextLong
private static long nextLong(long n) Get a pseudo-random long uniformly between 0 and n-1. Stolen fromRandom.nextInt().- Parameters:
n- the bound- Returns:
- a value select randomly from the range
[0..n).
-
getSnapshot
Description copied from interface:ReservoirReturns a snapshot of the reservoir's values.- Specified by:
getSnapshotin interfaceReservoir- Returns:
- a snapshot of the reservoir's values
-