PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
_int.h File Reference
#include "utils/array.h"
#include "utils/memutils.h"
Include dependency graph for _int.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GISTTYPE
 
struct  ITEM
 
struct  QUERYTYPE
 

Macros

#define MAXNUMRANGE   100
 
#define ARRPTR(x)   ( (int32 *) ARR_DATA_PTR(x) )
 
#define ARRNELEMS(x)   ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
 
#define CHECKARRVALID(x)
 
#define ARRISEMPTY(x)   (ARRNELEMS(x) == 0)
 
#define SORT(x)
 
#define PREPAREARR(x)
 
#define WISH_F(a, b, c)   (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
 
#define SIGLENINT   63 /* >122 => key will toast, so very slow!!! */
 
#define SIGLEN   ( sizeof(int)*SIGLENINT )
 
#define SIGLENBIT   (SIGLEN*BITS_PER_BYTE)
 
#define LOOPBYTE   for(i=0;i<SIGLEN;i++)
 
#define GETBYTE(x, i)   ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
 
#define GETBITBYTE(x, i)   ( (*((char*)(x)) >> (i)) & 0x01 )
 
#define CLRBIT(x, i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define SETBIT(x, i)   GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
 
#define GETBIT(x, i)   ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
 
#define HASHVAL(val)   (((unsigned int)(val)) % SIGLENBIT)
 
#define HASH(sign, val)   SETBIT((sign), HASHVAL(val))
 
#define ALLISTRUE   0x04
 
#define ISALLTRUE(x)   ( ((GISTTYPE*)x)->flag & ALLISTRUE )
 
#define GTHDRSIZE   (VARHDRSZ + sizeof(int32))
 
#define CALCGTSIZE(flag)   ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
 
#define GETSIGN(x)   ( (BITVECP)( (char*)x+GTHDRSIZE ) )
 
#define BooleanSearchStrategy   20
 
#define HDRSIZEQT   offsetof(QUERYTYPE, items)
 
#define COMPUTESIZE(size)   ( HDRSIZEQT + (size) * sizeof(ITEM) )
 
#define QUERYTYPEMAXITEMS   ((MaxAllocSize - HDRSIZEQT) / sizeof(ITEM))
 
#define GETQUERY(x)   ( (x)->items )
 
#define END   0
 
#define ERR   1
 
#define VAL   2
 
#define OPR   3
 
#define OPEN   4
 
#define CLOSE   5
 
#define DatumGetQueryTypeP(X)   ((QUERYTYPE *) PG_DETOAST_DATUM(X))
 
#define DatumGetQueryTypePCopy(X)   ((QUERYTYPE *) PG_DETOAST_DATUM_COPY(X))
 
#define PG_GETARG_QUERYTYPE_P(n)   DatumGetQueryTypeP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_QUERYTYPE_P_COPY(n)   DatumGetQueryTypePCopy(PG_GETARG_DATUM(n))
 
#define QSORT(a, direction)
 

Typedefs

typedef char BITVEC [SIGLEN]
 
typedef char * BITVECP
 
typedef ArrayType *(* formarray )(ArrayType *, ArrayType *)
 
typedef void(* formfloat )(ArrayType *, float *)
 
typedef struct ITEM ITEM
 
typedef struct QUERYTYPE QUERYTYPE
 

Functions

bool isort (int32 *a, int len)
 
ArrayTypenew_intArrayType (int num)
 
ArrayTypecopy_intArrayType (ArrayType *a)
 
ArrayTyperesize_intArrayType (ArrayType *a, int num)
 
int internal_size (int *a, int len)
 
ArrayType_int_unique (ArrayType *a)
 
int32 intarray_match_first (ArrayType *a, int32 elem)
 
ArrayTypeintarray_add_elem (ArrayType *a, int32 elem)
 
ArrayTypeintarray_concat_arrays (ArrayType *a, ArrayType *b)
 
ArrayTypeint_to_intset (int32 elem)
 
