#include "utils/array.h"

Go to the source code of this file.
Data Structures | |
| struct | GISTTYPE |
| struct | ITEM |
| struct | QUERYTYPE |
Defines | |
| #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 |
| #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 | 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) |
| ArrayType * | new_intArrayType (int num) |
| ArrayType * | copy_intArrayType (ArrayType *a) |
| ArrayType * | resize_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) |
| ArrayType * | intarray_add_elem (ArrayType *a, int32 elem) |
| ArrayType * | intarray_concat_arrays (ArrayType *a, ArrayType *b) |
| ArrayType * | int_to_intset (int32 elem) |
| bool | inner_int_overlap (ArrayType *a, ArrayType *b) |
| bool | inner_int_contains (ArrayType *a, ArrayType *b) |
| ArrayType * | inner_int_union (ArrayType *a, ArrayType *b) |
| ArrayType * | inner_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) |
| #define ARRISEMPTY | ( | x | ) | (ARRNELEMS(x) == 0) |
Definition at line 25 of file _int.h.
Referenced by _int_overlap(), g_int_compress(), g_int_decompress(), g_intbig_compress(), inner_int_inter(), inner_int_union(), intarray_del_elem(), and subarray().
| #define ARRNELEMS | ( | x | ) | ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x)) |
| #define BooleanSearchStrategy 20 |
Definition at line 118 of file _int.h.
Referenced by g_int_consistent(), g_intbig_consistent(), ginint4_consistent(), and ginint4_queryextract().
| #define CALCGTSIZE | ( | flag | ) | ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) ) |
| #define CHECKARRVALID | ( | x | ) |
do { \ if (ARR_HASNULL(x) && array_contains_nulls(x)) \ ereport(ERROR, \ (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), \ errmsg("array must not contain nulls"))); \ } while(0)
Definition at line 17 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 COMPUTESIZE | ( | size | ) | ( HDRSIZEQT + (size) * sizeof(ITEM) ) |
Definition at line 139 of file _int.h.
Referenced by bqarr_in(), parse_tsquery(), plainto_tsquery_byid(), QTN2QT(), queryin(), and to_tsquery_byid().
| #define DatumGetQueryTypeP | ( | X | ) | ((QUERYTYPE *) PG_DETOAST_DATUM(X)) |
| #define DatumGetQueryTypePCopy | ( | X | ) | ((QUERYTYPE *) PG_DETOAST_DATUM_COPY(X)) |
| #define ERR 1 |
Definition at line 144 of file _int.h.
Referenced by cclass(), element(), getcvec(), gettoken(), gettoken_query(), lacon(), lexdigits(), makepol(), newdfa(), pickss(), prefixes(), and range().
| #define GETQUERY | ( | x | ) | ( (x)->items ) |
Definition at line 140 of file _int.h.
Referenced by boolop(), bqarr_in(), bqarr_out(), calc_rank(), CompareTSQ(), Cover(), execconsistent(), get_docrep(), gin_bool_consistent(), gin_extract_tsquery(), gin_tsquery_consistent(), ginint4_queryextract(), gist_qtxt(), gtsvector_consistent(), hlCover(), hlfinditem(), join_tsqueries(), ltxtq_exec(), ltxtq_out(), makeTSQuerySign(), mcelem_tsquery_selec(), parse_tsquery(), plainto_tsquery_byid(), QTN2QT(), query_has_required_values(), queryin(), signconsistent(), SortAndUniqItems(), to_tsquery_byid(), ts_match_vq(), tsa_rewrite_accum(), tsq_mcontains(), tsquery_not(), tsquery_rewrite(), tsquery_rewrite_query(), tsqueryout(), tsqueryrecv(), tsquerysend(), and tsquerytree().
| #define MAXNUMRANGE 100 |
Definition at line 10 of file _int.h.
Referenced by g_int_compress(), and g_int_decompress().
| #define OPR 3 |
Definition at line 146 of file _int.h.
Referenced by bqarr_in(), findoprnd(), infix(), and makepol().
| #define PG_GETARG_QUERYTYPE_P | ( | n | ) | DatumGetQueryTypeP(PG_GETARG_DATUM(n)) |
Definition at line 153 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)) |
| #define PREPAREARR | ( | x | ) |
do { \ int _nelems_ = ARRNELEMS(x); \ if (_nelems_ > 1) \ if (isort(ARRPTR(x), _nelems_)) \ (x) = _int_unique(x); \ } while(0)
Definition at line 36 of file _int.h.
Referenced by _int_contains(), boolop(), g_int_compress(), and g_int_consistent().
| #define QSORT | ( | a, | ||
| direction | ||||
| ) |
do { \ int _nelems_ = ARRNELEMS(a); \ if (_nelems_ > 1) \ qsort((void*) ARRPTR(a), _nelems_, sizeof(int32), \ (direction) ? compASC : compDESC ); \ } while(0)
Definition at line 166 of file _int.h.
Referenced by g_int_union(), intset_subtract(), intset_union_elem(), sort(), sort_asc(), and sort_desc().
| #define SORT | ( | x | ) |
Definition at line 28 of file _int.h.
Referenced by _int_inter(), _int_overlap(), _int_same(), and _int_union().
| #define VAL 2 |
Definition at line 145 of file _int.h.
Referenced by contains_required_value(), execute(), findoprnd(), gettoken(), gin_bool_consistent(), ginint4_queryextract(), infix(), ltree_execute(), and makepol().
Definition at line 293 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().
{
int *tmp,
*dr,
*data;
int num = ARRNELEMS(r);
if (num < 2)
return r;
data = tmp = dr = ARRPTR(r);
while (tmp - data < num)
{
if (*tmp != *dr)
*(++dr) = *tmp++;
else
tmp++;
}
return resize_intArrayType(r, dr + 1 - ARRPTR(r));
}
| int compASC | ( | const void * | a, | |
| const void * | b | |||
| ) |
| int compDESC | ( | const void * | a, | |
| const void * | b | |||
| ) |
Definition at line 265 of file _int_tool.c.
References ARRNELEMS, ARRPTR, and new_intArrayType().
Referenced by g_int_picksplit(), and inner_int_union().
Definition at line 318 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().
| void gensign | ( | BITVEC | sign, | |
| int * | a, | |||
| int | len | |||
| ) |
Definition at line 345 of file _int_bool.c.
References checkcondition_gin(), execute(), GinChkVal::first, GETQUERY, i, GinChkVal::mapped_check, palloc(), QUERYTYPE::size, NODE::type, and VAL.
Referenced by ginint4_consistent().
{
GinChkVal gcv;
ITEM *items = GETQUERY(query);
int i,
j = 0;
if (query->size <= 0)
return FALSE;
/*
* Set up data for checkcondition_gin. This must agree with the query
* extraction code in ginint4_queryextract.
*/
gcv.first = items;
gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
for (i = 0; i < query->size; i++)
{
if (items[i].type == VAL)
gcv.mapped_check[i] = check[j++];
}
return execute(GETQUERY(query) + query->size - 1,
(void *) &gcv, true,
checkcondition_gin);
}
Definition at line 13 of file _int_tool.c.
References ARRNELEMS, ARRPTR, i, and TRUE.
Referenced by _int_contains(), and g_int_consistent().
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().
{
ArrayType *r;
int na,
nb;
int *da,
*db,
*dr;
int i,
j,
k;
if (ARRISEMPTY(a) || ARRISEMPTY(b))
return new_intArrayType(0);
na = ARRNELEMS(a);
nb = ARRNELEMS(b);
da = ARRPTR(a);
db = ARRPTR(b);
r = new_intArrayType(Min(na, nb));
dr = ARRPTR(r);
i = j = k = 0;
while (i < na && j < nb)
{
if (da[i] < db[j])
i++;
else if (da[i] == db[j])
{
if (k == 0 || dr[k - 1] != db[j])
dr[k++] = db[j];
i++;
j++;
}
else
j++;
}
if (k == 0)
{
pfree(r);
return new_intArrayType(0);
}
else
return resize_intArrayType(r, k);
}
Definition at line 48 of file _int_tool.c.
References ARRNELEMS, ARRPTR, and i.
Referenced by _int_overlap(), and g_int_consistent().
Definition at line 77 of file _int_tool.c.
References _int_unique(), ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, copy_intArrayType(), i, new_intArrayType(), and resize_intArrayType().
Referenced by _int_union(), g_int_penalty(), and g_int_picksplit().
{
ArrayType *r = NULL;
CHECKARRVALID(a);
CHECKARRVALID(b);
if (ARRISEMPTY(a) && ARRISEMPTY(b))
return new_intArrayType(0);
if (ARRISEMPTY(a))
r = copy_intArrayType(b);
if (ARRISEMPTY(b))
r = copy_intArrayType(a);
if (!r)
{
int na = ARRNELEMS(a),
nb = ARRNELEMS(b);
int *da = ARRPTR(a),
*db = ARRPTR(b);
int i,
j,
*dr;
r = new_intArrayType(na + nb);
dr = ARRPTR(r);
/* union */
i = j = 0;
while (i < na && j < nb)
{
if (da[i] == db[j])
{
*dr++ = da[i++];
j++;
}
else if (da[i] < db[j])
*dr++ = da[i++];
else
*dr++ = db[j++];
}
while (i < na)
*dr++ = da[i++];
while (j < nb)
*dr++ = db[j++];
r = resize_intArrayType(r, dr - ARRPTR(r));
}
if (ARRNELEMS(r) > 1)
r = _int_unique(r);
return r;
}
Definition at line 378 of file _int_tool.c.
References ARRPTR, and new_intArrayType().
Referenced by intset().
{
ArrayType *result;
int32 *aa;
result = new_intArrayType(1);
aa = ARRPTR(result);
aa[0] = n;
return result;
}
Definition at line 344 of file _int_tool.c.
References ARRNELEMS, ARRPTR, CHECKARRVALID, and new_intArrayType().
Referenced by intarray_push_elem(), and intset_union_elem().
{
ArrayType *result;
int32 *r;
int32 c;
CHECKARRVALID(a);
c = ARRNELEMS(a);
result = new_intArrayType(c + 1);
r = ARRPTR(result);
if (c > 0)
memcpy(r, ARRPTR(a), c * sizeof(int32));
r[c] = elem;
return result;
}
Definition at line 361 of file _int_tool.c.
References ARRNELEMS, ARRPTR, CHECKARRVALID, and new_intArrayType().
Referenced by intarray_push_array().
{
ArrayType *result;
int32 ac = ARRNELEMS(a);
int32 bc = ARRNELEMS(b);
CHECKARRVALID(a);
CHECKARRVALID(b);
result = new_intArrayType(ac + bc);
if (ac)
memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32));
if (bc)
memcpy(ARRPTR(result) + ac, ARRPTR(b), bc * sizeof(int32));
return result;
}
Definition at line 328 of file _int_tool.c.
References ARRNELEMS, ARRPTR, CHECKARRVALID, and i.
Referenced by idx().
{
int32 *aa,
c,
i;
CHECKARRVALID(a);
c = ARRNELEMS(a);
aa = ARRPTR(a);
for (i = 0; i < c; i++)
if (aa[i] == elem)
return (i + 1);
return 0;
}
| int internal_size | ( | int * | a, | |
| int | len | |||
| ) |
Definition at line 277 of file _int_tool.c.
References i.
Referenced by g_int_decompress().
{
int i,
size = 0;
for (i = 0; i < len; i += 2)
{
if (!i || a[i] != a[i - 1]) /* do not count repeated range */
size += a[i + 1] - a[i] + 1;
}
return size;
}
Definition at line 189 of file _int_tool.c.
References cur.
{
int32 cur,
prev;
int32 *pcur,
*pprev,
*end;
bool r = FALSE;
/*
* We use a simple insertion sort. While this is O(N^2) in the worst
* case, it's quite fast if the input is already sorted or nearly so.
* Also, for not-too-large inputs it's faster than more complex methods
* anyhow.
*/
end = a + len;
for (pcur = a + 1; pcur < end; pcur++)
{
cur = *pcur;
for (pprev = pcur - 1; pprev >= a; pprev--)
{
prev = *pprev;
if (prev <= cur)
{
if (prev == cur)
r = TRUE;
break;
}
pprev[1] = prev;
}
pprev[1] = cur;
}
return r;
}
| ArrayType* new_intArrayType | ( | int | num | ) |
Definition at line 226 of file _int_tool.c.
References ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, ARR_OVERHEAD_NONULLS, 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().
{
ArrayType *r;
int nbytes = ARR_OVERHEAD_NONULLS(1) + sizeof(int) * num;
r = (ArrayType *) palloc0(nbytes);
SET_VARSIZE(r, nbytes);
ARR_NDIM(r) = 1;
r->dataoffset = 0; /* marker for no null bitmap */
ARR_ELEMTYPE(r) = INT4OID;
ARR_DIMS(r)[0] = num;
ARR_LBOUND(r)[0] = 1;
return r;
}
Definition at line 408 of file _int_bool.c.
References contains_required_value(), GETQUERY, and QUERYTYPE::size.
Referenced by ginint4_queryextract().
{
if (query->size <= 0)
return false;
return contains_required_value(GETQUERY(query) + query->size - 1);
}
Definition at line 244 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().
{
int nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num;
int i;
if (num == ARRNELEMS(a))
return a;
a = (ArrayType *) repalloc(a, nbytes);
SET_VARSIZE(a, nbytes);
/* usually the array should be 1-D already, but just in case ... */
for (i = 0; i < ARR_NDIM(a); i++)
{
ARR_DIMS(a)[i] = num;
num = 1;
}
return a;
}
| 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().
{
*size = (float) ARRNELEMS(a);
}
Definition at line 309 of file _int_bool.c.
References checkcondition_bit(), execute(), GETQUERY, and QUERYTYPE::size.
Referenced by g_intbig_consistent().
{
return execute(GETQUERY(query) + query->size - 1,
(void *) sign, calcnot,
checkcondition_bit);
}
1.7.1