1 /*-------------------------------------------------------------------------
4 * definitions for sampling functions
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/utils/sampling.h
11 *-------------------------------------------------------------------------
16 #include "storage/block.h" /* for typedef BlockNumber */
19 /* Random generator for sampling code */
20 typedef unsigned short SamplerRandomState[3];
22 extern void sampler_random_init_state(long seed,
23 SamplerRandomState randstate);
24 extern double sampler_random_fract(SamplerRandomState randstate);
26 /* Block sampling methods */
28 /* Data structure for Algorithm S from Knuth 3.4.2 */
31 BlockNumber N; /* number of blocks, known in advance */
32 int n; /* desired sample size */
33 BlockNumber t; /* current block number */
34 int m; /* blocks selected so far */
35 SamplerRandomState randstate; /* random generator state */
38 typedef BlockSamplerData *BlockSampler;
40 extern void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
41 int samplesize, long randseed);
42 extern bool BlockSampler_HasMore(BlockSampler bs);
43 extern BlockNumber BlockSampler_Next(BlockSampler bs);
45 /* Reservoir sampling methods */
50 SamplerRandomState randstate; /* random generator state */
53 typedef ReservoirStateData *ReservoirState;
55 extern void reservoir_init_selection_state(ReservoirState rs, int n);
56 extern double reservoir_get_next_S(ReservoirState rs, double t, int n);
58 /* Old API, still in use by assorted FDWs */
59 /* For backwards compatibility, these declarations are duplicated in vacuum.h */
61 extern double anl_random_fract(void);
62 extern double anl_init_selection_state(int n);
63 extern double anl_get_next_S(double t, int n, double *stateptr);
65 #endif /* SAMPLING_H */