bool inner_int_overlap (ArrayType *a, ArrayType *b)
 
bool inner_int_contains (ArrayType *a, ArrayType *b)
 
ArrayTypeinner_int_union (ArrayType *a, ArrayType *b)
 
ArrayTypeinner_int_inter (ArrayType *a, ArrayType *b)
 
void rt__int_size (ArrayType *a, float *size)
 
void gensign (BITVEC sign, int *a, int len)
 
bool signconsistent (QUERYTYPE *query, BITVEC sign, bool calcnot)
 
bool execconsistent (QUERYTYPE *query, ArrayType *array, bool calcnot)
 
bool gin_bool_consistent (QUERYTYPE *query, bool *check)
 
bool query_has_required_values (QUERYTYPE *query)
 
int compASC (const void *a, const void *b)
 
int compDESC (const void *a, const void *b)
 

Macro Definition Documentation

#define ALLISTRUE   0x04

Definition at line 79 of file _int.h.

#define ARRISEMPTY (   x)    (ARRNELEMS(x) == 0)
#define ARRNELEMS (   x)    ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))

Definition at line 15 of file _int.h.

#define ARRPTR (   x)    ( (int32 *) ARR_DATA_PTR(x) )

Definition at line 14 of file _int.h.

#define BooleanSearchStrategy   20
#define CALCGTSIZE (   flag)    ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )

Definition at line 84 of file _int.h.

#define CHECKARRVALID (   x)
Value:
do { \
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
errmsg("array must not contain nulls"))); \
} while(0)
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ARR_HASNULL(a)
Definition: array.h:272
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3542

Definition at line 18 of file _int.h.

Referenced by _int_contains(), _int_inter(), _int_overlap(), _int_same(), _int_union(), _intbig_contains(), _intbig_overlap(), boolop(), execconsistent(), g_int_compress(), g_int_consistent(), g_int_decompress(), g_int_same(), g_int_union(), g_intbig_compress(), g_intbig_consistent(), ginint4_queryextract(), idx(), inner_int_union(), intarray_add_elem(), intarray_concat_arrays(), intarray_del_elem(), intarray_match_first(), intset_subtract(), sort(), sort_asc(), sort_desc(), subarray(), and uniq().

#define CLOSE   5

Definition at line 150 of file _int.h.

Referenced by gettoken(), gettoken_query(), and makepol().

#define CLRBIT (   x,
  i 
)    GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 63 of file _int.h.

#define COMPUTESIZE (   size)    ( HDRSIZEQT + (size) * sizeof(ITEM) )

Definition at line 140 of file _int.h.

Referenced by bqarr_in(), cleanup_tsquery_stopwords(), parse_tsquery(), QTN2QT(), and queryin().

#define DatumGetQueryTypeP (   X)    ((QUERYTYPE *) PG_DETOAST_DATUM(X))

Definition at line 153 of file _int.h.

Referenced by _int_matchsel().

#define DatumGetQueryTypePCopy (   X)    ((QUERYTYPE *) PG_DETOAST_DATUM_COPY(X))

Definition at line 154 of file _int.h.

#define END   0

Definition at line 145 of file _int.h.

Referenced by gettoken(), gettoken_query(), makepol(), and next().

#define ERR   1
#define GETBIT (   x,
  i 
)    ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )

Definition at line 65 of file _int.h.

#define GETBITBYTE (   x,
  i 
)    ( (*((char*)(x)) >> (i)) & 0x01 )

Definition at line 62 of file _int.h.

#define GETBYTE (   x,
  i 
)    ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )

Definition at line 61 of file _int.h.

#define GETSIGN (   x)    ( (BITVECP)( (char*)x+GTHDRSIZE ) )

Definition at line 86 of file _int.h.

#define GTHDRSIZE   (VARHDRSZ + sizeof(int32))

Definition at line 83 of file _int.h.

#define HASH (   sign,
  val 
)    SETBIT((sign), HASHVAL(val))

Definition at line 67 of file _int.h.

#define HASHVAL (   val)    (((unsigned int)(val)) % SIGLENBIT)

Definition at line 66 of file _int.h.

#define HDRSIZEQT   offsetof(QUERYTYPE, items)

Definition at line 139 of file _int.h.

#define ISALLTRUE (   x)    ( ((GISTTYPE*)x)->flag & ALLISTRUE )

Definition at line 81 of file _int.h.

#define LOOPBYTE   for(i=0;i<SIGLEN;i++)

Definition at line 57 of file _int.h.

#define MAXNUMRANGE   100

Definition at line 11 of file _int.h.

Referenced by g_int_compress(), and g_int_decompress().

#define OPEN   4

Definition at line 149 of file _int.h.

Referenced by gettoken(), gettoken_query(), and makepol().

#define OPR   3

Definition at line 148 of file _int.h.

Referenced by bqarr_in(), findoprnd(), gettoken(), gettoken_query(), infix(), int_query_opr_selec(), and makepol().

#define PG_GETARG_QUERYTYPE_P (   n)    DatumGetQueryTypeP(PG_GETARG_DATUM(n))

Definition at line 155 of file _int.h.

Referenced by boolop(), bqarr_out(), ginint4_consistent(), and ginint4_queryextract().

#define PG_GETARG_QUERYTYPE_P_COPY (   n)    DatumGetQueryTypePCopy(PG_GETARG_DATUM(n))

Definition at line 156 of file _int.h.

#define PREPAREARR (   x)
Value:
do { \
int _nelems_ = ARRNELEMS(x); \
if (_nelems_ > 1) \
if (isort(ARRPTR(x), _nelems_)) \
(x) = _int_unique(x); \
} while(0)
#define ARRNELEMS(x)
Definition: _int.h:15
bool isort(int32 *a, int len)
Definition: _int_tool.c:210
#define ARRPTR(x)
Definition: _int.h:14
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:294

Definition at line 37 of file _int.h.

Referenced by _int_contains(), boolop(), g_int_compress(), and g_int_consistent().

#define QSORT (   a,
  direction 
)
Value:
do { \
int _nelems_ = ARRNELEMS(a); \
if (_nelems_ > 1) \
qsort((void*) ARRPTR(a), _nelems_, sizeof(int32), \
(direction) ? compASC : compDESC ); \
} while(0)
#define ARRNELEMS(x)
Definition: _int.h:15
signed int int32
Definition: c.h:253
#define ARRPTR(x)
Definition: _int.h:14
int compDESC(const void *a, const void *b)
Definition: _int_tool.c:399
int compASC(const void *a, const void *b)
Definition: _int_tool.c:391
#define qsort(a, b, c, d)
Definition: port.h:440

Definition at line 168 of file _int.h.

Referenced by g_int_union(), intset_subtract(), intset_union_elem(), sort(), sort_asc(), and sort_desc().

#define QUERYTYPEMAXITEMS   ((MaxAllocSize - HDRSIZEQT) / sizeof(ITEM))

Definition at line 141 of file _int.h.

Referenced by bqarr_in().

#define SETBIT (   x,
  i 
)    GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )

Definition at line 64 of file _int.h.

#define SIGLEN   ( sizeof(int)*SIGLENINT )

Definition at line 51 of file _int.h.

#define SIGLENBIT   (SIGLEN*BITS_PER_BYTE)

Definition at line 52 of file _int.h.

#define SIGLENINT   63 /* >122 => key will toast, so very slow!!! */

Definition at line 50 of file _int.h.

#define SORT (   x)
Value:
do { \
int _nelems_ = ARRNELEMS(x); \
if (_nelems_ > 1) \
isort(ARRPTR(x), _nelems_); \
} while(0)
#define ARRNELEMS(x)
Definition: _int.h:15
bool isort(int32 *a, int len)
Definition: _int_tool.c:210
#define ARRPTR(x)
Definition: _int.h:14

