PostgreSQL Source Code  git master
cubedata.h
Go to the documentation of this file.
1 /* contrib/cube/cubedata.h */
2 
3 /*
4  * This limit is pretty arbitrary, but don't make it so large that you
5  * risk overflow in sizing calculations.
6  */
7 #define CUBE_MAX_DIM (100)
8 
9 typedef struct NDBOX
10 {
11  /* varlena header (do not touch directly!) */
13 
14  /*----------
15  * Header contains info about NDBOX. For binary compatibility with old
16  * versions, it is defined as "unsigned int".
17  *
18  * Following information is stored:
19  *
20  * bits 0-7 : number of cube dimensions;
21  * bits 8-30 : unused, initialize to zero;
22  * bit 31 : point flag. If set, the upper right coordinates are not
23  * stored, and are implicitly the same as the lower left
24  * coordinates.
25  *----------
26  */
27  unsigned int header;
28 
29  /*
30  * The lower left coordinates for each dimension come first, followed by
31  * upper right coordinates unless the point flag is set.
32  */
35 
36 /* NDBOX access macros */
37 #define POINT_BIT 0x80000000
38 #define DIM_MASK 0x7fffffff
39 
40 #define IS_POINT(cube) ( ((cube)->header & POINT_BIT) != 0 )
41 #define SET_POINT_BIT(cube) ( (cube)->header |= POINT_BIT )
42 #define DIM(cube) ( (cube)->header & DIM_MASK )
43 #define SET_DIM(cube, _dim) ( (cube)->header = ((cube)->header & ~DIM_MASK) | (_dim) )
44 
45 #define LL_COORD(cube, i) ( (cube)->x[i] )
46 #define UR_COORD(cube, i) ( IS_POINT(cube) ? (cube)->x[i] : (cube)->x[(i) + DIM(cube)] )
47 
48 #define POINT_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim))
49 #define CUBE_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim)*2)
50 
51 /* fmgr interface macros */
52 #define DatumGetNDBOXP(x) ((NDBOX *) PG_DETOAST_DATUM(x))
53 #define PG_GETARG_NDBOX_P(x) DatumGetNDBOXP(PG_GETARG_DATUM(x))
54 #define PG_RETURN_NDBOX_P(x) PG_RETURN_POINTER(x)
55 
56 /* GiST operator strategy numbers */
57 #define CubeKNNDistanceCoord 15 /* ~> */
58 #define CubeKNNDistanceTaxicab 16 /* <#> */
59 #define CubeKNNDistanceEuclid 17 /* <-> */
60 #define CubeKNNDistanceChebyshev 18 /* <=> */
61 
62 /* in cubescan.l */
63 extern int cube_yylex(void);
64 extern void cube_yyerror(NDBOX **result, Size scanbuflen,
65  struct Node *escontext,
66  const char *message);
67 extern void cube_scanner_init(const char *str, Size *scanbuflen);
68 extern void cube_scanner_finish(void);
69 
70 /* in cubeparse.y */
71 extern int cube_yyparse(NDBOX **result, Size scanbuflen,
72  struct Node *escontext);
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:417
int32_t int32
Definition: c.h:481
size_t Size
Definition: c.h:559
int cube_yylex(void)
void cube_scanner_finish(void)
struct NDBOX NDBOX
int cube_yyparse(NDBOX **result, Size scanbuflen, struct Node *escontext)
void cube_yyerror(NDBOX **result, Size scanbuflen, struct Node *escontext, const char *message)
void cube_scanner_init(const char *str, Size *scanbuflen)
const char * str
Definition: cubedata.h:10
double x[FLEXIBLE_ARRAY_MEMBER]
Definition: cubedata.h:33
int32 vl_len_
Definition: cubedata.h:12
unsigned int header
Definition: cubedata.h:27
Definition: nodes.h:129