Class ExactSamplerPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.FilterBasePipe<T>
-
- org.pipecraft.pipes.sync.inter.sample.ExactSamplerPipe<T>
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class ExactSamplerPipe<T> extends FilterBasePipe<T>
A pipe sampling exactly m items of an input pipe containing n items, where n is known in advance. The algorithm is an online algorithm choosing a given item with probability {#remaining items to sample}/{#remaining items to visit}.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description ExactSamplerPipe(Pipe<T> input, int n, int m)ConstructorExactSamplerPipe(Pipe<T> input, int n, int m, Random rnd)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanshouldSelect(T item)-
Methods inherited from class org.pipecraft.pipes.sync.inter.FilterBasePipe
close, getProgress, next, peek, start
-
-
-
-
Constructor Detail
-
ExactSamplerPipe
public ExactSamplerPipe(Pipe<T> input, int n, int m, Random rnd)
Constructor- Parameters:
input- The input pipen- The exact number of items in the input pipe. If inaccurate, sampling won't be complete or won't be uniform.m- The number of items to samplernd- The randomizer to use, if consistency is required
-
-
Method Detail
-
shouldSelect
protected boolean shouldSelect(T item)
- Specified by:
shouldSelectin classFilterBasePipe<T>- Parameters:
item- The next item from the input stream- Returns:
- true if and only if the item should be selected
-
-