aboutsummaryrefslogtreecommitdiff
path: root/contrib/intarray
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/intarray')
-rw-r--r--contrib/intarray/_int.h16
-rw-r--r--contrib/intarray/_int_bool.c54
-rw-r--r--contrib/intarray/_int_gin.c156
-rw-r--r--contrib/intarray/_int_gist.c24
-rw-r--r--contrib/intarray/_int_tool.c23
-rw-r--r--contrib/intarray/_intbig_gist.c23
6 files changed, 162 insertions, 134 deletions
diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h
index f40dc06a92c..bf10f109220 100644
--- a/contrib/intarray/_int.h
+++ b/contrib/intarray/_int.h
@@ -154,17 +154,17 @@ typedef struct
#define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) )
#define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
-#define END 0
-#define ERR 1
-#define VAL 2
-#define OPR 3
-#define OPEN 4
-#define CLOSE 5
+#define END 0
+#define ERR 1
+#define VAL 2
+#define OPR 3
+#define OPEN 4
+#define CLOSE 5
bool signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot);
bool execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot);
-bool ginconsistent(QUERYTYPE * query, bool *check);
-int4 shorterquery(ITEM * q, int4 len);
+bool ginconsistent(QUERYTYPE * query, bool *check);
+int4 shorterquery(ITEM * q, int4 len);
int compASC(const void *a, const void *b);
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 230c412a048..8517010e5ed 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -232,7 +232,7 @@ typedef struct
* is there value 'val' in array or not ?
*/
static bool
-checkcondition_arr(void *checkval, ITEM *item)
+checkcondition_arr(void *checkval, ITEM * item)
{
int4 *StopLow = ((CHKVAL *) checkval)->arrb;
int4 *StopHigh = ((CHKVAL *) checkval)->arre;
@@ -254,7 +254,7 @@ checkcondition_arr(void *checkval, ITEM *item)
}
static bool
-checkcondition_bit(void *checkval, ITEM *item)
+checkcondition_bit(void *checkval, ITEM * item)
{
return GETBIT(checkval, HASHVAL(item->val));
}
@@ -263,7 +263,7 @@ checkcondition_bit(void *checkval, ITEM *item)
* check for boolean condition
*/
static bool
-execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *item))
+execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM * item))
{
if (curitem->type == VAL)
@@ -319,38 +319,42 @@ execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot)
);
}
-typedef struct {
- ITEM *first;
- bool *mapped_check;
-} GinChkVal;
+typedef struct
+{
+ ITEM *first;
+ bool *mapped_check;
+} GinChkVal;
static bool
-checkcondition_gin(void *checkval, ITEM *item) {
- GinChkVal *gcv = (GinChkVal*)checkval;
+checkcondition_gin(void *checkval, ITEM * item)
+{
+ GinChkVal *gcv = (GinChkVal *) checkval;
- return gcv->mapped_check[ item - gcv->first ];
+ return gcv->mapped_check[item - gcv->first];
}
bool
-ginconsistent(QUERYTYPE * query, bool *check) {
- GinChkVal gcv;
- ITEM *items = GETQUERY(query);
- int i, j=0;
+ginconsistent(QUERYTYPE * query, bool *check)
+{
+ GinChkVal gcv;
+ ITEM *items = GETQUERY(query);
+ int i,
+ j = 0;
- if ( query->size < 0 )
+ if (query->size < 0)
return FALSE;
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
- );
+ 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
+ );
}
/*
diff --git a/contrib/intarray/_int_gin.c b/contrib/intarray/_int_gin.c
index 2a2830e578d..7bb9599b335 100644
--- a/contrib/intarray/_int_gin.c
+++ b/contrib/intarray/_int_gin.c
@@ -1,102 +1,118 @@
#include "_int.h"
PG_FUNCTION_INFO_V1(ginint4_queryextract);
-Datum ginint4_queryextract(PG_FUNCTION_ARGS);
+Datum ginint4_queryextract(PG_FUNCTION_ARGS);
Datum
-ginint4_queryextract(PG_FUNCTION_ARGS) {
- uint32 *nentries = (uint32*)PG_GETARG_POINTER(1);
- StrategyNumber strategy = PG_GETARG_UINT16(2);
- Datum *res = NULL;
-
+ginint4_queryextract(PG_FUNCTION_ARGS)
+{
+ uint32 *nentries = (uint32 *) PG_GETARG_POINTER(1);
+ StrategyNumber strategy = PG_GETARG_UINT16(2);
+ Datum *res = NULL;
+
*nentries = 0;
- if ( strategy == BooleanSearchStrategy ) {
- QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
- ITEM *items = GETQUERY(query);
- int i;
+ if (strategy == BooleanSearchStrategy)
+ {
+ QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
+ ITEM *items = GETQUERY(query);
+ int i;
if (query->size == 0)
PG_RETURN_POINTER(NULL);
- if ( shorterquery(items, query->size) == 0 )
- elog(ERROR,"Query requires full scan, GIN doesn't support it");
+ if (shorterquery(items, query->size) == 0)
+ elog(ERROR, "Query requires full scan, GIN doesn't support it");
- pfree( query );
+ pfree(query);
- query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
+ query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
items = GETQUERY(query);
- res = (Datum*)palloc(sizeof(Datum) * query->size);
+ res = (Datum *) palloc(sizeof(Datum) * query->size);
*nentries = 0;
- for(i=0;i<query->size;i++)
- if ( items[i].type == VAL ) {
- res[*nentries] = Int32GetDatum( items[i].val );
+ for (i = 0; i < query->size; i++)
+ if (items[i].type == VAL)
+ {
+ res[*nentries] = Int32GetDatum(items[i].val);
(*nentries)++;
}
- } else {
- ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
- int4 *arr;
- uint32 i;
+ }
+ else
+ {
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
+ int4 *arr;
+ uint32 i;
CHECKARRVALID(query);
- *nentries=ARRNELEMS(query);
- if ( *nentries > 0 ) {
- res = (Datum*)palloc(sizeof(Datum) * (*nentries));
-
- arr=ARRPTR(query);
- for(i=0;i<*nentries;i++)
- res[i] = Int32GetDatum( arr[i] );
+ *nentries = ARRNELEMS(query);
+ if (*nentries > 0)
+ {
+ res = (Datum *) palloc(sizeof(Datum) * (*nentries));
+
+ arr = ARRPTR(query);
+ for (i = 0; i < *nentries; i++)
+ res[i] = Int32GetDatum(arr[i]);
}
}
- PG_RETURN_POINTER( res );
+ PG_RETURN_POINTER(res);
}
PG_FUNCTION_INFO_V1(ginint4_consistent);
-Datum ginint4_consistent(PG_FUNCTION_ARGS);
+Datum ginint4_consistent(PG_FUNCTION_ARGS);
Datum
-ginint4_consistent(PG_FUNCTION_ARGS) {
- bool *check = (bool*)PG_GETARG_POINTER(0);
- StrategyNumber strategy = PG_GETARG_UINT16(1);
- int res=FALSE;
-
- /* we can do not check array carefully, it's done by previous ginarrayextract call */
-
- switch( strategy ) {
- case RTOverlapStrategyNumber:
- case RTContainedByStrategyNumber:
- case RTOldContainedByStrategyNumber:
- /* at least one element in check[] is true, so result = true */
-
- res = TRUE;
- break;
- case RTSameStrategyNumber:
- case RTContainsStrategyNumber:
- case RTOldContainsStrategyNumber:
- res = TRUE;
- do {
- ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
- int i, nentries=ARRNELEMS(query);
-
- for(i=0;i<nentries;i++)
- if ( !check[i] ) {
- res = FALSE;
- break;
- }
- } while(0);
- break;
- case BooleanSearchStrategy:
- do {
- QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
- res = ginconsistent( query, check );
- } while(0);
+ginint4_consistent(PG_FUNCTION_ARGS)
+{
+ bool *check = (bool *) PG_GETARG_POINTER(0);
+ StrategyNumber strategy = PG_GETARG_UINT16(1);
+ int res = FALSE;
+
+ /*
+ * we can do not check array carefully, it's done by previous
+ * ginarrayextract call
+ */
+
+ switch (strategy)
+ {
+ case RTOverlapStrategyNumber:
+ case RTContainedByStrategyNumber:
+ case RTOldContainedByStrategyNumber:
+ /* at least one element in check[] is true, so result = true */
+
+ res = TRUE;
+ break;
+ case RTSameStrategyNumber:
+ case RTContainsStrategyNumber:
+ case RTOldContainsStrategyNumber:
+ res = TRUE;
+ do
+ {
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
+ int i,
+ nentries = ARRNELEMS(query);
+
+ for (i = 0; i < nentries; i++)
+ if (!check[i])
+ {
+ res = FALSE;
+ break;
+ }
+ } while (0);
break;
- default:
- elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
- }
+ case BooleanSearchStrategy:
+ do
+ {
+ QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
+
+ res = ginconsistent(query, check);
+ } while (0);
+ break;
+ default:
+ elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
+ }
- PG_RETURN_BOOL(res);
+ PG_RETURN_BOOL(res);
}
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 71c9ad0cec5..56eb0c08c2e 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -36,19 +36,21 @@ g_int_consistent(PG_FUNCTION_ARGS)
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval;
- if (strategy == BooleanSearchStrategy) {
+ if (strategy == BooleanSearchStrategy)
+ {
retval = execconsistent((QUERYTYPE *) query,
- (ArrayType *) DatumGetPointer(entry->key),
- GIST_LEAF(entry));
+ (ArrayType *) DatumGetPointer(entry->key),
+ GIST_LEAF(entry));
- pfree( query );
+ pfree(query);
PG_RETURN_BOOL(retval);
}
/* sort query for fast search, key is already sorted */
CHECKARRVALID(query);
- if (ARRISVOID(query)) {
- pfree( query );
+ if (ARRISVOID(query))
+ {
+ pfree(query);
PG_RETURN_BOOL(false);
}
PREPAREARR(query);
@@ -88,7 +90,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
default:
retval = FALSE;
}
- pfree( query );
+ pfree(query);
PG_RETURN_BOOL(retval);
}
@@ -156,7 +158,7 @@ g_int_compress(PG_FUNCTION_ARGS)
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, FALSE);
PG_RETURN_POINTER(retval);
}
@@ -203,7 +205,7 @@ g_int_compress(PG_FUNCTION_ARGS)
r = resize_intArrayType(r, len);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, FALSE);
PG_RETURN_POINTER(retval);
}
else
@@ -240,7 +242,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
{
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(in),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, FALSE);
PG_RETURN_POINTER(retval);
}
@@ -331,7 +333,7 @@ typedef struct
{
OffsetNumber pos;
float cost;
-} SPLITCOST;
+} SPLITCOST;
static int
comparecost(const void *a, const void *b)
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 82ce4b7ac56..2ad0ef0cc04 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -89,22 +89,27 @@ inner_int_union(ArrayType *a, ArrayType *b)
if (!r)
{
- int na = ARRNELEMS(a),
- nb = ARRNELEMS(b);
- int *da = ARRPTR(a),
- *db = ARRPTR(b);
- int i,j, *dr;
+ 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]) {
+ while (i < na && j < nb)
+ {
+ if (da[i] == db[j])
+ {
*dr++ = da[i++];
j++;
- } else if (da[i] < db[j])
+ }
+ else if (da[i] < db[j])
*dr++ = da[i++];
else
*dr++ = db[j++];
@@ -115,7 +120,7 @@ inner_int_union(ArrayType *a, ArrayType *b)
while (j < nb)
*dr++ = db[j++];
- r = resize_intArrayType(r, dr-ARRPTR(r));
+ r = resize_intArrayType(r, dr - ARRPTR(r));
}
if (ARRNELEMS(r) > 1)
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index b25814c7ce7..cb80d8f6f24 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -214,7 +214,7 @@ sizebitvec(BITVECP sign)
i;
LOOPBYTE(
- size += number_of_ones[(unsigned char) sign[i]];
+ size += number_of_ones[(unsigned char) sign[i]];
);
return size;
}
@@ -227,8 +227,8 @@ hemdistsign(BITVECP a, BITVECP b)
dist = 0;
LOOPBYTE(
- diff = (unsigned char) (a[i] ^ b[i]);
- dist += number_of_ones[diff];
+ diff = (unsigned char) (a[i] ^ b[i]);
+ dist += number_of_ones[diff];
);
return dist;
}
@@ -318,7 +318,7 @@ typedef struct
{
OffsetNumber pos;
int4 cost;
-} SPLITCOST;
+} SPLITCOST;
static int
comparecost(const void *a, const void *b)
@@ -506,16 +506,17 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
if (strategy == BooleanSearchStrategy)
{
- retval =signconsistent((QUERYTYPE *) query,
- GETSIGN(DatumGetPointer(entry->key)),
- false);
- PG_FREE_IF_COPY( query, 1 );
+ retval = signconsistent((QUERYTYPE *) query,
+ GETSIGN(DatumGetPointer(entry->key)),
+ false);
+ PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(retval);
}
CHECKARRVALID(query);
- if (ARRISVOID(query)) {
- PG_FREE_IF_COPY( query, 1 );
+ if (ARRISVOID(query))
+ {
+ PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(FALSE);
}
@@ -602,6 +603,6 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
default:
retval = FALSE;
}
- PG_FREE_IF_COPY( query, 1 );
+ PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(retval);
}