T - The type of object held in the reservoir.public final class ReservoirItemsSketch<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> ReservoirItemsSketch<T> |
getInstance(int k)
Construct a mergeable sampling sketch with up to k samples using the default resize
factor (8).
|
static <T> ReservoirItemsSketch<T> |
getInstance(int k,
ResizeFactor rf)
Construct a mergeable sampling sketch with up to k samples using a specified resize factor.
|
static <T> ReservoirItemsSketch<T> |
getInstance(Memory srcMem,
ArrayOfItemsSerDe<T> serDe)
Returns a sketch instance of this class from the given srcMem,
which must be a Memory representation of this sketch class.
|
int |
getK()
Returns the sketch's value of k, the maximum number of samples stored in the
reservoir.
|
long |
getN()
Returns the number of items processed from the input stream
|
int |
getNumSamples()
Returns the current number of items in the reservoir, which may be smaller than the
reservoir capacity.
|
ArrayList<T> |
getRawSamplesAsList()
Returns the actual List backing the reservoir.
|
T[] |
getSamples()
Returns a copy of the items in the reservoir, or null if empty.
|
T[] |
getSamples(Class<?> clazz)
Returns a copy of the items in the reservoir as members of Class clazz, or null
if empty.
|
byte[] |
toByteArray(ArrayOfItemsSerDe<? super T> serDe)
Returns a byte array representation of this sketch.
|
byte[] |
toByteArray(ArrayOfItemsSerDe<? super T> serDe,
Class<?> clazz)
Returns a byte array representation of this sketch.
|
String |
toString()
Returns a human-readable summary of the sketch, without data.
|
void |
update(T item)
Randomly decide whether or not to include an item in the sample set.
|
public static <T> ReservoirItemsSketch<T> getInstance(int k)
T - The type of object held in the reservoir.k - Maximum size of sampling. Allocated size may be smaller until reservoir fills.
Unlike many sketches in this package, this value does not need to be a
power of 2.public static <T> ReservoirItemsSketch<T> getInstance(int k, ResizeFactor rf)
T - The type of object held in the reservoir.k - Maximum size of sampling. Allocated size may be smaller until reservoir fills.
Unlike many sketches in this package, this value does not need to be a
power of 2.rf - See Resize Factorpublic static <T> ReservoirItemsSketch<T> getInstance(Memory srcMem, ArrayOfItemsSerDe<T> serDe)
T - The type of item this sketch containssrcMem - a Memory representation of a sketch of this class.
See MemoryserDe - An instance of ArrayOfItemsSerDepublic int getK()
public long getN()
public int getNumSamples()
public void update(T item)
item - a unit-weight (equivalently, unweighted) item of the set being sampled frompublic T[] getSamples()
In order to allocate an array of generic type T, uses the class of the first item in the array. This method method may throw an ArrayAssignmentException if the reservoir stores instances of a polymorphic base class.
public T[] getSamples(Class<?> clazz)
This method allocates an array of class clazz, which must either match or extend T. This method should be used when objects in the array are all instances of T but are not necessarily instances of the base class.
clazz - A class to which the items are cast before returningpublic ArrayList<T> getRawSamplesAsList()
This method should be used only when making a copy of the returned samples, to avoid an extraneous array copy.
public String toString()
public byte[] toByteArray(ArrayOfItemsSerDe<? super T> serDe)
serDe - An instance of ArrayOfItemsSerDepublic byte[] toByteArray(ArrayOfItemsSerDe<? super T> serDe, Class<?> clazz)
serDe - An instance of ArrayOfItemsSerDeclazz - The class represented by <T>Copyright © 2015–2017 Yahoo! Inc.. All rights reserved.