PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
9typedef 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/* for cubescan.l and cubeparse.y */
63/* All grammar constructs return strings */
64#define YYSTYPE char *
65#ifndef YY_TYPEDEF_YY_SCANNER_T
66#define YY_TYPEDEF_YY_SCANNER_T
67typedef void *yyscan_t;
68#endif
69
70/* in cubescan.l */
71extern int cube_yylex(YYSTYPE *yylval_param, yyscan_t yyscanner);
72extern void cube_yyerror(NDBOX **result, Size scanbuflen,
73 struct Node *escontext,
74 yyscan_t yyscanner,
75 const char *message);
76extern void cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp);
77extern void cube_scanner_finish(yyscan_t yyscanner);
78
79/* in cubeparse.y */
80extern int cube_yyparse(NDBOX **result, Size scanbuflen,
81 struct Node *escontext,
82 yyscan_t yyscanner);
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
int32_t int32
Definition: c.h:498
size_t Size
Definition: c.h:576
int cube_yyparse(NDBOX **result, Size scanbuflen, struct Node *escontext, yyscan_t yyscanner)
void cube_yyerror(NDBOX **result, Size scanbuflen, struct Node *escontext, yyscan_t yyscanner, const char *message)
Definition: cubescan.l:71
void cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp)
Definition: cubescan.l:102
void * yyscan_t
Definition: cubedata.h:67
struct NDBOX NDBOX
void cube_scanner_finish(yyscan_t yyscanner)
Definition: cubescan.l:121
int cube_yylex(YYSTYPE *yylval_param, yyscan_t yyscanner)
const char * str
int YYSTYPE
Definition: psqlscanslash.l:39
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:135