ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RandomSampling.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File RandomSampling.h --------------------------*/
3/*--------------------------------------------------------------------------*/
100/*--------------------------------------------------------------------------*/
101/*----------------------------- DEFINITIONS --------------------------------*/
102/*--------------------------------------------------------------------------*/
103
104#ifndef __ADS_RandomSampling
105 #define __ADS_RandomSampling
106/* self-identification: #endif constant */
107
108/*--------------------------------------------------------------------------*/
109/*------------------------------ INCLUDES ----------------------------------*/
110/*--------------------------------------------------------------------------*/
111
112#include "ADS/Contract.h"
116
117#include <algorithm>
118#include <cmath>
119#include <cstddef>
120#include <functional>
121#include <iterator>
122#include <numeric>
123#include <random>
124#include <unordered_set>
125#include <utility>
126#include <vector>
127
128/*--------------------------------------------------------------------------*/
129/*--------------------------- NAMESPACE ------------------------------------*/
130/*--------------------------------------------------------------------------*/
131
132namespace ADS
133{
134
152template< class R >
153std::vector< std::size_t > sampleBySwaps( std::size_t n , std::size_t N ,
154 R & g );
155
176template< class R >
177std::vector< std::size_t > sampleByDictionary( std::size_t n , std::size_t N ,
178 R & g );
179
204template< class R >
205std::vector< std::size_t > sampleBySorting( std::size_t n , std::size_t N ,
206 R & g ,
207 std::size_t * rounds = nullptr );
208
236template< class R >
237std::vector< std::size_t > sampleBySkips( std::size_t n , std::size_t N ,
238 R & g ,
239 std::size_t * randoms = nullptr );
240
263template< class T , class R >
264std::vector< T > heapSampling( const std::vector< T > & S , std::size_t n ,
265 R & g );
266
286template< std::input_iterator I , std::sentinel_for< I > S , class R >
287std::vector< std::iter_value_t< I > > reservoirSampleL( I first , S last ,
288 std::size_t n ,
289 R & g );
290
291/*--------------------------------------------------------------------------*/
292
293} // end( namespace ADS )
294
295/*--------------------------------------------------------------------------*/
296/*-------------------------- IMPLEMENTATION --------------------------------*/
297/*--------------------------------------------------------------------------*/
298
299#include "ADS/numeric/impl/RandomSampling.tpp"
300
301/*--------------------------------------------------------------------------*/
302
303#endif /* RandomSampling.h included */
304
305/*--------------------------------------------------------------------------*/
306/*----------------------- End File RandomSampling.h ------------------------*/
307/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A -ary heap of plain items, beyond the book: the heap of section 10.1 with children per node in a ve...
Insertion Sort (section 2.7.2), as one sorts a hand of cards: is inserted in the sorted prefix ,...
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming),...
std::vector< std::size_t > sampleByDictionary(std::size_t n, std::size_t N, R &g)
of the positions , sorted, by a hash table of those drawn
std::vector< std::iter_value_t< I > > reservoirSampleL(I first, S last, std::size_t n, R &g)
items of , a stream of unknown length, by the skips of Algorithm L, in no particular order; all of th...
std::vector< T > heapSampling(const std::vector< T > &S, std::size_t n, R &g)
items of the stream , in the order of , by the largest of random keys, as if the length of were unk...
std::vector< std::size_t > sampleBySwaps(std::size_t n, std::size_t N, R &g)
of the positions , sorted, by swaps in an array of the positions
std::vector< std::size_t > sampleBySorting(std::size_t n, std::size_t N, R &g, std::size_t *rounds=nullptr)
of the positions , sorted, by a bucket sort of random positions; the rounds of draws go to *rounds,...
std::vector< std::size_t > sampleBySkips(std::size_t n, std::size_t N, R &g, std::size_t *randoms=nullptr)
of the positions , sorted, by the gaps of Vitter's Algorithm D (A when ); the random numbers drawn go...
Definition ADT.h:96