Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 ( 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

void add ( const Type &  item)
inline
size_t count ( ) const
inline

number of items seen

Definition at line 61 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::count_.

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_t size ( ) const
inline

size of reservoir

Definition at line 58 of file reservoir_sampling.hpp.

References ReservoirSampling< Type, RNG >::size_.

Member Data Documentation

size_t count_ = 0
private

number of items seen

Definition at line 70 of file reservoir_sampling.hpp.

Referenced by ReservoirSampling< Type, RNG >::add(), and ReservoirSampling< Type, RNG >::count().

RNG& rng_
private

source of randomness

Definition at line 74 of file reservoir_sampling.hpp.

Referenced by ReservoirSampling< Type, RNG >::add().


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