7 #include "utils/array.h"
9 /* number ranges for compression */
10 #define MAXNUMRANGE 100
12 /* dimension of array */
15 /* useful macros for accessing int4 arrays */
16 #define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
17 #define ARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
19 /* reject arrays we can't handle; but allow a NULL or empty array */
20 #define CHECKARRVALID(x) \
23 if (ARR_NDIM(x) != NDIM && ARR_NDIM(x) != 0) \
25 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), \
26 errmsg("array must be one-dimensional"))); \
29 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
30 errmsg("array must not contain nulls"))); \
34 #define ARRISVOID(x) ((x) == NULL || ARRNELEMS(x) == 0)
38 if ( ARRNELEMS( x ) > 1 ) \
39 isort( ARRPTR( x ), ARRNELEMS( x ) ); \
42 #define PREPAREARR(x) \
44 if ( ARRNELEMS( x ) > 1 ) \
45 if ( isort( ARRPTR( x ), ARRNELEMS( x ) ) ) \
46 x = _int_unique( x ); \
50 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
54 #define SIGLENINT 63 /* >122 => key will toast, so very slow!!! */
55 #define SIGLEN ( sizeof(int)*SIGLENINT )
56 #define SIGLENBIT (SIGLEN*BITS_PER_BYTE)
58 typedef char BITVEC
[SIGLEN
];
59 typedef char *BITVECP
;
64 /* beware of multiple evaluation of arguments to these macros! */
65 #define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
66 #define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
67 #define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
68 #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
69 #define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
70 #define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
71 #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
78 int32 vl_len_
; /* varlena header (do not touch directly!) */
83 #define ALLISTRUE 0x04
85 #define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
87 #define GTHDRSIZE (VARHDRSZ + sizeof(int4))
88 #define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
90 #define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
93 ** types for functions
95 typedef ArrayType
*(*formarray
) (ArrayType
*, ArrayType
*);
96 typedef void (*formfloat
) (ArrayType
*, float *);
101 bool isort(int4
*a
, int len
);
102 ArrayType
*new_intArrayType(int num
);
103 ArrayType
*copy_intArrayType(ArrayType
*a
);
104 ArrayType
*resize_intArrayType(ArrayType
*a
, int num
);
105 int internal_size(int *a
, int len
);
106 ArrayType
*_int_unique(ArrayType
*a
);
107 int32
intarray_match_first(ArrayType
*a
, int32 elem
);
108 ArrayType
*intarray_add_elem(ArrayType
*a
, int32 elem
);
109 ArrayType
*intarray_concat_arrays(ArrayType
*a
, ArrayType
*b
);
110 ArrayType
*int_to_intset(int32 elem
);
111 bool inner_int_overlap(ArrayType
*a
, ArrayType
*b
);
112 bool inner_int_contains(ArrayType
*a
, ArrayType
*b
);
113 ArrayType
*inner_int_union(ArrayType
*a
, ArrayType
*b
);
114 ArrayType
*inner_int_inter(ArrayType
*a
, ArrayType
*b
);
115 void rt__int_size(ArrayType
*a
, float *size
);
116 void gensign(BITVEC sign
, int *a
, int len
);
119 /*****************************************************************************
121 *****************************************************************************/
123 #define BooleanSearchStrategy 20
126 * item in polish notation with back link
138 int32 vl_len_
; /* varlena header (do not touch directly!) */
143 #define HDRSIZEQT (VARHDRSZ + sizeof(int4))
144 #define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) )
145 #define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
154 bool signconsistent(QUERYTYPE
* query
, BITVEC sign
, bool calcnot
);
155 bool execconsistent(QUERYTYPE
* query
, ArrayType
*array
, bool calcnot
);
156 bool ginconsistent(QUERYTYPE
* query
, bool *check
);
157 int4
shorterquery(ITEM
* q
, int4 len
);
159 int compASC(const void *a
, const void *b
);
161 int compDESC(const void *a
, const void *b
);
163 #define QSORT(a, direction) \
164 if (ARRNELEMS(a) > 1) \
165 qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
166 (direction) ? compASC : compDESC )
168 #endif /* ___INT_H__ */