Definition at line 29 of file _int.h.

Referenced by _int_inter(), _int_overlap(), _int_same(), and _int_union().

#define WISH_F (   a,
  b,
  c 
)    (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )

Definition at line 46 of file _int.h.

Typedef Documentation

typedef char BITVEC[SIGLEN]

Definition at line 54 of file _int.h.

Definition at line 55 of file _int.h.

typedef ArrayType*(* formarray)(ArrayType *, ArrayType *)

Definition at line 91 of file _int.h.

typedef void(* formfloat)(ArrayType *, float *)

Definition at line 92 of file _int.h.

typedef struct ITEM ITEM

Function Documentation

ArrayType* _int_unique ( ArrayType a)

Definition at line 294 of file _int_tool.c.

References ARRNELEMS, ARRPTR, and resize_intArrayType().

Referenced by g_int_union(), inner_int_union(), intset_subtract(), intset_union_elem(), and uniq().

295 {
296  int *tmp,
297  *dr,
298  *data;
299  int num = ARRNELEMS(r);
300 
301  if (num < 2)
302  return r;
303 
304  data = tmp = dr = ARRPTR(r);
305  while (tmp - data < num)
306  {
307  if (*tmp != *dr)
308  *(++dr) = *tmp++;
309  else
310  tmp++;
311  }
312  return resize_intArrayType(r, dr + 1 - ARRPTR(r));
313 }
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:238
#define ARRNELEMS(x)
Definition: cube.c:27
#define ARRPTR(x)
Definition: cube.c:26
int compASC ( const void *  a,
const void *  b 
)

Definition at line 391 of file _int_tool.c.

392 {
393  if (*(const int32 *) a == *(const int32 *) b)
394  return 0;
395  return (*(const int32 *) a > *(const int32 *) b) ? 1 : -1;
396 }
signed int int32
Definition: c.h:253
int compDESC ( const void *  a,
const void *  b 
)

Definition at line 399 of file _int_tool.c.

400 {
401  if (*(const int32 *) a == *(const int32 *) b)
402  return 0;
403  return (*(const int32 *) a < *(const int32 *) b) ? 1 : -1;
404 }
signed int int32
Definition: c.h:253
ArrayType* copy_intArrayType ( ArrayType a)

Definition at line 266 of file _int_tool.c.

References ARRNELEMS, ARRPTR, and new_intArrayType().

Referenced by g_int_picksplit(), and inner_int_union().

267 {
268  ArrayType *r;
269  int n = ARRNELEMS(a);
270 
271  r = new_intArrayType(n);
272  memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int32));
273  return r;
274 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
signed int int32
Definition: c.h:253
#define ARRNELEMS(x)
Definition: cube.c:27
#define ARRPTR(x)
Definition: cube.c:26
bool execconsistent ( QUERYTYPE query,
ArrayType array,
bool  calcnot 
)

Definition at line 310 of file _int_bool.c.

References CHKVAL::arrb, CHKVAL::arre, ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), GETQUERY, and QUERYTYPE::size.

Referenced by g_int_consistent().

