PostgreSQL Source Code: contrib/intarray/_int.h Source File

PostgreSQL Source Code git master
_int.h
Go to the documentation of this file.
1/*
2 * contrib/intarray/_int.h
3 */
4#ifndef ___INT_H__
5#define ___INT_H__
6
7#include "utils/array.h"
8#include "utils/memutils.h"
9
10/* number ranges for compression */
11 #define G_INT_NUMRANGES_DEFAULT 100
12 #define G_INT_NUMRANGES_MAX ((GISTMaxIndexKeySize - VARHDRSZ) / \
13 (2 * sizeof(int32)))
14 #define G_INT_GET_NUMRANGES() (PG_HAS_OPCLASS_OPTIONS() ? \
15 ((GISTIntArrayOptions *) PG_GET_OPCLASS_OPTIONS())->num_ranges : \
16 G_INT_NUMRANGES_DEFAULT)
17
18/* gist__int_ops opclass options */
19 typedef struct
20{
21 int32 vl_len_; /* varlena header (do not touch directly!) */
22 int num_ranges; /* number of ranges */
23} GISTIntArrayOptions;
24
25/* useful macros for accessing int4 arrays */
26 #define ARRPTR(x) ( (int32 *) ARR_DATA_PTR(x) )
27 #define ARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
28
29/* reject arrays we can't handle; to wit, those containing nulls */
30 #define CHECKARRVALID(x) \
31 do { \
32 if (ARR_HASNULL(x) && array_contains_nulls(x)) \
33 ereport(ERROR, \
34 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
35 errmsg("array must not contain nulls"))); \
36 } while(0)
37
38 #define ARRISEMPTY(x) (ARRNELEMS(x) == 0)
39
40/* sort the elements of the array */
41 #define SORT(x) \
42 do { \
43 int _nelems_ = ARRNELEMS(x); \
44 bool _ascending = true; \
45 isort(ARRPTR(x), _nelems_, &_ascending); \
46 } while(0)
47
48/* sort the elements of the array and remove duplicates */
49 #define PREPAREARR(x) \
50 do { \
51 int _nelems_ = ARRNELEMS(x); \
52 bool _ascending = true; \
53 isort(ARRPTR(x), _nelems_, &_ascending); \
54 (x) = _int_unique(x); \
55 } while(0)
56
57/* "wish" function */
58 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
59
60
61/* bigint defines */
62 #define SIGLEN_DEFAULT (63 * 4)
63 #define SIGLEN_MAX GISTMaxIndexKeySize
64 #define SIGLENBIT(siglen) ((siglen) * BITS_PER_BYTE)
65 #define GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \
66 ((GISTIntArrayBigOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \
67 SIGLEN_DEFAULT)
68
69 typedef char *BITVECP;
70
71 #define LOOPBYTE(siglen) \
72 for (i = 0; i < siglen; i++)
73
74/* beware of multiple evaluation of arguments to these macros! */
75 #define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
76 #define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
77 #define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
78 #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
79 #define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
80 #define HASHVAL(val, siglen) (((unsigned int)(val)) % SIGLENBIT(siglen))
81 #define HASH(sign, val, siglen) SETBIT((sign), HASHVAL(val, siglen))
82
83/* gist__intbig_ops opclass options */
84 typedef struct
85{
86 int32 vl_len_; /* varlena header (do not touch directly!) */
87 int siglen; /* signature length in bytes */
88} GISTIntArrayBigOptions;
89
90/*
91 * type of index key
92 */
93typedef struct
94{
95 int32 vl_len_; /* varlena header (do not touch directly!) */
96 int32 flag;
97 char data[FLEXIBLE_ARRAY_MEMBER];
98} GISTTYPE;
99
100 #define ALLISTRUE 0x04
101
102 #define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
103
104 #define GTHDRSIZE (VARHDRSZ + sizeof(int32))
105 #define CALCGTSIZE(flag, siglen) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : (siglen)) )
106
107 #define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
108
109/*
110 * useful functions
111 */
112 void isort(int32 *a, size_t len, void *arg);
113ArrayType *new_intArrayType(int num);
114ArrayType *copy_intArrayType(ArrayType *a);
115ArrayType *resize_intArrayType(ArrayType *a, int num);
116int internal_size(int *a, int len);
117ArrayType *_int_unique(ArrayType *r);
118int32 intarray_match_first(ArrayType *a, int32 elem);
119ArrayType *intarray_add_elem(ArrayType *a, int32 elem);
120ArrayType *intarray_concat_arrays(ArrayType *a, ArrayType *b);
121ArrayType *int_to_intset(int32 elem);
122bool inner_int_overlap(ArrayType *a, ArrayType *b);
123bool inner_int_contains(ArrayType *a, ArrayType *b);
124ArrayType *inner_int_union(ArrayType *a, ArrayType *b);
125ArrayType *inner_int_inter(ArrayType *a, ArrayType *b);
126void rt__int_size(ArrayType *a, float *size);
127void gensign(BITVECP sign, int *a, int len, int siglen);
128
129
130/*****************************************************************************
131 * Boolean Search
132 *****************************************************************************/
133
134 #define BooleanSearchStrategy 20
135
136/*
137 * item in polish notation with back link
138 * to left operand
139 */
140 typedef struct ITEM
141{
142 int16 type;
143 int16 left;
144 int32 val;
145 } ITEM;
146
147 typedef struct QUERYTYPE
148{
149 int32 vl_len_; /* varlena header (do not touch directly!) */
150 int32 size; /* number of ITEMs */
151 ITEM items[FLEXIBLE_ARRAY_MEMBER];
152 } QUERYTYPE;
153
154 #define HDRSIZEQT offsetof(QUERYTYPE, items)
155 #define COMPUTESIZE(size) ( HDRSIZEQT + (size) * sizeof(ITEM) )
156 #define QUERYTYPEMAXITEMS ((MaxAllocSize - HDRSIZEQT) / sizeof(ITEM))
157 #define GETQUERY(x) ( (x)->items )
158
159/* "type" codes for ITEM */
160 #define END 0
161 #define ERR 1
162 #define VAL 2
163 #define OPR 3
164 #define OPEN 4
165 #define CLOSE 5
166
167/* fmgr macros for QUERYTYPE objects */
168 #define DatumGetQueryTypeP(X) ((QUERYTYPE *) PG_DETOAST_DATUM(X))
169 #define DatumGetQueryTypePCopy(X) ((QUERYTYPE *) PG_DETOAST_DATUM_COPY(X))
170 #define PG_GETARG_QUERYTYPE_P(n) DatumGetQueryTypeP(PG_GETARG_DATUM(n))
171 #define PG_GETARG_QUERYTYPE_P_COPY(n) DatumGetQueryTypePCopy(PG_GETARG_DATUM(n))
172
173bool signconsistent(QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot);
174bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot);
175
176bool gin_bool_consistent(QUERYTYPE *query, bool *check);
177bool query_has_required_values(QUERYTYPE *query);
178
179/* sort, either ascending or descending */
180 #define QSORT(a, direction) \
181 do { \
182 int _nelems_ = ARRNELEMS(a); \
183 bool _ascending = (direction) ? true : false; \
184 isort(ARRPTR(a), _nelems_, &_ascending); \
185 } while(0)
186
187#endif /* ___INT_H__ */
bool inner_int_overlap(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:50
ArrayType * int_to_intset(int32 elem)
Definition: _int_tool.c:388
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:371
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:224
ArrayType * inner_int_union(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:79
bool inner_int_contains(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:15
int32 intarray_match_first(ArrayType *a, int32 elem)
Definition: _int_tool.c:338
int internal_size(int *a, int len)
Definition: _int_tool.c:295
ArrayType * copy_intArrayType(ArrayType *a)
Definition: _int_tool.c:283
bool signconsistent(QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
Definition: _int_bool.c:298
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition: _int_tool.c:354
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:136
void isort(int32 *a, size_t len, void *arg)
void rt__int_size(ArrayType *a, float *size)
Definition: _int_tool.c:184
struct ITEM ITEM
struct QUERYTYPE QUERYTYPE
bool query_has_required_values(QUERYTYPE *query)
Definition: _int_bool.c:397
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:252
char * BITVECP
Definition: _int.h:69
void gensign(BITVECP sign, int *a, int len, int siglen)
Definition: _int_tool.c:325
bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot)
Definition: _int_bool.c:307
ArrayType * _int_unique(ArrayType *r)
Definition: _int_tool.c:313
bool gin_bool_consistent(QUERYTYPE *query, bool *check)
Definition: _int_bool.c:334
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:470
int16_t int16
Definition: c.h:533
int32_t int32
Definition: c.h:534
char * BITVECP
Definition: hstore_gist.c:31
char sign
Definition: informix.c:693
b
int b
Definition: isn.c:74
a
int a
Definition: isn.c:73
void * arg
const void size_t len
const void * data
Definition: array.h:93
int32 vl_len_
Definition: _int.h:86
int num_ranges
Definition: _int.h:22
int32 vl_len_
Definition: _int.h:21
Definition: _int.h:141
int16 left
Definition: _int.h:143
int32 val
Definition: _int.h:144
int16 type
Definition: _int.h:142
Definition: _int.h:148
int32 vl_len_
Definition: _int.h:149
ITEM items[FLEXIBLE_ARRAY_MEMBER]
Definition: _int.h:151
int32 size
Definition: _int.h:150
char * flag(int b)
Definition: test-ctype.c:33

AltStyle によって変換されたページ (->オリジナル) /