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  */
33  double x[FLEXIBLE_ARRAY_MEMBER];
34 } NDBOX;
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, const char *message) pg_attribute_noreturn();
65 extern void cube_scanner_init(const char *str);
66 extern void cube_scanner_finish(void);
67 
68 /* in cubeparse.y */
69 extern int cube_yyparse(NDBOX **result);
unsigned int header
Definition: cubedata.h:27
void cube_scanner_init(const char *str)
signed int int32
Definition: c.h:294
int32 vl_len_
Definition: cubedata.h:12
void cube_scanner_finish(void)
void cube_yyerror(NDBOX **result, const char *message) pg_attribute_noreturn()
Definition: cubedata.h:9
double x[FLEXIBLE_ARRAY_MEMBER]
Definition: cubedata.h:33
#define pg_attribute_noreturn()
Definition: c.h:146
int cube_yyparse(NDBOX **result)
struct NDBOX NDBOX
int cube_yylex(void)