Thrill  0.1
ReservoirSampling< Type, RNG > Class Template Reference

Detailed Description

template<typename Type, typename RNG = std::default_random_engine>
class thrill::common::ReservoirSampling< Type, RNG >

Implementation of reservoir sampling using Vitter's Algorithm R.

The reservoir size is fixed, new items replace old ones such that all items in the stream are sampled with the same uniform probability.

Definition at line 32 of file reservoir_sampling.hpp.

#include <reservoir_sampling.hpp>

Public Member Functions

 ReservoirSampling (size_t size, std::vector< Type > &samples, RNG &rng)
 initialize reservoir sampler More...
 
void add (const Type &item)
 visit item, maybe add it to the sample. More...
 
size_t count () const
 number of items seen More...
 
const std::vector< Type > & samples () const
 access to samples More...
 
size_t size () const
 size of reservoir More...
 

Private Attributes

size_t count_ = 0
 number of items seen More...
 
RNG & rng_
 source of randomness More...
 
std::vector< Type > & samples_
 reservoir More...
 
size_t size_
 size of reservoir More...
 

Constructor & Destructor Documentation

◆ ReservoirSampling()

ReservoirSampling ( size_t  size,
std::vector< Type > &  samples,
RNG &  rng 
)
inline

initialize reservoir sampler

Definition at line 36 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::samples_, and ReservoirSampling< Type, RNG >::size_.

Member Function Documentation

◆ add()

void add ( const Type &  item)
inline

◆ count()

size_t count ( ) const
inline

number of items seen

Definition at line 61 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::count_.

◆ samples()

const std::vector<Type>& samples ( ) const
inline

access to samples

Definition at line 64 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::samples_.

◆ size()

size_t size ( ) const
inline

size of reservoir

Definition at line 58 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::size_.

Member Data Documentation

◆ count_

◆ rng_

◆ samples_

◆ size_


The documentation for this class was generated from the following file: