PostgreSQL Source Code  git master
_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  GISTIntArrayOptions
 
struct  GISTIntArrayBigOptions
 
struct  GISTTYPE
 
struct  ITEM
 
struct  QUERYTYPE
 

Macros

#define G_INT_NUMRANGES_DEFAULT   100
 
#define G_INT_NUMRANGES_MAX
 
#define G_INT_GET_NUMRANGES()
 
#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 SIGLEN_DEFAULT   (63 * 4)
 
#define SIGLEN_MAX   GISTMaxIndexKeySize
 
#define SIGLENBIT(siglen)   ((siglen) * BITS_PER_BYTE)
 
#define GET_SIGLEN()
 
#define LOOPBYTE(siglen)    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, siglen)   (((unsigned int)(val)) % SIGLENBIT(siglen))
 
#define HASH(sign, val, siglen)   SETBIT((sign), HASHVAL(val, siglen))
 
#define ALLISTRUE   0x04
 
#define ISALLTRUE(x)   ( ((GISTTYPE*)x)->flag & ALLISTRUE )
 
#define GTHDRSIZE   (VARHDRSZ + sizeof(int32))
 
#define CALCGTSIZE(flag, siglen)   ( 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 * BITVECP
 
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 *r)
 
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 (BITVECP sign, int *a, int len, int siglen)
 
bool signconsistent (QUERYTYPE *query, BITVECP sign, int siglen, 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

◆ ALLISTRUE

#define ALLISTRUE   0x04

Definition at line 100 of file _int.h.

◆ ARRISEMPTY

#define ARRISEMPTY (   x)    (ARRNELEMS(x) == 0)

Definition at line 38 of file _int.h.

◆ ARRNELEMS

#define ARRNELEMS (   x)    ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))

Definition at line 27 of file _int.h.

◆ ARRPTR

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

Definition at line 26 of file _int.h.

◆ BooleanSearchStrategy

#define BooleanSearchStrategy   20

Definition at line 134 of file _int.h.

◆ CALCGTSIZE

#define CALCGTSIZE (   flag,
  siglen 
)    ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : (siglen)) )

Definition at line 105 of file _int.h.

◆ CHECKARRVALID

#define CHECKARRVALID (   x)
Value:
do { \
ereport(ERROR, \
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \
errmsg("array must not contain nulls"))); \
} while(0)
#define ARR_HASNULL(a)
Definition: array.h:291
bool array_contains_nulls(ArrayType *array)
Definition: arrayfuncs.c:3748
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
int x
Definition: isn.c:71

Definition at line 30 of file _int.h.

◆ CLOSE

#define CLOSE   5

Definition at line 165 of file _int.h.

◆ CLRBIT

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

Definition at line 77 of file _int.h.

◆ COMPUTESIZE

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

Definition at line 155 of file _int.h.

◆ DatumGetQueryTypeP

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

Definition at line 168 of file _int.h.

◆ DatumGetQueryTypePCopy

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

Definition at line 169 of file _int.h.

◆ END

#define END   0

Definition at line 160 of file _int.h.

◆ ERR

#define ERR   1

Definition at line 161 of file _int.h.

◆ G_INT_GET_NUMRANGES

#define G_INT_GET_NUMRANGES ( )
Value:
#define G_INT_NUMRANGES_DEFAULT
Definition: _int.h:11
#define PG_GET_OPCLASS_OPTIONS()
Definition: fmgr.h:342
#define PG_HAS_OPCLASS_OPTIONS()
Definition: fmgr.h:341

Definition at line 14 of file _int.h.

◆ G_INT_NUMRANGES_DEFAULT

#define G_INT_NUMRANGES_DEFAULT   100

Definition at line 11 of file _int.h.

◆ G_INT_NUMRANGES_MAX

#define G_INT_NUMRANGES_MAX
Value:
(2 * sizeof(int32)))
signed int int32
Definition: c.h:481
#define VARHDRSZ
Definition: c.h:679
#define GISTMaxIndexKeySize
Definition: gist.h:102

Definition at line 12 of file _int.h.

◆ GET_SIGLEN

#define GET_SIGLEN ( )
Value:

Definition at line 65 of file _int.h.

◆ GETBIT

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

Definition at line 79 of file _int.h.

◆ GETBITBYTE

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

Definition at line 76 of file _int.h.

◆ GETBYTE

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

Definition at line 75 of file _int.h.

◆ GETQUERY

#define GETQUERY (   x)    ( (x)->items )

