Update copyright for 2022
[pgsql.git] / src / include / utils / sampling.h
blobc773b59bd9713a872f301647190b564ee951a0c1
1 /*-------------------------------------------------------------------------
3 * sampling.h
4 * definitions for sampling functions
6 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/utils/sampling.h
11 *-------------------------------------------------------------------------
13 #ifndef SAMPLING_H
14 #define SAMPLING_H
16 #include "common/pg_prng.h"
17 #include "storage/block.h" /* for typedef BlockNumber */
20 /* Random generator for sampling code */
21 extern void sampler_random_init_state(uint32 seed,
22 pg_prng_state *randstate);
23 extern double sampler_random_fract(pg_prng_state *randstate);
25 /* Block sampling methods */
27 /* Data structure for Algorithm S from Knuth 3.4.2 */
28 typedef struct
30 BlockNumber N; /* number of blocks, known in advance */
31 int n; /* desired sample size */
32 BlockNumber t; /* current block number */
33 int m; /* blocks selected so far */
34 pg_prng_state randstate; /* random generator state */
35 } BlockSamplerData;
37 typedef BlockSamplerData *BlockSampler;
39 extern BlockNumber BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
40 int samplesize, uint32 randseed);
41 extern bool BlockSampler_HasMore(BlockSampler bs);
42 extern BlockNumber BlockSampler_Next(BlockSampler bs);
44 /* Reservoir sampling methods */
46 typedef struct
48 double W;
49 pg_prng_state randstate; /* random generator state */
50 } ReservoirStateData;
52 typedef ReservoirStateData *ReservoirState;
54 extern void reservoir_init_selection_state(ReservoirState rs, int n);
55 extern double reservoir_get_next_S(ReservoirState rs, double t, int n);
57 /* Old API, still in use by assorted FDWs */
58 /* For backwards compatibility, these declarations are duplicated in vacuum.h */
60 extern double anl_random_fract(void);
61 extern double anl_init_selection_state(int n);
62 extern double anl_get_next_S(double t, int n, double *stateptr);
64 #endif /* SAMPLING_H */