311 {
312  CHKVAL chkval;
313 
314  CHECKARRVALID(array);
315  chkval.arrb = ARRPTR(array);
316  chkval.arre = chkval.arrb + ARRNELEMS(array);
317  return execute(GETQUERY(query) + query->size - 1,
318  (void *) &chkval, calcnot,
320 }
static bool checkcondition_arr(void *checkval, ITEM *item)
Definition: _int_bool.c:236
#define CHECKARRVALID(x)
Definition: _int.h:18
#define GETQUERY(x)
Definition: _int.h:142
int32 * arrb
Definition: _int_bool.c:228
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
#define ARRNELEMS(x)
Definition: cube.c:27
int32 * arre
Definition: _int_bool.c:229
#define ARRPTR(x)
Definition: cube.c:26
int32 size
Definition: _int.h:135
void gensign ( BITVEC  sign,
int *  a,
int  len 
)

Definition at line 316 of file _int_tool.c.

References HASH, and i.

317 {
318  int i;
319 
320  /* we assume that the sign vector is previously zeroed */
321  for (i = 0; i < len; i++)
322  {
323  HASH(sign, *a);
324  a++;
325  }
326 }
#define HASH(sign, val)
Definition: hstore_gist.c:38
char sign
Definition: informix.c:693
int i
bool gin_bool_consistent ( QUERYTYPE query,
bool check 
)

Definition at line 337 of file _int_bool.c.

References checkcondition_gin(), execute(), FALSE, GinChkVal::first, GETQUERY, i, GinChkVal::mapped_check, palloc(), QUERYTYPE::size, NODE::type, and VAL.

Referenced by ginint4_consistent().

338 {
339  GinChkVal gcv;
340  ITEM *items = GETQUERY(query);
341  int i,
342  j = 0;
343 
344  if (query->size <= 0)
345  return FALSE;
346 
347  /*
348  * Set up data for checkcondition_gin. This must agree with the query
349  * extraction code in ginint4_queryextract.
350  */
351  gcv.first = items;
352  gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
353  for (i = 0; i < query->size; i++)
354  {
355  if (items[i].type == VAL)
356  gcv.mapped_check[i] = check[j++];
357  }
358 
359  return execute(GETQUERY(query) + query->size - 1,
360  (void *) &gcv, true,
362 }
Definition: _int.h:125
bool * mapped_check
Definition: _int_bool.c:325
#define GETQUERY(x)
Definition: _int.h:142
#define FALSE
Definition: c.h:218
#define VAL
Definition: _int.h:147
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
void * palloc(Size size)
Definition: mcxt.c:891
int i
ITEM * first
Definition: _int_bool.c:324
int32 size
Definition: _int.h:135
static bool checkcondition_gin(void *checkval, ITEM *item)
Definition: _int_bool.c:329
bool inner_int_contains ( ArrayType a,
ArrayType b 
)

Definition at line 13 of file _int_tool.c.

References ARRNELEMS, ARRPTR, FALSE, i, and TRUE.

Referenced by _int_contains(), and g_int_consistent().

14 {
15  int na,
16  nb;
17  int i,
18  j,
19  n;
20  int *da,
21  *db;
22 
23  na = ARRNELEMS(a);
24  nb = ARRNELEMS(b);
25  da = ARRPTR(a);
26  db = ARRPTR(b);
27 
28  i = j = n = 0;
29  while (i < na && j < nb)
30  {
31  if (da[i] < db[j])
32  i++;
33  else if (da[i] == db[j])
34  {
35  n++;
36  i++;
37  j++;
38  }
39  else
40  break; /* db[j] is not in da */
41  }
42 
43  return (n == nb) ? TRUE : FALSE;
44 }
#define FALSE
Definition: c.h:218
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define TRUE
Definition: c.h:214
#define ARRPTR(x)
Definition: cube.c:26
ArrayType* inner_int_inter ( ArrayType a,
ArrayType b 
)

Definition at line 134 of file _int_tool.c.

References ARRISEMPTY, ARRNELEMS, ARRPTR, i, Min, new_intArrayType(), pfree(), and resize_intArrayType().

Referenced by _int_inter(), and g_int_picksplit().

135 {
136  ArrayType *r;
137  int na,
138  nb;
139  int *da,
140  *db,
141  *dr;
142  int i,
143  j,
144  k;
145 
146  if (ARRISEMPTY(a) || ARRISEMPTY(b))
147  return new_intArrayType(0);
148 
149  na = ARRNELEMS(a);
150  nb = ARRNELEMS(b);
151  da = ARRPTR(a);
152  db = ARRPTR(b);
153  r = new_intArrayType(Min(na, nb));
154  dr = ARRPTR(r);
155 
156  i = j = k = 0;
157  while (i < na && j < nb)
158  {
159  if (da[i] < db[j])
160  i++;
161  else if (da[i] == db[j])
162  {
163  if (k == 0 || dr[k - 1] != db[j])
164  dr[k++] = db[j];
165  i++;
166  j++;
167  }
168  else
169  j++;
170  }
171 
172  if (k == 0)
173  {
174  pfree(r);
175  return new_intArrayType(0);
176  }
177  else
178  return resize_intArrayType(r, k);
179 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
#define Min(x, y)
Definition: c.h:802
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:238
void pfree(void *pointer)
Definition: mcxt.c:992
#define ARRISEMPTY(x)
Definition: _int.h:26
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define ARRPTR(x)
Definition: cube.c:26
bool inner_int_overlap ( ArrayType a,
ArrayType b 
)

Definition at line 48 of file _int_tool.c.

References ARRNELEMS, ARRPTR, FALSE, i, and TRUE.

Referenced by _int_overlap(), and g_int_consistent().

49 {
50  int na,
51  nb;
52  int i,
53  j;
54  int *da,
55  *db;
56 
57  na = ARRNELEMS(a);
58  nb = ARRNELEMS(b);
59  da = ARRPTR(a);
60  db = ARRPTR(b);
61 
62  i = j = 0;
63  while (i < na && j < nb)
64  {
65  if (da[i] < db[j])
66  i++;
67  else if (da[i] == db[j])
68  return TRUE;
69  else
70  j++;
71  }
72 
73  return FALSE;
74 }
#define FALSE
Definition: c.h:218
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define TRUE
Definition: c.h:214
#define ARRPTR(x)
Definition: cube.c:26
ArrayType* inner_int_union ( ArrayType a,
ArrayType b 
)

Definition at line 77 of file _int_tool.c.

References _int_unique(), ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, copy_intArrayType(), i, new_intArrayType(), NULL, and resize_intArrayType().

Referenced by _int_union(), g_int_penalty(), and g_int_picksplit().

78 {
79  ArrayType *r = NULL;
80 
81  CHECKARRVALID(a);
82  CHECKARRVALID(b);
83 
84  if (ARRISEMPTY(a) && ARRISEMPTY(b))
85  return new_intArrayType(0);
86  if (ARRISEMPTY(a))
87  r = copy_intArrayType(b);
88  if (ARRISEMPTY(b))
89  r = copy_intArrayType(a);
90 
91  if (!r)
92  {
93  int na = ARRNELEMS(a),
94  nb = ARRNELEMS(b);
95  int *da = ARRPTR(a),
96  *db = ARRPTR(b);
97  int i,
98  j,
99  *dr;
100 
101  r = new_intArrayType(na + nb);
102  dr = ARRPTR(r);
103 
104  /* union */
105  i = j = 0;
106  while (i < na && j < nb)
107  {
108  if (da[i] == db[j])
109  {
110  *dr++ = da[i++];
111  j++;
112  }
113  else if (da[i] < db[j])
114  *dr++ = da[i++];
115  else
116  *dr++ = db[j++];
117  }
118 
119  while (i < na)
120  *dr++ = da[i++];
121  while (j < nb)
122  *dr++ = db[j++];
123 
124  r = resize_intArrayType(r, dr - ARRPTR(r));
125  }
126 
127  if (ARRNELEMS(r) > 1)
128  r = _int_unique(r);
129 
130  return r;
131 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
#define CHECKARRVALID(x)
Definition: _int.h:18
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:238
#define ARRISEMPTY(x)
Definition: _int.h:26
#define NULL
Definition: c.h:226
ArrayType * copy_intArrayType(ArrayType *a)
Definition: _int_tool.c:266
ArrayType * _int_unique(ArrayType *r)
Definition: _int_tool.c:294
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define ARRPTR(x)
Definition: cube.c:26
ArrayType* int_to_intset ( int32  elem)

Definition at line 379 of file _int_tool.c.

References ARRPTR, and new_intArrayType().

Referenced by intset().

380 {
381  ArrayType *result;
382  int32 *aa;
383 
384  result = new_intArrayType(1);
385  aa = ARRPTR(result);
386  aa[0] = n;
387  return result;
388 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
signed int int32
Definition: c.h:253
#define ARRPTR(x)
Definition: cube.c:26
ArrayType* intarray_add_elem ( ArrayType a,
int32  elem 
)

Definition at line 345 of file _int_tool.c.

References ARRNELEMS, ARRPTR, CHECKARRVALID, and new_intArrayType().

Referenced by intarray_push_elem(), and intset_union_elem().

346 {
347  ArrayType *result;
348  int32 *r;
349  int32 c;
350 
351  CHECKARRVALID(a);
352  c = ARRNELEMS(a);
353  result = new_intArrayType(c + 1);
354  r = ARRPTR(result);
355  if (c > 0)
356  memcpy(r, ARRPTR(a), c * sizeof(int32));
357  r[c] = elem;
358  return result;
359 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:253
char * c
#define ARRNELEMS(x)
Definition: cube.c:27
#define ARRPTR(x)
Definition: cube.c:26
ArrayType* intarray_concat_arrays ( ArrayType a,
ArrayType b 
)

Definition at line 362 of file _int_tool.c.

References ARRNELEMS, ARRPTR, CHECKARRVALID, and new_intArrayType().

Referenced by intarray_push_array().

363 {
364  ArrayType *result;
365  int32 ac = ARRNELEMS(a);
366  int32 bc = ARRNELEMS(b);
367 
368  CHECKARRVALID(a);
369  CHECKARRVALID(b);
370  result = new_intArrayType(ac + bc);
371  if (ac)
372  memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32));
373  if (bc)
374  memcpy(ARRPTR(result) + ac, ARRPTR(b), bc * sizeof(int32));
375  return result;
376 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:253
#define ARRNELEMS(x)
Definition: cube.c:27
#define ARRPTR(x)
Definition: cube.c:26
int32 intarray_match_first ( ArrayType a,
int32  elem 
)

Definition at line 329 of file _int_tool.c.

References ARRNELEMS, ARRPTR, CHECKARRVALID, and i.

Referenced by idx().

330 {
331  int32 *aa,
332  c,
333  i;
334 
335  CHECKARRVALID(a);
336  c = ARRNELEMS(a);
337  aa = ARRPTR(a);
338  for (i = 0; i < c; i++)
339  if (aa[i] == elem)
340  return (i + 1);
341  return 0;
342 }
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:253
char * c
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define ARRPTR(x)
Definition: cube.c:26
int internal_size ( int *  a,
int  len 
)

Definition at line 278 of file _int_tool.c.

References i.

Referenced by g_int_decompress().

279 {
280  int i,
281  size = 0;
282 
283  for (i = 0; i < len; i += 2)
284  {
285  if (!i || a[i] != a[i - 1]) /* do not count repeated range */
286  size += a[i + 1] - a[i] + 1;
287  }
288 
289  return size;
290 }
int i
bool isort ( int32 a,
int  len 
)

Definition at line 210 of file _int_tool.c.

References isort_cmp(), and qsort_arg().

211 {
212  bool r = false;
213 
214  qsort_arg(a, len, sizeof(int32), isort_cmp, (void *) &r);
215  return r;
216 }
signed int int32
Definition: c.h:253
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
Definition: qsort_arg.c:113
static int isort_cmp(const void *a, const void *b, void *arg)
Definition: _int_tool.c:189
ArrayType* new_intArrayType ( int  num)

Definition at line 220 of file _int_tool.c.

References ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_OVERHEAD_NONULLS, ArrayType::dataoffset, INT4OID, palloc0(), and SET_VARSIZE.

Referenced by copy_intArrayType(), g_int_decompress(), g_int_union(), inner_int_inter(), inner_int_union(), int_to_intset(), intarray_add_elem(), intarray_concat_arrays(), intset_subtract(), and subarray().

221 {
222  ArrayType *r;
223  int nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
224 
225  r = (ArrayType *) palloc0(nbytes);
226 
227  SET_VARSIZE(r, nbytes);
228  ARR_NDIM(r) = 1;
229  r->dataoffset = 0; /* marker for no null bitmap */
230  ARR_ELEMTYPE(r) = INT4OID;
231  ARR_DIMS(r)[0] = num;
232  ARR_LBOUND(r)[0] = 1;
233 
234  return r;
235 }
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:291
int32 dataoffset
Definition: array.h:80
#define INT4OID
Definition: pg_type.h:316
#define ARR_LBOUND(a)
Definition: array.h:277
#define ARR_DIMS(a)
Definition: array.h:275
void * palloc0(Size size)
Definition: mcxt.c:920
#define ARR_NDIM(a)
Definition: array.h:271
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#define ARR_ELEMTYPE(a)
Definition: array.h:273
bool query_has_required_values ( QUERYTYPE query)

Definition at line 400 of file _int_bool.c.

References contains_required_value(), GETQUERY, and QUERYTYPE::size.

Referenced by ginint4_queryextract().

401 {
402  if (query->size <= 0)
403  return false;
404  return contains_required_value(GETQUERY(query) + query->size - 1);
405 }
static bool contains_required_value(ITEM *curitem)
Definition: _int_bool.c:365
#define GETQUERY(x)
Definition: _int.h:142
int32 size
Definition: _int.h:135
ArrayType* resize_intArrayType ( ArrayType a,
int  num 
)

Definition at line 238 of file _int_tool.c.

References ARR_DATA_OFFSET, ARR_DIMS, ARR_NDIM, ARRNELEMS, i, repalloc(), and SET_VARSIZE.

Referenced by _int_unique(), g_int_compress(), inner_int_inter(), inner_int_union(), intarray_del_elem(), and intset_subtract().

239 {
240  int nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num;
241  int i;
242 
243  /* if no elements, return a zero-dimensional array */
244  if (num == 0)
245  {
246  ARR_NDIM(a) = 0;
247  return a;
248  }
249 
250  if (num == ARRNELEMS(a))
251  return a;
252 
253  a = (ArrayType *) repalloc(a, nbytes);
254 
255  SET_VARSIZE(a, nbytes);
256  /* usually the array should be 1-D already, but just in case ... */
257  for (i = 0; i < ARR_NDIM(a); i++)
258  {
259  ARR_DIMS(a)[i] = num;
260  num = 1;
261  }
262  return a;
263 }
#define ARR_DATA_OFFSET(a)
Definition: array.h:297
#define ARR_DIMS(a)
Definition: array.h:275
#define ARR_NDIM(a)
Definition: array.h:271
#define ARRNELEMS(x)
Definition: cube.c:27
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1021
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
void rt__int_size ( ArrayType a,
float *  size 
)

Definition at line 182 of file _int_tool.c.

References ARRNELEMS.

Referenced by g_int_penalty(), and g_int_picksplit().

183 {
184  *size = (float) ARRNELEMS(a);
185 }
#define ARRNELEMS(x)
Definition: cube.c:27
bool signconsistent ( QUERYTYPE query,
BITVEC  sign,
bool  calcnot 
)

Definition at line 301 of file _int_bool.c.

References checkcondition_bit(), execute(), GETQUERY, and QUERYTYPE::size.

Referenced by g_intbig_consistent().

302 {
303  return execute(GETQUERY(query) + query->size - 1,
304  (void *) sign, calcnot,
306 }
#define GETQUERY(x)
Definition: _int.h:142
char sign
Definition: informix.c:693
static bool execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item))
Definition: _int_bool.c:267
static bool checkcondition_bit(void *checkval, ITEM *item)
Definition: _int_bool.c:258
int32 size
Definition: _int.h:135