2 * contrib/intarray/_int.h
10/* number ranges for compression */
11 #define G_INT_NUMRANGES_DEFAULT 100
12 #define G_INT_NUMRANGES_MAX ((GISTMaxIndexKeySize - VARHDRSZ) / \
14 #define G_INT_GET_NUMRANGES() (PG_HAS_OPCLASS_OPTIONS() ? \
15 ((GISTIntArrayOptions *) PG_GET_OPCLASS_OPTIONS())->num_ranges : \
16 G_INT_NUMRANGES_DEFAULT)
18/* gist__int_ops opclass options */
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))
29/* reject arrays we can't handle; to wit, those containing nulls */
30 #define CHECKARRVALID(x) \
32 if (ARR_HASNULL(x) && array_contains_nulls(x)) \
34 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
35 errmsg("array must not contain nulls"))); \
38 #define ARRISEMPTY(x) (ARRNELEMS(x) == 0)
40/* sort the elements of the array */
43 int _nelems_ = ARRNELEMS(x); \
44 bool _ascending = true; \
45 isort(ARRPTR(x), _nelems_, &_ascending); \
48/* sort the elements of the array and remove duplicates */
49 #define PREPAREARR(x) \
51 int _nelems_ = ARRNELEMS(x); \
52 bool _ascending = true; \
53 isort(ARRPTR(x), _nelems_, &_ascending); \
54 (x) = _int_unique(x); \
58 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
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 : \
71 #define LOOPBYTE(siglen) \
72 for (i = 0; i < siglen; i++)
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))
83/* gist__intbig_ops opclass options */
87 int siglen;
/* signature length in bytes */
95 int32 vl_len_;
/* varlena header (do not touch directly!) */
100 #define ALLISTRUE 0x04
102 #define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
104 #define GTHDRSIZE (VARHDRSZ + sizeof(int32))
105 #define CALCGTSIZE(flag, siglen) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : (siglen)) )
107 #define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
130/*****************************************************************************
132 *****************************************************************************/
134 #define BooleanSearchStrategy 20
137 * item in polish notation with back link
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 )
159/* "type" codes for ITEM */
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))
179/* sort, either ascending or descending */
180 #define QSORT(a, direction) \
182 int _nelems_ = ARRNELEMS(a); \
183 bool _ascending = (direction) ? true : false; \
184 isort(ARRPTR(a), _nelems_, &_ascending); \
187#endif /* ___INT_H__ */
bool inner_int_overlap(ArrayType *a, ArrayType *b)
ArrayType * int_to_intset(int32 elem)
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
ArrayType * new_intArrayType(int num)
ArrayType * inner_int_union(ArrayType *a, ArrayType *b)
bool inner_int_contains(ArrayType *a, ArrayType *b)
int32 intarray_match_first(ArrayType *a, int32 elem)
int internal_size(int *a, int len)
ArrayType * copy_intArrayType(ArrayType *a)
bool signconsistent(QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
void isort(int32 *a, size_t len, void *arg)
void rt__int_size(ArrayType *a, float *size)
struct QUERYTYPE QUERYTYPE
bool query_has_required_values(QUERYTYPE *query)
ArrayType * resize_intArrayType(ArrayType *a, int num)
void gensign(BITVECP sign, int *a, int len, int siglen)
bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot)
ArrayType * _int_unique(ArrayType *r)
bool gin_bool_consistent(QUERYTYPE *query, bool *check)
#define FLEXIBLE_ARRAY_MEMBER
ITEM items[FLEXIBLE_ARRAY_MEMBER]