Definition at line 157 of file _int.h.

◆ GETSIGN

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

Definition at line 107 of file _int.h.

◆ GTHDRSIZE

#define GTHDRSIZE   (VARHDRSZ + sizeof(int32))

Definition at line 104 of file _int.h.

◆ HASH

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

Definition at line 81 of file _int.h.

◆ HASHVAL

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

Definition at line 80 of file _int.h.

◆ HDRSIZEQT

#define HDRSIZEQT   offsetof(QUERYTYPE, items)

Definition at line 154 of file _int.h.

◆ ISALLTRUE

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

Definition at line 102 of file _int.h.

◆ LOOPBYTE

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

Definition at line 71 of file _int.h.

◆ OPEN

#define OPEN   4

Definition at line 164 of file _int.h.

◆ OPR

#define OPR   3

Definition at line 163 of file _int.h.

◆ PG_GETARG_QUERYTYPE_P

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

Definition at line 170 of file _int.h.

◆ PG_GETARG_QUERYTYPE_P_COPY

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

Definition at line 171 of file _int.h.

◆ PREPAREARR

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

Definition at line 49 of file _int.h.

◆ QSORT

#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)
int compASC(const void *a, const void *b)
Definition: _int_tool.c:398
int compDESC(const void *a, const void *b)
Definition: _int_tool.c:404
int a
Definition: isn.c:69

Definition at line 183 of file _int.h.

◆ QUERYTYPEMAXITEMS

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

Definition at line 156 of file _int.h.

◆ SETBIT

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

Definition at line 78 of file _int.h.

◆ SIGLEN_DEFAULT

#define SIGLEN_DEFAULT   (63 * 4)

Definition at line 62 of file _int.h.

◆ SIGLEN_MAX

#define SIGLEN_MAX   GISTMaxIndexKeySize

Definition at line 63 of file _int.h.

◆ SIGLENBIT

#define SIGLENBIT (   siglen)    ((siglen) * BITS_PER_BYTE)

Definition at line 64 of file _int.h.

◆ SORT

#define SORT (   x)
Value:
do { \
int _nelems_ = ARRNELEMS(x); \
if (_nelems_ > 1) \
isort(ARRPTR(x), _nelems_); \
} while(0)

Definition at line 41 of file _int.h.

◆ VAL

#define VAL   2

Definition at line 162 of file _int.h.

◆ WISH_F

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

Definition at line 58 of file _int.h.

Typedef Documentation

◆ BITVECP

typedef char* BITVECP

Definition at line 69 of file _int.h.

◆ ITEM

typedef struct ITEM ITEM

◆ QUERYTYPE

typedef struct QUERYTYPE QUERYTYPE

Function Documentation

◆ _int_unique()

ArrayType* _int_unique ( ArrayType r)

Definition at line 311 of file _int_tool.c.

312 {
313  int num = ARRNELEMS(r);
314  bool duplicates_found; /* not used */
315 
316  num = qunique_arg(ARRPTR(r), num, sizeof(int), isort_cmp,
317  &duplicates_found);
318 
319  return resize_intArrayType(r, num);
320 }
static int isort_cmp(const void *a, const void *b, void *arg)
Definition: _int_tool.c:191
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:250
#define ARRNELEMS(x)
Definition: cube.c:26
#define ARRPTR(x)
Definition: cube.c:25
static size_t qunique_arg(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *, void *), void *arg)
Definition: qunique.h:46

References ARRNELEMS, ARRPTR, isort_cmp(), qunique_arg(), and resize_intArrayType().

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

◆ compASC()

int compASC ( const void *  a,
const void *  b 
)

Definition at line 398 of file _int_tool.c.

399 {
400  return pg_cmp_s32(*(const int32 *) a, *(const int32 *) b);
401 }
static int pg_cmp_s32(int32 a, int32 b)
Definition: int.h:483
int b
Definition: isn.c:70

References a, b, and pg_cmp_s32().

◆ compDESC()

int compDESC ( const void *  a,
const void *  b 
)

Definition at line 404 of file _int_tool.c.

405 {
406  return pg_cmp_s32(*(const int32 *) b, *(const int32 *) a);
407 }

References a, b, and pg_cmp_s32().

◆ copy_intArrayType()

ArrayType* copy_intArrayType ( ArrayType a)

Definition at line 281 of file _int_tool.c.

282 {
283  ArrayType *r;
284  int n = ARRNELEMS(a);
285 
286  r = new_intArrayType(n);
287  memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int32));
288  return r;
289 }
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:222

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

