PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sampling.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * sampling.h
4  * definitions for sampling functions
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/utils/sampling.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SAMPLING_H
14 #define SAMPLING_H
15 
16 #include "storage/block.h" /* for typedef BlockNumber */
17 
18 
19 /* Random generator for sampling code */
20 typedef unsigned short SamplerRandomState[3];
21 
22 extern void sampler_random_init_state(long seed,
23  SamplerRandomState randstate);
24 extern double sampler_random_fract(SamplerRandomState randstate);
25 
26 /* Block sampling methods */
27 
28 /* Data structure for Algorithm S from Knuth 3.4.2 */
29 typedef struct
30 {
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 */
37 
39 
40 extern void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
41  int samplesize, long randseed);
42 extern bool BlockSampler_HasMore(BlockSampler bs);
44 
45 /* Reservoir sampling methods */
46 
47 typedef struct
48 {
49  double W;
50  SamplerRandomState randstate; /* random generator state */
52 
54 
55 extern void reservoir_init_selection_state(ReservoirState rs, int n);
56 extern double reservoir_get_next_S(ReservoirState rs, double t, int n);
57 
58 /* Old API, still in use by assorted FDWs */
59 /* For backwards compatibility, these declarations are duplicated in vacuum.h */
60 
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);
64 
65 #endif /* SAMPLING_H */
void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks, int samplesize, long randseed)
Definition: sampling.c:37
bool BlockSampler_HasMore(BlockSampler bs)
Definition: sampling.c:54
uint32 BlockNumber
Definition: block.h:31
unsigned short SamplerRandomState[3]
Definition: sampling.h:20
double reservoir_get_next_S(ReservoirState rs, double t, int n)
Definition: sampling.c:142
BlockNumber t
Definition: sampling.h:33
double anl_random_fract(void)
Definition: sampling.c:262
BlockSamplerData * BlockSampler
Definition: sampling.h:38
void sampler_random_init_state(long seed, SamplerRandomState randstate)
Definition: sampling.c:229
void reservoir_init_selection_state(ReservoirState rs, int n)
Definition: sampling.c:129
double anl_init_selection_state(int n)
Definition: sampling.c:273
double anl_get_next_S(double t, int n, double *stateptr)
Definition: sampling.c:284
BlockNumber N
Definition: sampling.h:31
double sampler_random_fract(SamplerRandomState randstate)
Definition: sampling.c:238
BlockNumber BlockSampler_Next(BlockSampler bs)
Definition: sampling.c:60
SamplerRandomState randstate
Definition: sampling.h:50
ReservoirStateData * ReservoirState
Definition: sampling.h:53
SamplerRandomState randstate
Definition: sampling.h:35