|
9 | 9 | /* number ranges for compression */ |
10 | 10 | #defineMAXNUMRANGE 100 |
11 | 11 |
|
12 | | -/* dimension of array */ |
13 | | -#defineNDIM 1 |
14 | | - |
15 | 12 | /* useful macros for accessing int4 arrays */ |
16 | 13 | #defineARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) ) |
17 | 14 | #defineARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x)) |
18 | 15 |
|
19 | | -/* reject arrays we can't handle;but allow a NULL or empty array */ |
| 16 | +/* reject arrays we can't handle;to wit, those containing nulls */ |
20 | 17 | #defineCHECKARRVALID(x) \ |
21 | 18 | do { \ |
22 | | -if (x) { \ |
23 | | -if (ARR_NDIM(x) != NDIM && ARR_NDIM(x) != 0) \ |
24 | | -ereport(ERROR, \ |
25 | | -(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \ |
26 | | - errmsg("array must be one-dimensional"))); \ |
27 | | -if (ARR_HASNULL(x)) \ |
28 | | -ereport(ERROR, \ |
29 | | -(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \ |
30 | | - errmsg("array must not contain nulls"))); \ |
31 | | -} \ |
| 19 | +if (ARR_HASNULL(x) && array_contains_nulls(x)) \ |
| 20 | +ereport(ERROR, \ |
| 21 | +(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \ |
| 22 | + errmsg("array must not contain nulls"))); \ |
32 | 23 | } while(0) |
33 | 24 |
|
34 | | -#defineARRISVOID(x) ((x) == NULL ||ARRNELEMS(x) == 0) |
| 25 | +#defineARRISEMPTY(x) (ARRNELEMS(x) == 0) |
35 | 26 |
|
| 27 | +/* sort the elements of the array */ |
36 | 28 | #defineSORT(x) \ |
37 | 29 | do { \ |
38 | | - if ( ARRNELEMS( x ) > 1 ) \ |
39 | | -isort( ARRPTR( x ), ARRNELEMS( x ) ); \ |
| 30 | +int_nelems_ = ARRNELEMS(x); \ |
| 31 | +if (_nelems_ > 1) \ |
| 32 | +isort(ARRPTR(x), _nelems_); \ |
40 | 33 | } while(0) |
41 | 34 |
|
| 35 | +/* sort the elements of the array and remove duplicates */ |
42 | 36 | #definePREPAREARR(x) \ |
43 | 37 | do { \ |
44 | | - if ( ARRNELEMS( x ) > 1 ) \ |
45 | | -if ( isort( ARRPTR( x ), ARRNELEMS( x ) ) ) \ |
46 | | -x = _int_unique( x ); \ |
| 38 | +int_nelems_ = ARRNELEMS(x); \ |
| 39 | +if (_nelems_ > 1) \ |
| 40 | +if (isort(ARRPTR(x), _nelems_)) \ |
| 41 | +(x) = _int_unique(x); \ |
47 | 42 | } while(0) |
48 | 43 |
|
49 | 44 | /* "wish" function */ |
@@ -90,14 +85,14 @@ typedef struct |
90 | 85 | #defineGETSIGN(x)( (BITVECP)( (char*)x+GTHDRSIZE ) ) |
91 | 86 |
|
92 | 87 | /* |
93 | | -** types for functions |
94 | | -*/ |
| 88 | +* types for functions |
| 89 | +*/ |
95 | 90 | typedefArrayType*(*formarray) (ArrayType*,ArrayType*); |
96 | 91 | typedefvoid (*formfloat) (ArrayType*,float*); |
97 | 92 |
|
98 | 93 | /* |
99 | | -** usefulfunction |
100 | | -*/ |
| 94 | + * usefulfunctions |
| 95 | +*/ |
101 | 96 | boolisort(int4*a,intlen); |
102 | 97 | ArrayType*new_intArrayType(intnum); |
103 | 98 | ArrayType*copy_intArrayType(ArrayType*a); |
@@ -133,36 +128,47 @@ typedef struct ITEM |
133 | 128 | int4val; |
134 | 129 | }ITEM; |
135 | 130 |
|
136 | | -typedefstruct |
| 131 | +typedefstructQUERYTYPE |
137 | 132 | { |
138 | 133 | int32vl_len_;/* varlena header (do not touch directly!) */ |
139 | | -int4size; |
140 | | -chardata[1]; |
| 134 | +int4size;/* number of ITEMs */ |
| 135 | +ITEMitems[1];/* variable length array */ |
141 | 136 | }QUERYTYPE; |
142 | 137 |
|
143 | | -#defineHDRSIZEQT(VARHDRSZ + sizeof(int4)) |
144 | | -#defineCOMPUTESIZE(size)( HDRSIZEQT + size * sizeof(ITEM) ) |
145 | | -#defineGETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT ) |
| 138 | +#defineHDRSIZEQToffsetof(QUERYTYPE, items) |
| 139 | +#defineCOMPUTESIZE(size)( HDRSIZEQT +(size) * sizeof(ITEM) ) |
| 140 | +#defineGETQUERY(x) ( (x)->items ) |
146 | 141 |
|
| 142 | +/* "type" codes for ITEM */ |
147 | 143 | #defineEND0 |
148 | 144 | #defineERR1 |
149 | 145 | #defineVAL2 |
150 | 146 | #defineOPR3 |
151 | 147 | #defineOPEN4 |
152 | 148 | #defineCLOSE5 |
153 | 149 |
|
| 150 | +/* fmgr macros for QUERYTYPE objects */ |
| 151 | +#defineDatumGetQueryTypeP(X) ((QUERYTYPE *) PG_DETOAST_DATUM(X)) |
| 152 | +#defineDatumGetQueryTypePCopy(X) ((QUERYTYPE *) PG_DETOAST_DATUM_COPY(X)) |
| 153 | +#definePG_GETARG_QUERYTYPE_P(n) DatumGetQueryTypeP(PG_GETARG_DATUM(n)) |
| 154 | +#definePG_GETARG_QUERYTYPE_P_COPY(n) DatumGetQueryTypePCopy(PG_GETARG_DATUM(n)) |
| 155 | + |
154 | 156 | boolsignconsistent(QUERYTYPE*query,BITVECsign,boolcalcnot); |
155 | 157 | boolexecconsistent(QUERYTYPE*query,ArrayType*array,boolcalcnot); |
156 | | -boolginconsistent(QUERYTYPE*query,bool*check); |
157 | | -int4shorterquery(ITEM*q,int4len); |
158 | 158 |
|
159 | | -intcompASC(constvoid*a,constvoid*b); |
| 159 | +boolgin_bool_consistent(QUERYTYPE*query,bool*check); |
| 160 | +boolquery_has_required_values(QUERYTYPE*query); |
160 | 161 |
|
| 162 | +intcompASC(constvoid*a,constvoid*b); |
161 | 163 | intcompDESC(constvoid*a,constvoid*b); |
162 | 164 |
|
163 | | -#defineQSORT(a,direction)\ |
164 | | -if (ARRNELEMS(a) > 1)\ |
165 | | -qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4),\ |
166 | | -(direction) ? compASC : compDESC ) |
| 165 | +/* sort, either ascending or descending */ |
| 166 | +#defineQSORT(a,direction) \ |
| 167 | +do { \ |
| 168 | +int_nelems_ = ARRNELEMS(a); \ |
| 169 | +if (_nelems_ > 1) \ |
| 170 | +qsort((void*) ARRPTR(a), _nelems_, sizeof(int4), \ |
| 171 | + (direction) ? compASC : compDESC ); \ |
| 172 | +} while(0) |
167 | 173 |
|
168 | 174 | #endif/* ___INT_H__ */ |