Referenced by g_int_picksplit(), and inner_int_union().

◆ execconsistent()

bool execconsistent ( QUERYTYPE query,
ArrayType array,
bool  calcnot 
)

Definition at line 308 of file _int_bool.c.

309 {
310  CHKVAL chkval;
311 
312  CHECKARRVALID(array);
313  chkval.arrb = ARRPTR(array);
314  chkval.arre = chkval.arrb + ARRNELEMS(array);
315  return execute(GETQUERY(query) + query->size - 1,
316  (void *) &chkval, NULL, calcnot,
318 }
#define CHECKARRVALID(x)
Definition: _int.h:30
#define GETQUERY(x)
Definition: _int.h:157
static bool checkcondition_arr(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:234
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
Definition: _int_bool.c:265
int32 * arrb
Definition: _int_bool.c:226
int32 * arre
Definition: _int_bool.c:227
int32 size
Definition: _int.h:150

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

Referenced by g_int_consistent().

◆ gensign()

void gensign ( BITVECP  sign,
int *  a,
int  len,
int  siglen 
)

Definition at line 323 of file _int_tool.c.

324 {
325  int i;
326 
327  /* we assume that the sign vector is previously zeroed */
328  for (i = 0; i < len; i++)
329  {
330  HASH(sign, *a, siglen);
331  a++;
332  }
333 }
#define HASH(sign, val, siglen)
Definition: hstore_gist.c:46
char sign
Definition: informix.c:668
int i
Definition: isn.c:73
const void size_t len

References a, HASH, i, len, and sign.

◆ gin_bool_consistent()

bool gin_bool_consistent ( QUERYTYPE query,
bool check 
)

Definition at line 335 of file _int_bool.c.

336 {
337  GinChkVal gcv;
338  ITEM *items = GETQUERY(query);
339  int i,
340  j = 0;
341 
342  if (query->size <= 0)
343  return false;
344 
345  /*
346  * Set up data for checkcondition_gin. This must agree with the query
347  * extraction code in ginint4_queryextract.
348  */
349  gcv.first = items;
350  gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
351  for (i = 0; i < query->size; i++)
352  {
353  if (items[i].type == VAL)
354  gcv.mapped_check[i] = check[j++];
355  }
356 
357  return execute(GETQUERY(query) + query->size - 1,
358  (void *) &gcv, NULL, true,
360 }
#define VAL
Definition: _int.h:162
static bool checkcondition_gin(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:327
int j
Definition: isn.c:74
void * palloc(Size size)
Definition: mcxt.c:1304
ITEM * first
Definition: _int_bool.c:322
bool * mapped_check
Definition: _int_bool.c:323
Definition: _int.h:141
const char * type

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

Referenced by ginint4_consistent().

◆ inner_int_contains()

bool inner_int_contains ( ArrayType a,
ArrayType b 
)

Definition at line 15 of file _int_tool.c.

16 {
17  int na,
18  nb;
19  int i,
20  j,
21  n;
22  int *da,
23  *db;
24 
25  na = ARRNELEMS(a);
26  nb = ARRNELEMS(b);
27  da = ARRPTR(a);
28  db = ARRPTR(b);
29 
30  i = j = n = 0;
31  while (i < na && j < nb)
32  {
33  if (da[i] < db[j])
34  i++;
35  else if (da[i] == db[j])
36  {
37  n++;
38  i++;
39  j++;
40  }
41  else
42  break; /* db[j] is not in da */
43  }
44 
45  return (n == nb);
46 }

References a, ARRNELEMS, ARRPTR, b, i, and j.

Referenced by _int_contains(), and g_int_consistent().

◆ inner_int_inter()

ArrayType* inner_int_inter ( ArrayType a,
ArrayType b 
)

Definition at line 136 of file _int_tool.c.

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

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

Referenced by _int_inter(), and g_int_picksplit().

◆ inner_int_overlap()

bool inner_int_overlap ( ArrayType a,
ArrayType b 
)

Definition at line 50 of file _int_tool.c.

51 {
52  int na,
53  nb;
54  int i,
55  j;
56  int *da,
57  *db;
58 
59  na = ARRNELEMS(a);
60  nb = ARRNELEMS(b);
61  da = ARRPTR(a);
62  db = ARRPTR(b);
63 
64  i = j = 0;
65  while (i < na && j < nb)
66  {
67  if (da[i] < db[j])
68  i++;
69  else if (da[i] == db[j])
70  return true;
71  else
72  j++;
73  }
74 
75  return false;
76 }

References a, ARRNELEMS, ARRPTR, b, i, and j.

Referenced by _int_overlap(), and g_int_consistent().

◆ inner_int_union()

ArrayType* inner_int_union ( ArrayType a,
ArrayType b 
)

Definition at line 79 of file _int_tool.c.

80 {
81  ArrayType *r = NULL;
82 
85 
86  if (ARRISEMPTY(a) && ARRISEMPTY(b))
87  return new_intArrayType(0);
88  if (ARRISEMPTY(a))
89  r = copy_intArrayType(b);
90  if (ARRISEMPTY(b))
91  r = copy_intArrayType(a);
92 
93  if (!r)
94  {
95  int na = ARRNELEMS(a),
96  nb = ARRNELEMS(b);
97  int *da = ARRPTR(a),
98  *db = ARRPTR(b);
99  int i,
100  j,
101  *dr;
102 
103  r = new_intArrayType(na + nb);
104  dr = ARRPTR(r);
105 
106  /* union */
107  i = j = 0;
108  while (i < na && j < nb)
109  {
110  if (da[i] == db[j])
111  {
112  *dr++ = da[i++];
113  j++;
114  }
115  else if (da[i] < db[j])
116  *dr++ = da[i++];
117  else
118  *dr++ = db[j++];
119  }
120 
121  while (i < na)
122  *dr++ = da[i++];
123  while (j < nb)
124  *dr++ = db[j++];
125 
126  r = resize_intArrayType(r, dr - ARRPTR(r));
127  }
128 
129  if (ARRNELEMS(r) > 1)
130  r = _int_unique(r);
131 
132  return r;
133 }
ArrayType * copy_intArrayType(ArrayType *a)
Definition: _int_tool.c:281
ArrayType * _int_unique(ArrayType *r)
Definition: _int_tool.c:311

References _int_unique(), a, ARRISEMPTY, ARRNELEMS, ARRPTR, b, CHECKARRVALID, copy_intArrayType(), i, j, new_intArrayType(), and resize_intArrayType().

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

◆ int_to_intset()

ArrayType* int_to_intset ( int32  elem)

Definition at line 386 of file _int_tool.c.

387 {
388  ArrayType *result;
389  int32 *aa;
390 
391  result = new_intArrayType(1);
392  aa = ARRPTR(result);
393  aa[0] = elem;
394  return result;
395 }

References ARRPTR, and new_intArrayType().

Referenced by intset().

◆ intarray_add_elem()

ArrayType* intarray_add_elem ( ArrayType a,
int32  elem 
)

Definition at line 352 of file _int_tool.c.

353 {
354  ArrayType *result;
355  int32 *r;
356  int32 c;
357 
358  CHECKARRVALID(a);
359  c = ARRNELEMS(a);
360  result = new_intArrayType(c + 1);
361  r = ARRPTR(result);
362  if (c > 0)
363  memcpy(r, ARRPTR(a), c * sizeof(int32));
364  r[c] = elem;
365  return result;
366 }
char * c

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

Referenced by intarray_push_elem(), and intset_union_elem().

◆ intarray_concat_arrays()

ArrayType* intarray_concat_arrays ( ArrayType a,
ArrayType b 
)

Definition at line 369 of file _int_tool.c.

370 {
371  ArrayType *result;
372  int32 ac = ARRNELEMS(a);
373  int32 bc = ARRNELEMS(b);
374 
375  CHECKARRVALID(a);
376  CHECKARRVALID(b);
377  result = new_intArrayType(ac + bc);
378  if (ac)
379  memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32));
380  if (bc)
381  memcpy(ARRPTR(result) + ac, ARRPTR(b), bc * sizeof(int32));
382  return result;
383 }

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

Referenced by intarray_push_array().

◆ intarray_match_first()

int32 intarray_match_first ( ArrayType a,
int32  elem 
)

Definition at line 336 of file _int_tool.c.

337 {
338  int32 *aa,
339  c,
340  i;
341 
342  CHECKARRVALID(a);
343  c = ARRNELEMS(a);
344  aa = ARRPTR(a);
345  for (i = 0; i < c; i++)
346  if (aa[i] == elem)
347  return (i + 1);
348  return 0;
349 }

References a, ARRNELEMS, ARRPTR, CHECKARRVALID, and i.

Referenced by idx().

◆ internal_size()

int internal_size ( int *  a,
int  len 
)

Definition at line 293 of file _int_tool.c.

294 {
295  int i;
296  int64 size = 0;
297 
298  for (i = 0; i < len; i += 2)
299  {
300  if (!i || a[i] != a[i - 1]) /* do not count repeated range */
301  size += (int64) (a[i + 1]) - (int64) (a[i]) + 1;
302  }
303 
304  if (size > (int64) INT_MAX || size < (int64) INT_MIN)
305  return -1; /* overflow */
306  return (int) size;
307 }
static pg_noinline void Size size
Definition: slab.c:607

References a, i, len, and size.

Referenced by g_int_compress(), and g_int_decompress().

◆ isort()

bool isort ( int32 a,
int  len 
)

Definition at line 212 of file _int_tool.c.

213 {
214  bool r = false;
215 
216  qsort_arg(a, len, sizeof(int32), isort_cmp, &r);
217  return r;
218 }
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)

References a, isort_cmp(), len, and qsort_arg().

◆ new_intArrayType()

ArrayType* new_intArrayType ( int  num)

Definition at line 222 of file _int_tool.c.

223 {
224  ArrayType *r;
225  int nbytes;
226 
227  /* if no elements, return a zero-dimensional array */
228  if (num <= 0)
229  {
230  Assert(num == 0);
231  r = construct_empty_array(INT4OID);
232  return r;
233  }
234 
235  nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
236 
237  r = (ArrayType *) palloc0(nbytes);
238 
239  SET_VARSIZE(r, nbytes);
240  ARR_NDIM(r) = 1;
241  r->dataoffset = 0; /* marker for no null bitmap */
242  ARR_ELEMTYPE(r) = INT4OID;
243  ARR_DIMS(r)[0] = num;
244  ARR_LBOUND(r)[0] = 1;
245 
246  return r;
247 }
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_ELEMTYPE(a)
Definition: array.h:292
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:310
#define ARR_DIMS(a)
Definition: array.h:294
#define ARR_LBOUND(a)
Definition: array.h:296
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3561
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1334
int32 dataoffset
Definition: array.h:96
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_OVERHEAD_NONULLS, Assert(), construct_empty_array(), ArrayType::dataoffset, 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().

◆ query_has_required_values()

bool query_has_required_values ( QUERYTYPE query)

Definition at line 398 of file _int_bool.c.

399 {
400  if (query->size <= 0)
401  return false;
402  return contains_required_value(GETQUERY(query) + query->size - 1);
403 }
static bool contains_required_value(ITEM *curitem)
Definition: _int_bool.c:363

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

Referenced by ginint4_queryextract().

◆ resize_intArrayType()

ArrayType* resize_intArrayType ( ArrayType a,
int  num 
)

Definition at line 250 of file _int_tool.c.

251 {
252  int nbytes;
253  int i;
254 
255  /* if no elements, return a zero-dimensional array */
256  if (num <= 0)
257  {
258  Assert(num == 0);
259  a = construct_empty_array(INT4OID);
260  return a;
261  }
262 
263  if (num == ARRNELEMS(a))
264  return a;
265 
266  nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num;
267 
268  a = (ArrayType *) repalloc(a, nbytes);
269 
270  SET_VARSIZE(a, nbytes);
271  /* usually the array should be 1-D already, but just in case ... */
272  for (i = 0; i < ARR_NDIM(a); i++)
273  {
274  ARR_DIMS(a)[i] = num;
275  num = 1;
276  }
277  return a;
278 }
#define ARR_DATA_OFFSET(a)
Definition: array.h:316
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1528

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

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

◆ rt__int_size()

void rt__int_size ( ArrayType a,
float *  size 
)

Definition at line 184 of file _int_tool.c.

185 {
186  *size = (float) ARRNELEMS(a);
187 }

References a, ARRNELEMS, and size.

Referenced by g_int_penalty(), and g_int_picksplit().

◆ signconsistent()

bool signconsistent ( QUERYTYPE query,
BITVECP  sign,
int  siglen,
bool  calcnot 
)

Definition at line 299 of file _int_bool.c.

300 {
301  return execute(GETQUERY(query) + query->size - 1,
302  (void *) sign, (void *) (intptr_t) siglen, calcnot,
304 }
static bool checkcondition_bit(void *checkval, ITEM *item, void *siglen)
Definition: _int_bool.c:256

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

Referenced by g_intbig_consistent().