aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist')
-rw-r--r--contrib/btree_gist/btree_bit.c192
-rw-r--r--contrib/btree_gist/btree_bytea.c144
-rw-r--r--contrib/btree_gist/btree_cash.c161
-rw-r--r--contrib/btree_gist/btree_date.c219
-rw-r--r--contrib/btree_gist/btree_float4.c162
-rw-r--r--contrib/btree_gist/btree_float8.c161
-rw-r--r--contrib/btree_gist/btree_gist.c25
-rw-r--r--contrib/btree_gist/btree_gist.h42
-rw-r--r--contrib/btree_gist/btree_inet.c229
-rw-r--r--contrib/btree_gist/btree_int2.c159
-rw-r--r--contrib/btree_gist/btree_int4.c159
-rw-r--r--contrib/btree_gist/btree_int8.c158
-rw-r--r--contrib/btree_gist/btree_interval.c269
-rw-r--r--contrib/btree_gist/btree_macaddr.c191
-rw-r--r--contrib/btree_gist/btree_numeric.c259
-rw-r--r--contrib/btree_gist/btree_oid.c161
-rw-r--r--contrib/btree_gist/btree_text.c320
-rw-r--r--contrib/btree_gist/btree_time.c303
-rw-r--r--contrib/btree_gist/btree_ts.c325
-rw-r--r--contrib/btree_gist/btree_utils_num.c382
-rw-r--r--contrib/btree_gist/btree_utils_num.h67
-rw-r--r--contrib/btree_gist/btree_utils_var.c978
-rw-r--r--contrib/btree_gist/btree_utils_var.h69
23 files changed, 2657 insertions, 2478 deletions
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index 138418a30e0..0b220ae2bb7 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -14,92 +14,99 @@ PG_FUNCTION_INFO_V1(gbt_bit_consistent);
PG_FUNCTION_INFO_V1(gbt_bit_penalty);
PG_FUNCTION_INFO_V1(gbt_bit_same);
-Datum gbt_bit_compress(PG_FUNCTION_ARGS);
-Datum gbt_bit_union(PG_FUNCTION_ARGS);
-Datum gbt_bit_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_bit_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bit_penalty(PG_FUNCTION_ARGS);
-Datum gbt_bit_same(PG_FUNCTION_ARGS);
+Datum gbt_bit_compress(PG_FUNCTION_ARGS);
+Datum gbt_bit_union(PG_FUNCTION_ARGS);
+Datum gbt_bit_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_bit_consistent(PG_FUNCTION_ARGS);
+Datum gbt_bit_penalty(PG_FUNCTION_ARGS);
+Datum gbt_bit_same(PG_FUNCTION_ARGS);
/* define for comparison */
-static bool gbt_bitgt (const void *a, const void *b)
+static bool
+gbt_bitgt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( bitgt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(bitgt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_bitge (const void *a, const void *b)
+static bool
+gbt_bitge(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( bitge ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(bitge, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_biteq (const void *a, const void *b)
+static bool
+gbt_biteq(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( biteq ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(biteq, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_bitle (const void *a, const void *b)
+static bool
+gbt_bitle(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( bitle ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(bitle, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_bitlt (const void *a, const void *b)
+static bool
+gbt_bitlt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( bitlt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(bitlt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static int32 gbt_bitcmp ( const bytea * a , const bytea * b )
+static int32
+gbt_bitcmp(const bytea *a, const bytea *b)
{
- return
- ( DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b) ) ) );
+ return
+ (DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
}
-
+
static bytea *
-gbt_bit_xfrm ( bytea * leaf )
+gbt_bit_xfrm(bytea *leaf)
{
- bytea * out = leaf;
- int s = VARBITBYTES(leaf) + VARHDRSZ;
+ bytea *out = leaf;
+ int s = VARBITBYTES(leaf) + VARHDRSZ;
- out = palloc ( s );
- VARATT_SIZEP(out) = s;
- memcpy ( (void*)VARDATA(out), (void*)VARBITS(leaf), VARBITBYTES(leaf) );
- return out;
+ out = palloc(s);
+ VARATT_SIZEP(out) = s;
+ memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
+ return out;
}
-static GBT_VARKEY * gbt_bit_l2n ( GBT_VARKEY * leaf )
+static GBT_VARKEY *
+gbt_bit_l2n(GBT_VARKEY * leaf)
{
- GBT_VARKEY *out = leaf ;
- GBT_VARKEY_R r = gbt_var_key_readable ( leaf );
- bytea *o ;
+ GBT_VARKEY *out = leaf;
+ GBT_VARKEY_R r = gbt_var_key_readable(leaf);
+ bytea *o;
- o = gbt_bit_xfrm (r.lower);
- r.upper = r.lower = o;
- out = gbt_var_key_copy( &r, TRUE );
- pfree(o);
+ o = gbt_bit_xfrm(r.lower);
+ r.upper = r.lower = o;
+ out = gbt_var_key_copy(&r, TRUE);
+ pfree(o);
- return out;
+ return out;
}
static const gbtree_vinfo tinfo =
{
- gbt_t_bit,
- FALSE,
- TRUE,
- gbt_bitgt,
- gbt_bitge,
- gbt_biteq,
- gbt_bitle,
- gbt_bitlt,
- gbt_bitcmp,
- gbt_bit_l2n
+ gbt_t_bit,
+ FALSE,
+ TRUE,
+ gbt_bitgt,
+ gbt_bitge,
+ gbt_biteq,
+ gbt_bitle,
+ gbt_bitlt,
+ gbt_bitcmp,
+ gbt_bit_l2n
};
@@ -108,40 +115,40 @@ static const gbtree_vinfo tinfo =
**************************************************/
Datum
-gbt_bit_compress (PG_FUNCTION_ARGS)
+gbt_bit_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+
+ PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
}
Datum
gbt_bit_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
- void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) );
- void *query = ( void * ) DatumGetByteaP ( PG_GETARG_DATUM(1) );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool retval = FALSE;
- GBT_VARKEY_R r = gbt_var_key_readable ( key );
-
- if ( GIST_LEAF(entry) )
- {
- retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo );
- } else {
- bytea * q = gbt_bit_xfrm ( ( bytea * ) query );
- retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
- pfree(q);
- }
-
- if ( ktst != key ){
- pfree ( key );
- }
- if ( qtst != query ){
- pfree ( query );
- }
- PG_RETURN_BOOL(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
+ void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool retval = FALSE;
+ GBT_VARKEY_R r = gbt_var_key_readable(key);
+
+ if (GIST_LEAF(entry))
+ retval = gbt_var_consistent(&r, query, &strategy, TRUE, &tinfo);
+ else
+ {
+ bytea *q = gbt_bit_xfrm((bytea *) query);
+
+ retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
+ pfree(q);
+ }
+
+ if (ktst != key)
+ pfree(key);
+ if (qtst != query)
+ pfree(query);
+ PG_RETURN_BOOL(retval);
}
@@ -149,37 +156,40 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
Datum
gbt_bit_union(PG_FUNCTION_ARGS)
{
- GistEntryVector * entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- int32 * size = (int *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ int32 *size = (int *) PG_GETARG_POINTER(1);
+
+ PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
}
-
+
Datum
gbt_bit_picksplit(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
- gbt_var_picksplit ( entryvec, v, &tinfo );
- PG_RETURN_POINTER(v);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
+
+ gbt_var_picksplit(entryvec, v, &tinfo);
+ PG_RETURN_POINTER(v);
}
Datum
gbt_bit_same(PG_FUNCTION_ARGS)
{
- Datum d1 = PG_GETARG_DATUM(0);
- Datum d2 = PG_GETARG_DATUM(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
- PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
+ Datum d1 = PG_GETARG_DATUM(0);
+ Datum d2 = PG_GETARG_DATUM(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
+
+ PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
}
Datum
gbt_bit_penalty(PG_FUNCTION_ARGS)
{
- float *result = (float *) PG_GETARG_POINTER(2);
- GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
-}
+ float *result = (float *) PG_GETARG_POINTER(2);
+ GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
+ PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
+}
diff --git a/contrib/btree_gist/btree_bytea.c b/contrib/btree_gist/btree_bytea.c
index da8a7f405b5..3671acd24c8 100644
--- a/contrib/btree_gist/btree_bytea.c
+++ b/contrib/btree_gist/btree_bytea.c
@@ -13,61 +13,67 @@ PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
PG_FUNCTION_INFO_V1(gbt_bytea_same);
-Datum gbt_bytea_compress(PG_FUNCTION_ARGS);
-Datum gbt_bytea_union(PG_FUNCTION_ARGS);
-Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_bytea_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bytea_penalty(PG_FUNCTION_ARGS);
-Datum gbt_bytea_same(PG_FUNCTION_ARGS);
+Datum gbt_bytea_compress(PG_FUNCTION_ARGS);
+Datum gbt_bytea_union(PG_FUNCTION_ARGS);
+Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_bytea_consistent(PG_FUNCTION_ARGS);
+Datum gbt_bytea_penalty(PG_FUNCTION_ARGS);
+Datum gbt_bytea_same(PG_FUNCTION_ARGS);
/* define for comparison */
-static bool gbt_byteagt (const void *a, const void *b)
+static bool
+gbt_byteagt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( byteagt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(byteagt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_byteage (const void *a, const void *b)
+static bool
+gbt_byteage(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( byteage ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(byteage, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_byteaeq (const void *a, const void *b)
+static bool
+gbt_byteaeq(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( byteaeq ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(byteaeq, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_byteale (const void *a, const void *b)
+static bool
+gbt_byteale(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( byteale ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(byteale, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_bytealt (const void *a, const void *b)
+static bool
+gbt_bytealt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( bytealt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(bytealt, PointerGetDatum(a), PointerGetDatum(b))));
}
-
-static int32 gbt_byteacmp ( const bytea * a , const bytea * b )
+
+static int32
+gbt_byteacmp(const bytea *a, const bytea *b)
{
- return
- ( DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b) ) ) );
+ return
+ (DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
}
static const gbtree_vinfo tinfo =
{
- gbt_t_bytea,
- FALSE,
- TRUE,
- gbt_byteagt,
- gbt_byteage,
- gbt_byteaeq,
- gbt_byteale,
- gbt_bytealt,
- gbt_byteacmp,
- NULL
+ gbt_t_bytea,
+ FALSE,
+ TRUE,
+ gbt_byteagt,
+ gbt_byteage,
+ gbt_byteaeq,
+ gbt_byteale,
+ gbt_bytealt,
+ gbt_byteacmp,
+ NULL
};
@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo =
Datum
-gbt_bytea_compress (PG_FUNCTION_ARGS)
+gbt_bytea_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+
+ PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
}
@@ -88,24 +95,22 @@ gbt_bytea_compress (PG_FUNCTION_ARGS)
Datum
gbt_bytea_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
- void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) );
- void *query = ( void * ) DatumGetByteaP ( PG_GETARG_DATUM(1) );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool retval = FALSE;
- GBT_VARKEY_R r = gbt_var_key_readable ( key );
-
- retval = gbt_var_consistent( &r, query, &strategy, GIST_LEAF(entry), &tinfo );
-
- if ( ktst != key ){
- pfree ( key );
- }
- if ( qtst != query ){
- pfree ( query );
- }
- PG_RETURN_BOOL(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
+ void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool retval = FALSE;
+ GBT_VARKEY_R r = gbt_var_key_readable(key);
+
+ retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
+
+ if (ktst != key)
+ pfree(key);
+ if (qtst != query)
+ pfree(query);
+ PG_RETURN_BOOL(retval);
}
@@ -113,37 +118,40 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
Datum
gbt_bytea_union(PG_FUNCTION_ARGS)
{
- GistEntryVector * entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- int32 * size = (int *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ int32 *size = (int *) PG_GETARG_POINTER(1);
+
+ PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
}
-
+
Datum
gbt_bytea_picksplit(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
- gbt_var_picksplit ( entryvec, v, &tinfo );
- PG_RETURN_POINTER(v);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
+
+ gbt_var_picksplit(entryvec, v, &tinfo);
+ PG_RETURN_POINTER(v);
}
Datum
gbt_bytea_same(PG_FUNCTION_ARGS)
{
- Datum d1 = PG_GETARG_DATUM(0);
- Datum d2 = PG_GETARG_DATUM(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
- PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
+ Datum d1 = PG_GETARG_DATUM(0);
+ Datum d2 = PG_GETARG_DATUM(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
+
+ PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
}
Datum
gbt_bytea_penalty(PG_FUNCTION_ARGS)
{
- float *result = (float *) PG_GETARG_POINTER(2);
- GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
-}
+ float *result = (float *) PG_GETARG_POINTER(2);
+ GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
+ PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
+}
diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c
index 6c5acb3e7e1..84e46101181 100644
--- a/contrib/btree_gist/btree_cash.c
+++ b/contrib/btree_gist/btree_cash.c
@@ -4,9 +4,9 @@
typedef struct
{
- Cash lower;
- Cash upper;
-} cashKEY;
+ Cash lower;
+ Cash upper;
+} cashKEY;
/*
** Cash ops
@@ -18,59 +18,62 @@ PG_FUNCTION_INFO_V1(gbt_cash_consistent);
PG_FUNCTION_INFO_V1(gbt_cash_penalty);
PG_FUNCTION_INFO_V1(gbt_cash_same);
-Datum gbt_cash_compress(PG_FUNCTION_ARGS);
-Datum gbt_cash_union(PG_FUNCTION_ARGS);
-Datum gbt_cash_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_cash_consistent(PG_FUNCTION_ARGS);
-Datum gbt_cash_penalty(PG_FUNCTION_ARGS);
-Datum gbt_cash_same(PG_FUNCTION_ARGS);
+Datum gbt_cash_compress(PG_FUNCTION_ARGS);
+Datum gbt_cash_union(PG_FUNCTION_ARGS);
+Datum gbt_cash_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_cash_consistent(PG_FUNCTION_ARGS);
+Datum gbt_cash_penalty(PG_FUNCTION_ARGS);
+Datum gbt_cash_same(PG_FUNCTION_ARGS);
-static bool gbt_cashgt (const void *a, const void *b)
+static bool
+gbt_cashgt(const void *a, const void *b)
{
- return ( *((Cash*)a) > *((Cash*)b) );
+ return (*((Cash *) a) > *((Cash *) b));
}
-static bool gbt_cashge (const void *a, const void *b)
+static bool
+gbt_cashge(const void *a, const void *b)
{
- return ( *((Cash*)a) >= *((Cash*)b) );
+ return (*((Cash *) a) >= *((Cash *) b));
}
-static bool gbt_casheq (const void *a, const void *b)
+static bool
+gbt_casheq(const void *a, const void *b)
{
- return ( *((Cash*)a) == *((Cash*)b) );
+ return (*((Cash *) a) == *((Cash *) b));
}
-static bool gbt_cashle (const void *a, const void *b)
+static bool
+gbt_cashle(const void *a, const void *b)
{
- return ( *((Cash*)a) <= *((Cash*)b) );
+ return (*((Cash *) a) <= *((Cash *) b));
}
-static bool gbt_cashlt (const void *a, const void *b)
+static bool
+gbt_cashlt(const void *a, const void *b)
{
- return ( *((Cash*)a) < *((Cash*)b) );
+ return (*((Cash *) a) < *((Cash *) b));
}
static int
gbt_cashkey_cmp(const void *a, const void *b)
{
- if ( *(Cash*)&(((Nsrt *) a)->t[0]) > *(Cash*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(Cash*)&(((Nsrt *) a)->t[0]) < *(Cash*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_cash,
- sizeof(Cash),
- gbt_cashgt,
- gbt_cashge,
- gbt_casheq,
- gbt_cashle,
- gbt_cashlt,
- gbt_cashkey_cmp
+ gbt_t_cash,
+ sizeof(Cash),
+ gbt_cashgt,
+ gbt_cashge,
+ gbt_casheq,
+ gbt_cashle,
+ gbt_cashlt,
+ gbt_cashkey_cmp
};
@@ -82,81 +85,83 @@ static const gbtree_ninfo tinfo =
Datum
gbt_cash_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_cash_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- Cash query = (*((Cash *) PG_GETARG_POINTER(1)));
- cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ Cash query = (*((Cash *) PG_GETARG_POINTER(1)));
+ cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_cash_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(cashKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(cashKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_cash_penalty(PG_FUNCTION_ARGS)
{
- cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+
+ Cash res;
- Cash res ;
+ *result = 0.0;
- *result = 0.0;
-
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_cash_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_cash_same(PG_FUNCTION_ARGS)
{
- cashKEY *b1 = (cashKEY *) PG_GETARG_POINTER(0);
- cashKEY *b2 = (cashKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ cashKEY *b1 = (cashKEY *) PG_GETARG_POINTER(0);
+ cashKEY *b2 = (cashKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
-
diff --git a/contrib/btree_gist/btree_date.c b/contrib/btree_gist/btree_date.c
index 9522d386252..d3ce33c7172 100644
--- a/contrib/btree_gist/btree_date.c
+++ b/contrib/btree_gist/btree_date.c
@@ -4,9 +4,9 @@
typedef struct
{
- DateADT lower;
- DateADT upper;
-} dateKEY;
+ DateADT lower;
+ DateADT upper;
+} dateKEY;
/*
** date ops
@@ -18,46 +18,51 @@ PG_FUNCTION_INFO_V1(gbt_date_consistent);
PG_FUNCTION_INFO_V1(gbt_date_penalty);
PG_FUNCTION_INFO_V1(gbt_date_same);
-Datum gbt_date_compress(PG_FUNCTION_ARGS);
-Datum gbt_date_union(PG_FUNCTION_ARGS);
-Datum gbt_date_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_date_consistent(PG_FUNCTION_ARGS);
-Datum gbt_date_penalty(PG_FUNCTION_ARGS);
-Datum gbt_date_same(PG_FUNCTION_ARGS);
+Datum gbt_date_compress(PG_FUNCTION_ARGS);
+Datum gbt_date_union(PG_FUNCTION_ARGS);
+Datum gbt_date_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_date_consistent(PG_FUNCTION_ARGS);
+Datum gbt_date_penalty(PG_FUNCTION_ARGS);
+Datum gbt_date_same(PG_FUNCTION_ARGS);
-static bool gbt_dategt (const void *a, const void *b)
+static bool
+gbt_dategt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(date_gt,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(date_gt, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
+ );
}
-static bool gbt_datege (const void *a, const void *b)
+static bool
+gbt_datege(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(date_ge,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(date_ge, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
+ );
}
-static bool gbt_dateeq (const void *a, const void *b)
+static bool
+gbt_dateeq(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(date_eq,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(date_eq, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
+ );
}
-static bool gbt_datele (const void *a, const void *b)
+static bool
+gbt_datele(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(date_le,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(date_le, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
+ );
}
-static bool gbt_datelt (const void *a, const void *b)
+static bool
+gbt_datelt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(date_lt,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(date_lt, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
+ );
}
@@ -65,26 +70,24 @@ static bool gbt_datelt (const void *a, const void *b)
static int
gbt_datekey_cmp(const void *a, const void *b)
{
- if ( gbt_dategt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return 1;
- } else
- if ( gbt_datelt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return -1;
- }
- return 0;
+ if (gbt_dategt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return 1;
+ else if (gbt_datelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_date,
- sizeof(DateADT),
- gbt_dategt,
- gbt_datege,
- gbt_dateeq,
- gbt_datele,
- gbt_datelt,
- gbt_datekey_cmp
+ gbt_t_date,
+ sizeof(DateADT),
+ gbt_dategt,
+ gbt_datege,
+ gbt_dateeq,
+ gbt_datele,
+ gbt_datelt,
+ gbt_datekey_cmp
};
@@ -97,9 +100,10 @@ static const gbtree_ninfo tinfo =
Datum
gbt_date_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
@@ -107,86 +111,89 @@ gbt_date_compress(PG_FUNCTION_ARGS)
Datum
gbt_date_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- DateADT query = PG_GETARG_DATEADT( 1 );
- dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
-
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ DateADT query = PG_GETARG_DATEADT(1);
+ dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_date_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(dateKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(dateKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_date_penalty(PG_FUNCTION_ARGS)
{
- dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- dateKEY *newentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- int32 diff, res ;
-
- diff = DatumGetInt32(DirectFunctionCall2(
- date_mi,
- DateADTGetDatum(newentry->upper),
- DateADTGetDatum(origentry->upper)));
-
- res = Max(diff, 0);
-
- diff = DatumGetInt32(DirectFunctionCall2(
- date_mi,
- DateADTGetDatum(origentry->lower),
- DateADTGetDatum(newentry->lower)));
-
- res += Max(diff, 0);
-
- *result = 0.0;
-
- if ( res > 0 ){
- diff = DatumGetInt32(DirectFunctionCall2(
- date_mi,
- DateADTGetDatum(origentry->upper),
- DateADTGetDatum(origentry->lower)));
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + diff ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
-
- PG_RETURN_POINTER(result);
+ dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ dateKEY *newentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ int32 diff,
+ res;
+
+ diff = DatumGetInt32(DirectFunctionCall2(
+ date_mi,
+ DateADTGetDatum(newentry->upper),
+ DateADTGetDatum(origentry->upper)));
+
+ res = Max(diff, 0);
+
+ diff = DatumGetInt32(DirectFunctionCall2(
+ date_mi,
+ DateADTGetDatum(origentry->lower),
+ DateADTGetDatum(newentry->lower)));
+
+ res += Max(diff, 0);
+
+ *result = 0.0;
+
+ if (res > 0)
+ {
+ diff = DatumGetInt32(DirectFunctionCall2(
+ date_mi,
+ DateADTGetDatum(origentry->upper),
+ DateADTGetDatum(origentry->lower)));
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + diff)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
+
+ PG_RETURN_POINTER(result);
}
Datum
gbt_date_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_date_same(PG_FUNCTION_ARGS)
{
- dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
- dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
+ dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_float4.c b/contrib/btree_gist/btree_float4.c
index 621532d9a99..b36178e4541 100644
--- a/contrib/btree_gist/btree_float4.c
+++ b/contrib/btree_gist/btree_float4.c
@@ -3,9 +3,9 @@
typedef struct float4key
{
- float4 lower;
- float4 upper;
-} float4KEY;
+ float4 lower;
+ float4 upper;
+} float4KEY;
/*
** float4 ops
@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_float4_consistent);
PG_FUNCTION_INFO_V1(gbt_float4_penalty);
PG_FUNCTION_INFO_V1(gbt_float4_same);
-Datum gbt_float4_compress(PG_FUNCTION_ARGS);
-Datum gbt_float4_union(PG_FUNCTION_ARGS);
-Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
-Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
-Datum gbt_float4_same(PG_FUNCTION_ARGS);
+Datum gbt_float4_compress(PG_FUNCTION_ARGS);
+Datum gbt_float4_union(PG_FUNCTION_ARGS);
+Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
+Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
+Datum gbt_float4_same(PG_FUNCTION_ARGS);
-static bool gbt_float4gt (const void *a, const void *b)
+static bool
+gbt_float4gt(const void *a, const void *b)
{
- return ( *((float4*)a) > *((float4*)b) );
+ return (*((float4 *) a) > *((float4 *) b));
}
-static bool gbt_float4ge (const void *a, const void *b)
+static bool
+gbt_float4ge(const void *a, const void *b)
{
- return ( *((float4*)a) >= *((float4*)b) );
+ return (*((float4 *) a) >= *((float4 *) b));
}
-static bool gbt_float4eq (const void *a, const void *b)
+static bool
+gbt_float4eq(const void *a, const void *b)
{
- return ( *((float4*)a) == *((float4*)b) );
+ return (*((float4 *) a) == *((float4 *) b));
}
-static bool gbt_float4le (const void *a, const void *b)
+static bool
+gbt_float4le(const void *a, const void *b)
{
- return ( *((float4*)a) <= *((float4*)b) );
+ return (*((float4 *) a) <= *((float4 *) b));
}
-static bool gbt_float4lt (const void *a, const void *b)
+static bool
+gbt_float4lt(const void *a, const void *b)
{
- return ( *((float4*)a) < *((float4*)b) );
+ return (*((float4 *) a) < *((float4 *) b));
}
static int
gbt_float4key_cmp(const void *a, const void *b)
{
- if ( *(float4*)&(((Nsrt *) a)->t[0]) > *(float4*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(float4*)&(((Nsrt *) a)->t[0]) < *(float4*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_float4,
- sizeof(float4),
- gbt_float4gt,
- gbt_float4ge,
- gbt_float4eq,
- gbt_float4le,
- gbt_float4lt,
- gbt_float4key_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_float4,
+ sizeof(float4),
+ gbt_float4gt,
+ gbt_float4ge,
+ gbt_float4eq,
+ gbt_float4le,
+ gbt_float4lt,
+ gbt_float4key_cmp
};
@@ -81,80 +84,83 @@ static const gbtree_ninfo tinfo =
Datum
gbt_float4_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_float4_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- float4 query = PG_GETARG_FLOAT4(1);
- float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ float4 query = PG_GETARG_FLOAT4(1);
+ float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_float4_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(float4KEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(float4KEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_float4_penalty(PG_FUNCTION_ARGS)
{
- float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
- float4 res ;
+ float4 res;
- *result = 0.0;
-
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ *result = 0.0;
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- PG_RETURN_POINTER(result);
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
+
+ PG_RETURN_POINTER(result);
}
Datum
gbt_float4_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_float4_same(PG_FUNCTION_ARGS)
{
- float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
- float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
+ float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c
index e19632fd78c..a5511d5abfe 100644
--- a/contrib/btree_gist/btree_float8.c
+++ b/contrib/btree_gist/btree_float8.c
@@ -3,9 +3,9 @@
typedef struct float8key
{
- float8 lower;
- float8 upper;
-} float8KEY;
+ float8 lower;
+ float8 upper;
+} float8KEY;
/*
** float8 ops
@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_float8_consistent);
PG_FUNCTION_INFO_V1(gbt_float8_penalty);
PG_FUNCTION_INFO_V1(gbt_float8_same);
-Datum gbt_float8_compress(PG_FUNCTION_ARGS);
-Datum gbt_float8_union(PG_FUNCTION_ARGS);
-Datum gbt_float8_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_float8_consistent(PG_FUNCTION_ARGS);
-Datum gbt_float8_penalty(PG_FUNCTION_ARGS);
-Datum gbt_float8_same(PG_FUNCTION_ARGS);
+Datum gbt_float8_compress(PG_FUNCTION_ARGS);
+Datum gbt_float8_union(PG_FUNCTION_ARGS);
+Datum gbt_float8_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_float8_consistent(PG_FUNCTION_ARGS);
+Datum gbt_float8_penalty(PG_FUNCTION_ARGS);
+Datum gbt_float8_same(PG_FUNCTION_ARGS);
-static bool gbt_float8gt (const void *a, const void *b)
+static bool
+gbt_float8gt(const void *a, const void *b)
{
- return ( *((float8*)a) > *((float8*)b) );
+ return (*((float8 *) a) > *((float8 *) b));
}
-static bool gbt_float8ge (const void *a, const void *b)
+static bool
+gbt_float8ge(const void *a, const void *b)
{
- return ( *((float8*)a) >= *((float8*)b) );
+ return (*((float8 *) a) >= *((float8 *) b));
}
-static bool gbt_float8eq (const void *a, const void *b)
+static bool
+gbt_float8eq(const void *a, const void *b)
{
- return ( *((float8*)a) == *((float8*)b) );
+ return (*((float8 *) a) == *((float8 *) b));
}
-static bool gbt_float8le (const void *a, const void *b)
+static bool
+gbt_float8le(const void *a, const void *b)
{
- return ( *((float8*)a) <= *((float8*)b) );
+ return (*((float8 *) a) <= *((float8 *) b));
}
-static bool gbt_float8lt (const void *a, const void *b)
+static bool
+gbt_float8lt(const void *a, const void *b)
{
- return ( *((float8*)a) < *((float8*)b) );
+ return (*((float8 *) a) < *((float8 *) b));
}
static int
gbt_float8key_cmp(const void *a, const void *b)
{
- if ( *(float8*)&(((Nsrt *) a)->t[0]) > *(float8*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(float8*)&(((Nsrt *) a)->t[0]) < *(float8*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(float8 *) &(((Nsrt *) a)->t[0]) > *(float8 *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(float8 *) &(((Nsrt *) a)->t[0]) < *(float8 *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_float8,
- sizeof(float8),
- gbt_float8gt,
- gbt_float8ge,
- gbt_float8eq,
- gbt_float8le,
- gbt_float8lt,
- gbt_float8key_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_float8,
+ sizeof(float8),
+ gbt_float8gt,
+ gbt_float8ge,
+ gbt_float8eq,
+ gbt_float8le,
+ gbt_float8lt,
+ gbt_float8key_cmp
};
@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum
gbt_float8_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
@@ -92,70 +96,73 @@ Datum
gbt_float8_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- float8 query = PG_GETARG_FLOAT8(1);
- float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ float8 query = PG_GETARG_FLOAT8(1);
+ float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_float8_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(float8KEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(float8KEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_float8_penalty(PG_FUNCTION_ARGS)
{
- float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+
+ float8 res;
- float8 res ;
+ *result = 0.0;
- *result = 0.0;
-
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_float8_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_float8_same(PG_FUNCTION_ARGS)
{
- float8KEY *b1 = (float8KEY *) PG_GETARG_POINTER(0);
- float8KEY *b2 = (float8KEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ float8KEY *b1 = (float8KEY *) PG_GETARG_POINTER(0);
+ float8KEY *b2 = (float8KEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_gist.c b/contrib/btree_gist/btree_gist.c
index 5e5a6988bb9..a64a6cb7c12 100644
--- a/contrib/btree_gist/btree_gist.c
+++ b/contrib/btree_gist/btree_gist.c
@@ -1,24 +1,24 @@
#include "btree_gist.h"
PG_FUNCTION_INFO_V1(gbt_decompress);
-PG_FUNCTION_INFO_V1(gbtreekey_in);
+PG_FUNCTION_INFO_V1(gbtreekey_in);
PG_FUNCTION_INFO_V1(gbtreekey_out);
-Datum gbt_decompress(PG_FUNCTION_ARGS);
+Datum gbt_decompress(PG_FUNCTION_ARGS);
/**************************************************
* In/Out for keys
**************************************************/
-
+
Datum
gbtreekey_in(PG_FUNCTION_ARGS)
{
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("<datatype>key_in() not implemented")));
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("<datatype>key_in() not implemented")));
- PG_RETURN_POINTER(NULL);
+ PG_RETURN_POINTER(NULL);
}
#include "btree_utils_var.h"
@@ -26,10 +26,10 @@ gbtreekey_in(PG_FUNCTION_ARGS)
Datum
gbtreekey_out(PG_FUNCTION_ARGS)
{
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("<datatype>key_out() not implemented")));
- PG_RETURN_POINTER(NULL);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("<datatype>key_out() not implemented")));
+ PG_RETURN_POINTER(NULL);
}
@@ -40,6 +40,5 @@ gbtreekey_out(PG_FUNCTION_ARGS)
Datum
gbt_decompress(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(PG_GETARG_POINTER(0));
+ PG_RETURN_POINTER(PG_GETARG_POINTER(0));
}
-
diff --git a/contrib/btree_gist/btree_gist.h b/contrib/btree_gist/btree_gist.h
index 1b4fe837d26..f7db9206e7c 100644
--- a/contrib/btree_gist/btree_gist.h
+++ b/contrib/btree_gist/btree_gist.h
@@ -7,25 +7,25 @@
enum gbtree_type
{
- gbt_t_var ,
- gbt_t_int2 ,
- gbt_t_int4 ,
- gbt_t_int8 ,
- gbt_t_float4 ,
- gbt_t_float8 ,
- gbt_t_numeric,
- gbt_t_ts,
- gbt_t_cash,
- gbt_t_oid,
- gbt_t_time,
- gbt_t_date,
- gbt_t_intv,
- gbt_t_macad,
- gbt_t_text,
- gbt_t_bpchar,
- gbt_t_bytea,
- gbt_t_bit,
- gbt_t_inet
+ gbt_t_var,
+ gbt_t_int2,
+ gbt_t_int4,
+ gbt_t_int8,
+ gbt_t_float4,
+ gbt_t_float8,
+ gbt_t_numeric,
+ gbt_t_ts,
+ gbt_t_cash,
+ gbt_t_oid,
+ gbt_t_time,
+ gbt_t_date,
+ gbt_t_intv,
+ gbt_t_macad,
+ gbt_t_text,
+ gbt_t_bpchar,
+ gbt_t_bytea,
+ gbt_t_bit,
+ gbt_t_inet
};
@@ -34,6 +34,6 @@ enum gbtree_type
* Generic btree functions
*/
-Datum gbtreekey_in (PG_FUNCTION_ARGS);
+Datum gbtreekey_in(PG_FUNCTION_ARGS);
-Datum gbtreekey_out(PG_FUNCTION_ARGS);
+Datum gbtreekey_out(PG_FUNCTION_ARGS);
diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c
index 5b3f66789de..fad053a36f7 100644
--- a/contrib/btree_gist/btree_inet.c
+++ b/contrib/btree_gist/btree_inet.c
@@ -6,9 +6,9 @@
typedef struct inetkey
{
- double lower;
- double upper;
-} inetKEY;
+ double lower;
+ double upper;
+} inetKEY;
/*
** inet ops
@@ -22,62 +22,65 @@ PG_FUNCTION_INFO_V1(gbt_cidr_consistent);
PG_FUNCTION_INFO_V1(gbt_inet_penalty);
PG_FUNCTION_INFO_V1(gbt_inet_same);
-Datum gbt_inet_compress(PG_FUNCTION_ARGS);
-Datum gbt_cidr_compress(PG_FUNCTION_ARGS);
-Datum gbt_inet_union(PG_FUNCTION_ARGS);
-Datum gbt_inet_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_inet_consistent(PG_FUNCTION_ARGS);
-Datum gbt_cidr_consistent(PG_FUNCTION_ARGS);
-Datum gbt_inet_penalty(PG_FUNCTION_ARGS);
-Datum gbt_inet_same(PG_FUNCTION_ARGS);
+Datum gbt_inet_compress(PG_FUNCTION_ARGS);
+Datum gbt_cidr_compress(PG_FUNCTION_ARGS);
+Datum gbt_inet_union(PG_FUNCTION_ARGS);
+Datum gbt_inet_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_inet_consistent(PG_FUNCTION_ARGS);
+Datum gbt_cidr_consistent(PG_FUNCTION_ARGS);
+Datum gbt_inet_penalty(PG_FUNCTION_ARGS);
+Datum gbt_inet_same(PG_FUNCTION_ARGS);
-static bool gbt_inetgt (const void *a, const void *b)
+static bool
+gbt_inetgt(const void *a, const void *b)
{
- return ( *((double*)a) > *((double*)b) );
+ return (*((double *) a) > *((double *) b));
}
-static bool gbt_inetge (const void *a, const void *b)
+static bool
+gbt_inetge(const void *a, const void *b)
{
- return ( *((double*)a) >= *((double*)b) );
+ return (*((double *) a) >= *((double *) b));
}
-static bool gbt_ineteq (const void *a, const void *b)
+static bool
+gbt_ineteq(const void *a, const void *b)
{
- return ( *((double*)a) == *((double*)b) );
+ return (*((double *) a) == *((double *) b));
}
-static bool gbt_inetle (const void *a, const void *b)
+static bool
+gbt_inetle(const void *a, const void *b)
{
- return ( *((double*)a) <= *((double*)b) );
+ return (*((double *) a) <= *((double *) b));
}
-static bool gbt_inetlt (const void *a, const void *b)
+static bool
+gbt_inetlt(const void *a, const void *b)
{
- return ( *((double*)a) < *((double*)b) );
+ return (*((double *) a) < *((double *) b));
}
static int
gbt_inetkey_cmp(const void *a, const void *b)
{
- if ( *(double*)(&((Nsrt *) a)->t[0]) > *(double*)(&((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(double*)(&((Nsrt *) a)->t[0]) < *(double*)(&((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(double *) (&((Nsrt *) a)->t[0]) > *(double *) (&((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(double *) (&((Nsrt *) a)->t[0]) < *(double *) (&((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_inet,
- sizeof(double),
- gbt_inetgt,
- gbt_inetge,
- gbt_ineteq,
- gbt_inetle,
- gbt_inetlt,
- gbt_inetkey_cmp
+ gbt_t_inet,
+ sizeof(double),
+ gbt_inetgt,
+ gbt_inetge,
+ gbt_ineteq,
+ gbt_inetle,
+ gbt_inetlt,
+ gbt_inetkey_cmp
};
@@ -87,24 +90,25 @@ static const gbtree_ninfo tinfo =
-static GISTENTRY *
-gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid)
+static GISTENTRY *
+gbt_inet_compress_inetrnal(GISTENTRY *retval, GISTENTRY *entry, Oid typid)
{
-
- if (entry->leafkey)
- {
- inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
- retval = palloc(sizeof(GISTENTRY));
- r->lower = convert_network_to_scalar(entry->key, typid );
- r->upper = r->lower ;
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, sizeof(inetKEY), FALSE);
- }
- else
- retval = entry;
- return ( retval );
+ if (entry->leafkey)
+ {
+ inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
+
+ retval = palloc(sizeof(GISTENTRY));
+ r->lower = convert_network_to_scalar(entry->key, typid);
+ r->upper = r->lower;
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, sizeof(inetKEY), FALSE);
+ }
+ else
+ retval = entry;
+
+ return (retval);
}
@@ -112,113 +116,118 @@ gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid)
Datum
gbt_inet_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_inet_compress_inetrnal(retval ,entry ,INETOID ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_inet_compress_inetrnal(retval, entry, INETOID));
}
Datum
gbt_cidr_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_inet_compress_inetrnal(retval ,entry ,CIDROID ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_inet_compress_inetrnal(retval, entry, CIDROID));
}
static bool
-gbt_inet_consistent_internal (
- const GISTENTRY * entry,
- const double * query,
- const StrategyNumber * strategy
-){
- inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
+gbt_inet_consistent_internal(
+ const GISTENTRY *entry,
+ const double *query,
+ const StrategyNumber *strategy
+)
+{
+ inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- return (
- gbt_num_consistent( &key, (void*)query,strategy,GIST_LEAF(entry),&tinfo)
- );
+ return (
+ gbt_num_consistent(&key, (void *) query, strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_inet_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- double query = convert_network_to_scalar( PG_GETARG_DATUM(1) ,INETOID );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ double query = convert_network_to_scalar(PG_GETARG_DATUM(1), INETOID);
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- PG_RETURN_BOOL(
- gbt_inet_consistent_internal ( entry, &query, &strategy )
- );
+ PG_RETURN_BOOL(
+ gbt_inet_consistent_internal(entry, &query, &strategy)
+ );
}
Datum
gbt_cidr_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- double query = convert_network_to_scalar( PG_GETARG_DATUM(1) ,CIDROID );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ double query = convert_network_to_scalar(PG_GETARG_DATUM(1), CIDROID);
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- PG_RETURN_BOOL(
- gbt_inet_consistent_internal ( entry, &query, &strategy )
- );
+ PG_RETURN_BOOL(
+ gbt_inet_consistent_internal(entry, &query, &strategy)
+ );
}
Datum
gbt_inet_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(inetKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(inetKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_inet_penalty(PG_FUNCTION_ARGS)
{
- inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
- double res ;
+ double res;
- *result = 0.0;
+ *result = 0.0;
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_inet_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_inet_same(PG_FUNCTION_ARGS)
{
- inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
- inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
+ inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index 9b791df2c37..3eb5801a7e9 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -3,9 +3,9 @@
typedef struct int16key
{
- int16 lower;
- int16 upper;
-} int16KEY;
+ int16 lower;
+ int16 upper;
+} int16KEY;
/*
** int16 ops
@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_int2_consistent);
PG_FUNCTION_INFO_V1(gbt_int2_penalty);
PG_FUNCTION_INFO_V1(gbt_int2_same);
-Datum gbt_int2_compress(PG_FUNCTION_ARGS);
-Datum gbt_int2_union(PG_FUNCTION_ARGS);
-Datum gbt_int2_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int2_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int2_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int2_same(PG_FUNCTION_ARGS);
+Datum gbt_int2_compress(PG_FUNCTION_ARGS);
+Datum gbt_int2_union(PG_FUNCTION_ARGS);
+Datum gbt_int2_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_int2_consistent(PG_FUNCTION_ARGS);
+Datum gbt_int2_penalty(PG_FUNCTION_ARGS);
+Datum gbt_int2_same(PG_FUNCTION_ARGS);
-static bool gbt_int2gt (const void *a, const void *b)
+static bool
+gbt_int2gt(const void *a, const void *b)
{
- return ( *((int16*)a) > *((int16*)b) );
+ return (*((int16 *) a) > *((int16 *) b));
}
-static bool gbt_int2ge (const void *a, const void *b)
+static bool
+gbt_int2ge(const void *a, const void *b)
{
- return ( *((int16*)a) >= *((int16*)b) );
+ return (*((int16 *) a) >= *((int16 *) b));
}
-static bool gbt_int2eq (const void *a, const void *b)
+static bool
+gbt_int2eq(const void *a, const void *b)
{
- return ( *((int16*)a) == *((int16*)b) );
+ return (*((int16 *) a) == *((int16 *) b));
}
-static bool gbt_int2le (const void *a, const void *b)
+static bool
+gbt_int2le(const void *a, const void *b)
{
- return ( *((int16*)a) <= *((int16*)b) );
+ return (*((int16 *) a) <= *((int16 *) b));
}
-static bool gbt_int2lt (const void *a, const void *b)
+static bool
+gbt_int2lt(const void *a, const void *b)
{
- return ( *((int16*)a) < *((int16*)b) );
+ return (*((int16 *) a) < *((int16 *) b));
}
static int
gbt_int2key_cmp(const void *a, const void *b)
{
- if ( *(int16*)(&((Nsrt *) a)->t[0]) > *(int16*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(int16*)&(((Nsrt *) a)->t[0]) < *(int16*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_int2,
- sizeof(int16),
- gbt_int2gt,
- gbt_int2ge,
- gbt_int2eq,
- gbt_int2le,
- gbt_int2lt,
- gbt_int2key_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_int2,
+ sizeof(int16),
+ gbt_int2gt,
+ gbt_int2ge,
+ gbt_int2eq,
+ gbt_int2le,
+ gbt_int2lt,
+ gbt_int2key_cmp
};
@@ -85,77 +88,81 @@ static const gbtree_ninfo tinfo =
Datum
gbt_int2_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_int2_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- int16 query = PG_GETARG_INT16(1);
- int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ int16 query = PG_GETARG_INT16(1);
+ int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_int2_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(int16KEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(int16KEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_int2_penalty(PG_FUNCTION_ARGS)
{
- int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- int2 res ;
+ int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ int2 res;
- *result = 0.0;
+ *result = 0.0;
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_int2_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_int2_same(PG_FUNCTION_ARGS)
{
- int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0);
- int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0);
+ int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 6e26752e5f3..6693185c98d 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -3,9 +3,9 @@
typedef struct int32key
{
- int32 lower;
- int32 upper;
-} int32KEY;
+ int32 lower;
+ int32 upper;
+} int32KEY;
/*
** int32 ops
@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int4_consistent);
PG_FUNCTION_INFO_V1(gbt_int4_penalty);
PG_FUNCTION_INFO_V1(gbt_int4_same);
-Datum gbt_int4_compress(PG_FUNCTION_ARGS);
-Datum gbt_int4_union(PG_FUNCTION_ARGS);
-Datum gbt_int4_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int4_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int4_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int4_same(PG_FUNCTION_ARGS);
+Datum gbt_int4_compress(PG_FUNCTION_ARGS);
+Datum gbt_int4_union(PG_FUNCTION_ARGS);
+Datum gbt_int4_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_int4_consistent(PG_FUNCTION_ARGS);
+Datum gbt_int4_penalty(PG_FUNCTION_ARGS);
+Datum gbt_int4_same(PG_FUNCTION_ARGS);
-static bool gbt_int4gt (const void *a, const void *b)
+static bool
+gbt_int4gt(const void *a, const void *b)
{
- return ( *((int32*)a) > *((int32*)b) );
+ return (*((int32 *) a) > *((int32 *) b));
}
-static bool gbt_int4ge (const void *a, const void *b)
+static bool
+gbt_int4ge(const void *a, const void *b)
{
- return ( *((int32*)a) >= *((int32*)b) );
+ return (*((int32 *) a) >= *((int32 *) b));
}
-static bool gbt_int4eq (const void *a, const void *b)
+static bool
+gbt_int4eq(const void *a, const void *b)
{
- return ( *((int32*)a) == *((int32*)b) );
+ return (*((int32 *) a) == *((int32 *) b));
}
-static bool gbt_int4le (const void *a, const void *b)
+static bool
+gbt_int4le(const void *a, const void *b)
{
- return ( *((int32*)a) <= *((int32*)b) );
+ return (*((int32 *) a) <= *((int32 *) b));
}
-static bool gbt_int4lt (const void *a, const void *b)
+static bool
+gbt_int4lt(const void *a, const void *b)
{
- return ( *((int32*)a) < *((int32*)b) );
+ return (*((int32 *) a) < *((int32 *) b));
}
static int
gbt_int4key_cmp(const void *a, const void *b)
{
- if ( *(int32*)&(((Nsrt *) a)->t[0]) > *(int32*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(int32*)&(((Nsrt *) a)->t[0]) < *(int32*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_int4,
- sizeof(int32),
- gbt_int4gt,
- gbt_int4ge,
- gbt_int4eq,
- gbt_int4le,
- gbt_int4lt,
- gbt_int4key_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_int4,
+ sizeof(int32),
+ gbt_int4gt,
+ gbt_int4ge,
+ gbt_int4eq,
+ gbt_int4le,
+ gbt_int4lt,
+ gbt_int4key_cmp
};
@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum
gbt_int4_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
@@ -92,68 +96,71 @@ Datum
gbt_int4_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- int32 query = PG_GETARG_INT32(1);
- int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ int32 query = PG_GETARG_INT32(1);
+ int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_int4_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc( sizeof(int32KEY) );
- *(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(int32KEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_int4_penalty(PG_FUNCTION_ARGS)
{
- int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- int4 res ;
+ int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ int4 res;
- *result = 0.0;
+ *result = 0.0;
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_int4_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_int4_same(PG_FUNCTION_ARGS)
{
- int32KEY *b1 = (int32KEY *) PG_GETARG_POINTER(0);
- int32KEY *b2 = (int32KEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ int32KEY *b1 = (int32KEY *) PG_GETARG_POINTER(0);
+ int32KEY *b2 = (int32KEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c
index c12d078f4cd..0741193c6f0 100644
--- a/contrib/btree_gist/btree_int8.c
+++ b/contrib/btree_gist/btree_int8.c
@@ -3,9 +3,9 @@
typedef struct int64key
{
- int64 lower;
- int64 upper;
-} int64KEY;
+ int64 lower;
+ int64 upper;
+} int64KEY;
/*
** int64 ops
@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int8_consistent);
PG_FUNCTION_INFO_V1(gbt_int8_penalty);
PG_FUNCTION_INFO_V1(gbt_int8_same);
-Datum gbt_int8_compress(PG_FUNCTION_ARGS);
-Datum gbt_int8_union(PG_FUNCTION_ARGS);
-Datum gbt_int8_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_int8_consistent(PG_FUNCTION_ARGS);
-Datum gbt_int8_penalty(PG_FUNCTION_ARGS);
-Datum gbt_int8_same(PG_FUNCTION_ARGS);
+Datum gbt_int8_compress(PG_FUNCTION_ARGS);
+Datum gbt_int8_union(PG_FUNCTION_ARGS);
+Datum gbt_int8_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_int8_consistent(PG_FUNCTION_ARGS);
+Datum gbt_int8_penalty(PG_FUNCTION_ARGS);
+Datum gbt_int8_same(PG_FUNCTION_ARGS);
-static bool gbt_int8gt (const void *a, const void *b)
+static bool
+gbt_int8gt(const void *a, const void *b)
{
- return ( *((int64*)a) > *((int64*)b) );
+ return (*((int64 *) a) > *((int64 *) b));
}
-static bool gbt_int8ge (const void *a, const void *b)
+static bool
+gbt_int8ge(const void *a, const void *b)
{
- return ( *((int64*)a) >= *((int64*)b) );
+ return (*((int64 *) a) >= *((int64 *) b));
}
-static bool gbt_int8eq (const void *a, const void *b)
+static bool
+gbt_int8eq(const void *a, const void *b)
{
- return ( *((int64*)a) == *((int64*)b) );
+ return (*((int64 *) a) == *((int64 *) b));
}
-static bool gbt_int8le (const void *a, const void *b)
+static bool
+gbt_int8le(const void *a, const void *b)
{
- return ( *((int64*)a) <= *((int64*)b) );
+ return (*((int64 *) a) <= *((int64 *) b));
}
-static bool gbt_int8lt (const void *a, const void *b)
+static bool
+gbt_int8lt(const void *a, const void *b)
{
- return ( *((int64*)a) < *((int64*)b) );
+ return (*((int64 *) a) < *((int64 *) b));
}
static int
gbt_int8key_cmp(const void *a, const void *b)
{
- if ( *(int64*)&(((Nsrt *) a)->t[0]) > *(int64*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(int64*)&(((Nsrt *) a)->t[0]) < *(int64*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_int8,
- sizeof(int64),
- gbt_int8gt,
- gbt_int8ge,
- gbt_int8eq,
- gbt_int8le,
- gbt_int8lt,
- gbt_int8key_cmp
+ gbt_t_int8,
+ sizeof(int64),
+ gbt_int8gt,
+ gbt_int8ge,
+ gbt_int8eq,
+ gbt_int8le,
+ gbt_int8lt,
+ gbt_int8key_cmp
};
@@ -82,79 +85,82 @@ static const gbtree_ninfo tinfo =
Datum
gbt_int8_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_int8_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- int64 query = PG_GETARG_INT64(1);
- int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ int64 query = PG_GETARG_INT64(1);
+ int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_int8_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(int64KEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(int64KEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_int8_penalty(PG_FUNCTION_ARGS)
{
- int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- int64 res ;
+ int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ int64 res;
- *result = 0.0;
+ *result = 0.0;
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_int8_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_int8_same(PG_FUNCTION_ARGS)
{
- int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
- int64KEY *b2 = (int64KEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
+ int64KEY *b2 = (int64KEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c
index 9dd37010846..97374a40544 100644
--- a/contrib/btree_gist/btree_interval.c
+++ b/contrib/btree_gist/btree_interval.c
@@ -3,8 +3,9 @@
typedef struct
{
- Interval lower, upper;
-} intvKEY;
+ Interval lower,
+ upper;
+} intvKEY;
/*
@@ -18,81 +19,88 @@ PG_FUNCTION_INFO_V1(gbt_intv_consistent);
PG_FUNCTION_INFO_V1(gbt_intv_penalty);
PG_FUNCTION_INFO_V1(gbt_intv_same);
-Datum gbt_intv_compress(PG_FUNCTION_ARGS);
-Datum gbt_intv_decompress(PG_FUNCTION_ARGS);
-Datum gbt_intv_union(PG_FUNCTION_ARGS);
-Datum gbt_intv_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_intv_consistent(PG_FUNCTION_ARGS);
-Datum gbt_intv_penalty(PG_FUNCTION_ARGS);
-Datum gbt_intv_same(PG_FUNCTION_ARGS);
+Datum gbt_intv_compress(PG_FUNCTION_ARGS);
+Datum gbt_intv_decompress(PG_FUNCTION_ARGS);
+Datum gbt_intv_union(PG_FUNCTION_ARGS);
+Datum gbt_intv_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_intv_consistent(PG_FUNCTION_ARGS);
+Datum gbt_intv_penalty(PG_FUNCTION_ARGS);
+Datum gbt_intv_same(PG_FUNCTION_ARGS);
-static bool gbt_intvgt (const void *a, const void *b)
+static bool
+gbt_intvgt(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2 ( interval_gt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
+ return DatumGetBool(DirectFunctionCall2(interval_gt, IntervalPGetDatum(a), IntervalPGetDatum(b)));
}
-static bool gbt_intvge (const void *a, const void *b)
+static bool
+gbt_intvge(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2 ( interval_ge , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
+ return DatumGetBool(DirectFunctionCall2(interval_ge, IntervalPGetDatum(a), IntervalPGetDatum(b)));
}
-static bool gbt_intveq (const void *a, const void *b)
+static bool
+gbt_intveq(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2 ( interval_eq , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
+ return DatumGetBool(DirectFunctionCall2(interval_eq, IntervalPGetDatum(a), IntervalPGetDatum(b)));
}
-static bool gbt_intvle (const void *a, const void *b)
+static bool
+gbt_intvle(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2 ( interval_le , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
+ return DatumGetBool(DirectFunctionCall2(interval_le, IntervalPGetDatum(a), IntervalPGetDatum(b)));
}
-static bool gbt_intvlt (const void *a, const void *b)
+static bool
+gbt_intvlt(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2 ( interval_lt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
+ return DatumGetBool(DirectFunctionCall2(interval_lt, IntervalPGetDatum(a), IntervalPGetDatum(b)));
}
static int
gbt_intvkey_cmp(const void *a, const void *b)
{
- return DatumGetInt32 (
- DirectFunctionCall2 ( interval_cmp ,
- IntervalPGetDatum(((Nsrt *) a)->t) ,
- IntervalPGetDatum(((Nsrt *) b)->t)
- )
- );
+ return DatumGetInt32(
+ DirectFunctionCall2(interval_cmp,
+ IntervalPGetDatum(((Nsrt *) a)->t),
+ IntervalPGetDatum(((Nsrt *) b)->t)
+ )
+ );
}
-static double intr2num ( const Interval * i )
+static double
+intr2num(const Interval *i)
{
- double ret = 0.0;
- struct pg_tm tm;
- fsec_t fsec;
- interval2tm( *i, &tm, &fsec);
- ret += ( tm.tm_year * 360.0 * 86400.0 ) ;
- ret += ( tm.tm_mon * 12.0 * 86400.0 ) ;
- ret += ( tm.tm_mday * 86400.0 ) ;
- ret += ( tm.tm_hour * 3600.0 ) ;
- ret += ( tm.tm_min * 60.0 ) ;
- ret += ( tm.tm_sec ) ;
- ret += ( fsec / 1000000.0 );
+ double ret = 0.0;
+ struct pg_tm tm;
+ fsec_t fsec;
- return ( ret );
+ interval2tm(*i, &tm, &fsec);
+ ret += (tm.tm_year * 360.0 * 86400.0);
+ ret += (tm.tm_mon * 12.0 * 86400.0);
+ ret += (tm.tm_mday * 86400.0);
+ ret += (tm.tm_hour * 3600.0);
+ ret += (tm.tm_min * 60.0);
+ ret += (tm.tm_sec);
+ ret += (fsec / 1000000.0);
+
+ return (ret);
}
#define INTERVALSIZE 12
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_intv,
- sizeof(Interval),
- gbt_intvgt,
- gbt_intvge,
- gbt_intveq,
- gbt_intvle,
- gbt_intvlt,
- gbt_intvkey_cmp
+ gbt_t_intv,
+ sizeof(Interval),
+ gbt_intvgt,
+ gbt_intvge,
+ gbt_intveq,
+ gbt_intvle,
+ gbt_intvlt,
+ gbt_intvkey_cmp
};
@@ -104,126 +112,137 @@ static const gbtree_ninfo tinfo =
Datum
gbt_intv_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = entry;
- if ( entry->leafkey || INTERVALSIZE != sizeof(Interval) ) {
- char *r = ( char * ) palloc(2 * INTERVALSIZE);
-
- retval = palloc(sizeof(GISTENTRY));
-
- if ( entry->leafkey ) {
- Interval *key = DatumGetIntervalP(entry->key);
- memcpy( (void*) r , (void*)key, INTERVALSIZE);
- memcpy( (void*)(r + INTERVALSIZE), (void*)key, INTERVALSIZE);
- } else {
- intvKEY *key = ( intvKEY * ) DatumGetPointer(entry->key);
- memcpy(r, &key->lower, INTERVALSIZE);
- memcpy(r + INTERVALSIZE, &key->upper, INTERVALSIZE);
- }
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, 2 * INTERVALSIZE, FALSE);
- }
-
- PG_RETURN_POINTER(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = entry;
+
+ if (entry->leafkey || INTERVALSIZE != sizeof(Interval))
+ {
+ char *r = (char *) palloc(2 * INTERVALSIZE);
+
+ retval = palloc(sizeof(GISTENTRY));
+
+ if (entry->leafkey)
+ {
+ Interval *key = DatumGetIntervalP(entry->key);
+
+ memcpy((void *) r, (void *) key, INTERVALSIZE);
+ memcpy((void *) (r + INTERVALSIZE), (void *) key, INTERVALSIZE);
+ }
+ else
+ {
+ intvKEY *key = (intvKEY *) DatumGetPointer(entry->key);
+
+ memcpy(r, &key->lower, INTERVALSIZE);
+ memcpy(r + INTERVALSIZE, &key->upper, INTERVALSIZE);
+ }
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, 2 * INTERVALSIZE, FALSE);
+ }
+
+ PG_RETURN_POINTER(retval);
}
Datum
gbt_intv_decompress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = entry;
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = entry;
- if ( INTERVALSIZE != sizeof(Interval) ) {
- intvKEY *r = palloc(sizeof(intvKEY));
- char *key = DatumGetPointer(entry->key);
+ if (INTERVALSIZE != sizeof(Interval))
+ {
+ intvKEY *r = palloc(sizeof(intvKEY));
+ char *key = DatumGetPointer(entry->key);
- retval = palloc(sizeof(GISTENTRY));
- memcpy( &r->lower, key, INTERVALSIZE);
- memcpy( &r->upper, key+ INTERVALSIZE, INTERVALSIZE);
+ retval = palloc(sizeof(GISTENTRY));
+ memcpy(&r->lower, key, INTERVALSIZE);
+ memcpy(&r->upper, key + INTERVALSIZE, INTERVALSIZE);
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, sizeof(intvKEY), FALSE);
- }
- PG_RETURN_POINTER(retval);
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, sizeof(intvKEY), FALSE);
+ }
+ PG_RETURN_POINTER(retval);
}
Datum
gbt_intv_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- Interval *query = PG_GETARG_INTERVAL_P(1);
- intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
-
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)query ,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ Interval *query = PG_GETARG_INTERVAL_P(1);
+ intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_intv_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(intvKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(intvKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(intvKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(intvKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_intv_penalty(PG_FUNCTION_ARGS)
{
- intvKEY *origentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- double iorg[2], inew[2], res;
+ intvKEY *origentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ double iorg[2],
+ inew[2],
+ res;
- iorg[0] = intr2num ( &origentry->lower );
- iorg[1] = intr2num ( &origentry->upper );
- inew[0] = intr2num ( &newentry->lower );
- inew[1] = intr2num ( &newentry->upper );
+ iorg[0] = intr2num(&origentry->lower);
+ iorg[1] = intr2num(&origentry->upper);
+ inew[0] = intr2num(&newentry->lower);
+ inew[1] = intr2num(&newentry->upper);
- penalty_range_enlarge ( iorg[0], iorg[1], inew[0], inew[1] );
+ penalty_range_enlarge(iorg[0], iorg[1], inew[0], inew[1]);
- *result = 0.0;
+ *result = 0.0;
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( res + iorg[1] - iorg[0] ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / (res + iorg[1] - iorg[0]));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_intv_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_intv_same(PG_FUNCTION_ARGS)
{
- intvKEY *b1 = (intvKEY *) PG_GETARG_POINTER(0);
- intvKEY *b2 = (intvKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ intvKEY *b1 = (intvKEY *) PG_GETARG_POINTER(0);
+ intvKEY *b2 = (intvKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_macaddr.c b/contrib/btree_gist/btree_macaddr.c
index b6e9c672f1d..3f08a586556 100644
--- a/contrib/btree_gist/btree_macaddr.c
+++ b/contrib/btree_gist/btree_macaddr.c
@@ -5,9 +5,9 @@
typedef struct
{
- macaddr lower;
- macaddr upper;
-} macKEY;
+ macaddr lower;
+ macaddr upper;
+} macKEY;
/*
** OID ops
@@ -19,62 +19,67 @@ PG_FUNCTION_INFO_V1(gbt_macad_consistent);
PG_FUNCTION_INFO_V1(gbt_macad_penalty);
PG_FUNCTION_INFO_V1(gbt_macad_same);
-Datum gbt_macad_compress(PG_FUNCTION_ARGS);
-Datum gbt_macad_union(PG_FUNCTION_ARGS);
-Datum gbt_macad_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_macad_consistent(PG_FUNCTION_ARGS);
-Datum gbt_macad_penalty(PG_FUNCTION_ARGS);
-Datum gbt_macad_same(PG_FUNCTION_ARGS);
+Datum gbt_macad_compress(PG_FUNCTION_ARGS);
+Datum gbt_macad_union(PG_FUNCTION_ARGS);
+Datum gbt_macad_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_macad_consistent(PG_FUNCTION_ARGS);
+Datum gbt_macad_penalty(PG_FUNCTION_ARGS);
+Datum gbt_macad_same(PG_FUNCTION_ARGS);
-static bool gbt_macadgt (const void *a, const void *b)
+static bool
+gbt_macadgt(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2(macaddr_gt,PointerGetDatum(a),PointerGetDatum(b)));
+ return DatumGetBool(DirectFunctionCall2(macaddr_gt, PointerGetDatum(a), PointerGetDatum(b)));
}
-static bool gbt_macadge (const void *a, const void *b)
+static bool
+gbt_macadge(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2(macaddr_ge,PointerGetDatum(a),PointerGetDatum(b)));
+ return DatumGetBool(DirectFunctionCall2(macaddr_ge, PointerGetDatum(a), PointerGetDatum(b)));
}
-static bool gbt_macadeq (const void *a, const void *b)
+static bool
+gbt_macadeq(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2(macaddr_eq,PointerGetDatum(a),PointerGetDatum(b)));
+ return DatumGetBool(DirectFunctionCall2(macaddr_eq, PointerGetDatum(a), PointerGetDatum(b)));
}
-static bool gbt_macadle (const void *a, const void *b)
+static bool
+gbt_macadle(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2(macaddr_le,PointerGetDatum(a),PointerGetDatum(b)));
+ return DatumGetBool(DirectFunctionCall2(macaddr_le, PointerGetDatum(a), PointerGetDatum(b)));
}
-static bool gbt_macadlt (const void *a, const void *b)
+static bool
+gbt_macadlt(const void *a, const void *b)
{
- return DatumGetBool(DirectFunctionCall2(macaddr_lt,PointerGetDatum(a),PointerGetDatum(b)));
+ return DatumGetBool(DirectFunctionCall2(macaddr_lt, PointerGetDatum(a), PointerGetDatum(b)));
}
static int
gbt_macadkey_cmp(const void *a, const void *b)
{
- return DatumGetInt32(
- DirectFunctionCall2(
- macaddr_cmp ,
- PointerGetDatum (&((Nsrt *) a)->t[0]),
- PointerGetDatum (&((Nsrt *) b)->t[0])
- )
- );
+ return DatumGetInt32(
+ DirectFunctionCall2(
+ macaddr_cmp,
+ PointerGetDatum(&((Nsrt *) a)->t[0]),
+ PointerGetDatum(&((Nsrt *) b)->t[0])
+ )
+ );
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_macad,
- sizeof(macaddr),
- gbt_macadgt,
- gbt_macadge,
- gbt_macadeq,
- gbt_macadle,
- gbt_macadlt,
- gbt_macadkey_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_macad,
+ sizeof(macaddr),
+ gbt_macadgt,
+ gbt_macadge,
+ gbt_macadeq,
+ gbt_macadle,
+ gbt_macadlt,
+ gbt_macadkey_cmp
};
@@ -84,14 +89,16 @@ static const gbtree_ninfo tinfo =
-static uint64 mac_2_uint64 ( macaddr * m ){
- unsigned char * mi = ( unsigned char * ) m;
- uint64 res = 0;
- int i;
- for (i=0; i<6; i++ ){
- res += ( ( (uint64) mi[i] ) << ( (uint64) ( (5-i)*8 ) ) );
- }
- return res;
+static uint64
+mac_2_uint64(macaddr *m)
+{
+ unsigned char *mi = (unsigned char *) m;
+ uint64 res = 0;
+ int i;
+
+ for (i = 0; i < 6; i++)
+ res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
+ return res;
}
@@ -99,9 +106,10 @@ static uint64 mac_2_uint64 ( macaddr * m ){
Datum
gbt_macad_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
@@ -109,76 +117,79 @@ Datum
gbt_macad_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
- macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
+ macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_macad_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(macKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(macKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_macad_penalty(PG_FUNCTION_ARGS)
{
- macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- uint64 iorg[2], inew[2];
- uint64 res;
+ macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ uint64 iorg[2],
+ inew[2];
+ uint64 res;
- iorg[0] = mac_2_uint64 ( &origentry->lower );
- iorg[1] = mac_2_uint64 ( &origentry->upper );
- inew[0] = mac_2_uint64 ( &newentry->lower );
- inew[1] = mac_2_uint64 ( &newentry->upper );
+ iorg[0] = mac_2_uint64(&origentry->lower);
+ iorg[1] = mac_2_uint64(&origentry->upper);
+ inew[0] = mac_2_uint64(&newentry->lower);
+ inew[1] = mac_2_uint64(&newentry->upper);
- penalty_range_enlarge ( iorg[0], iorg[1], inew[0], inew[1] );
+ penalty_range_enlarge(iorg[0], iorg[1], inew[0], inew[1]);
- *result = 0.0;
+ *result = 0.0;
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( ( (double)res ) / ( (double)res + (double)iorg[1] - (double)iorg[0] ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (((double) res) / ((double) res + (double) iorg[1] - (double) iorg[0]));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_macad_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_macad_same(PG_FUNCTION_ARGS)
{
- macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
- macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
+ macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_numeric.c b/contrib/btree_gist/btree_numeric.c
index f46cfa4fef8..8b54b931d5b 100644
--- a/contrib/btree_gist/btree_numeric.c
+++ b/contrib/btree_gist/btree_numeric.c
@@ -13,61 +13,67 @@ PG_FUNCTION_INFO_V1(gbt_numeric_consistent);
PG_FUNCTION_INFO_V1(gbt_numeric_penalty);
PG_FUNCTION_INFO_V1(gbt_numeric_same);
-Datum gbt_numeric_compress(PG_FUNCTION_ARGS);
-Datum gbt_numeric_union(PG_FUNCTION_ARGS);
-Datum gbt_numeric_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_numeric_consistent(PG_FUNCTION_ARGS);
-Datum gbt_numeric_penalty(PG_FUNCTION_ARGS);
-Datum gbt_numeric_same(PG_FUNCTION_ARGS);
+Datum gbt_numeric_compress(PG_FUNCTION_ARGS);
+Datum gbt_numeric_union(PG_FUNCTION_ARGS);
+Datum gbt_numeric_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_numeric_consistent(PG_FUNCTION_ARGS);
+Datum gbt_numeric_penalty(PG_FUNCTION_ARGS);
+Datum gbt_numeric_same(PG_FUNCTION_ARGS);
/* define for comparison */
-static bool gbt_numeric_gt (const void *a, const void *b)
+static bool
+gbt_numeric_gt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( numeric_gt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(numeric_gt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_numeric_ge (const void *a, const void *b)
+static bool
+gbt_numeric_ge(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( numeric_ge ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(numeric_ge, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_numeric_eq (const void *a, const void *b)
+static bool
+gbt_numeric_eq(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( numeric_eq ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(numeric_eq, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_numeric_le (const void *a, const void *b)
+static bool
+gbt_numeric_le(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( numeric_le ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(numeric_le, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_numeric_lt (const void *a, const void *b)
+static bool
+gbt_numeric_lt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( numeric_lt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(numeric_lt, PointerGetDatum(a), PointerGetDatum(b))));
}
-
-static int32 gbt_numeric_cmp ( const bytea * a , const bytea * b )
+
+static int32
+gbt_numeric_cmp(const bytea *a, const bytea *b)
{
- return
- ( DatumGetInt32(DirectFunctionCall2(numeric_cmp,PointerGetDatum(a),PointerGetDatum(b) ) ) );
+ return
+ (DatumGetInt32(DirectFunctionCall2(numeric_cmp, PointerGetDatum(a), PointerGetDatum(b))));
}
static const gbtree_vinfo tinfo =
{
- gbt_t_numeric,
- FALSE,
- FALSE,
- gbt_numeric_gt,
- gbt_numeric_ge,
- gbt_numeric_eq,
- gbt_numeric_le,
- gbt_numeric_lt,
- gbt_numeric_cmp,
- NULL
+ gbt_t_numeric,
+ FALSE,
+ FALSE,
+ gbt_numeric_gt,
+ gbt_numeric_ge,
+ gbt_numeric_eq,
+ gbt_numeric_le,
+ gbt_numeric_lt,
+ gbt_numeric_cmp,
+ NULL
};
@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo =
Datum
-gbt_numeric_compress (PG_FUNCTION_ARGS)
+gbt_numeric_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+
+ PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
}
@@ -89,24 +96,22 @@ Datum
gbt_numeric_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
- void *qtst = ( void * ) DatumGetPointer ( PG_GETARG_DATUM(1) );
- void *query = ( void * ) DatumGetNumeric ( PG_GETARG_DATUM(1) );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool retval = FALSE;
- GBT_VARKEY_R r = gbt_var_key_readable ( key );
-
- retval = gbt_var_consistent( &r, query, &strategy, GIST_LEAF(entry), &tinfo );
-
- if ( ktst != key ){
- pfree ( key );
- }
- if ( qtst != query ){
- pfree ( query );
- }
- PG_RETURN_BOOL(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
+ void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool retval = FALSE;
+ GBT_VARKEY_R r = gbt_var_key_readable(key);
+
+ retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
+
+ if (ktst != key)
+ pfree(key);
+ if (qtst != query)
+ pfree(query);
+ PG_RETURN_BOOL(retval);
}
@@ -114,104 +119,110 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
Datum
gbt_numeric_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- int32 * size = (int *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ int32 *size = (int *) PG_GETARG_POINTER(1);
+
+ PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
}
-
+
Datum
gbt_numeric_same(PG_FUNCTION_ARGS)
{
- Datum d1 = PG_GETARG_DATUM(0);
- Datum d2 = PG_GETARG_DATUM(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
- PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
+ Datum d1 = PG_GETARG_DATUM(0);
+ Datum d2 = PG_GETARG_DATUM(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
+
+ PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
}
Datum
-gbt_numeric_penalty (PG_FUNCTION_ARGS)
+gbt_numeric_penalty(PG_FUNCTION_ARGS)
{
- GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1);
- float *result = (float *) PG_GETARG_POINTER(2);
+ GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
+ float *result = (float *) PG_GETARG_POINTER(2);
- Numeric us, os, ds ;
+ Numeric us,
+ os,
+ ds;
- GBT_VARKEY *org = (GBT_VARKEY *) DatumGetPointer(o->key);
- GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
- Datum uni ;
- GBT_VARKEY_R rk , ok, uk ;
+ GBT_VARKEY *org = (GBT_VARKEY *) DatumGetPointer(o->key);
+ GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
+ Datum uni;
+ GBT_VARKEY_R rk,
+ ok,
+ uk;
- rk = gbt_var_key_readable ( org );
- uni = PointerGetDatum( gbt_var_key_copy( &rk, TRUE ) );
- gbt_var_bin_union ( &uni , newe, &tinfo );
- ok = gbt_var_key_readable ( org );
- uk = gbt_var_key_readable ( (GBT_VARKEY *) DatumGetPointer(uni) );
+ rk = gbt_var_key_readable(org);
+ uni = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
+ gbt_var_bin_union(&uni, newe, &tinfo);
+ ok = gbt_var_key_readable(org);
+ uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
- us = DatumGetNumeric(DirectFunctionCall2(
- numeric_sub,
- PointerGetDatum(uk.upper),
- PointerGetDatum(uk.lower)
- ));
+ us = DatumGetNumeric(DirectFunctionCall2(
+ numeric_sub,
+ PointerGetDatum(uk.upper),
+ PointerGetDatum(uk.lower)
+ ));
- pfree ( DatumGetPointer(uni) );
+ pfree(DatumGetPointer(uni));
- os = DatumGetNumeric(DirectFunctionCall2(
- numeric_sub,
- PointerGetDatum(ok.upper),
- PointerGetDatum(ok.lower)
- ));
+ os = DatumGetNumeric(DirectFunctionCall2(
+ numeric_sub,
+ PointerGetDatum(ok.upper),
+ PointerGetDatum(ok.lower)
+ ));
- ds = DatumGetNumeric(DirectFunctionCall2(
- numeric_sub,
- NumericGetDatum(us),
- NumericGetDatum(os)
- ));
+ ds = DatumGetNumeric(DirectFunctionCall2(
+ numeric_sub,
+ NumericGetDatum(us),
+ NumericGetDatum(os)
+ ));
- pfree ( os );
+ pfree(os);
- if ( NUMERIC_IS_NAN( us ) )
- {
+ if (NUMERIC_IS_NAN(us))
+ {
- if ( NUMERIC_IS_NAN( os ) )
- {
- *result = 0.0;
- } else {
- *result = 1.0;
- }
+ if (NUMERIC_IS_NAN(os))
+ *result = 0.0;
+ else
+ *result = 1.0;
- } else {
+ }
+ else
+ {
- Numeric nul = DatumGetNumeric(DirectFunctionCall1( int4_numeric , Int32GetDatum (0) ) );
+ Numeric nul = DatumGetNumeric(DirectFunctionCall1(int4_numeric, Int32GetDatum(0)));
- *result = 0.0;
+ *result = 0.0;
- if ( DirectFunctionCall2( numeric_gt , NumericGetDatum(ds), NumericGetDatum(nul) ) )
- {
+ if (DirectFunctionCall2(numeric_gt, NumericGetDatum(ds), NumericGetDatum(nul)))
+ {
- *result += FLT_MIN ;
- os = DatumGetNumeric(DirectFunctionCall2(
- numeric_div,
- NumericGetDatum(ds),
- NumericGetDatum(us)
- ));
- *result += ( float4 ) DatumGetFloat8( DirectFunctionCall1( numeric_float8_no_overflow , NumericGetDatum(os) ) );
- pfree ( os );
+ *result += FLT_MIN;
+ os = DatumGetNumeric(DirectFunctionCall2(
+ numeric_div,
+ NumericGetDatum(ds),
+ NumericGetDatum(us)
+ ));
+ *result += (float4) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, NumericGetDatum(os)));
+ pfree(os);
- }
+ }
- pfree ( nul );
- }
+ pfree(nul);
+ }
- if ( *result > 0 )
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
+ if (*result > 0)
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
- pfree ( us );
- pfree ( ds );
+ pfree(us);
+ pfree(ds);
- PG_RETURN_POINTER( result );
+ PG_RETURN_POINTER(result);
}
@@ -219,9 +230,9 @@ gbt_numeric_penalty (PG_FUNCTION_ARGS)
Datum
gbt_numeric_picksplit(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
- gbt_var_picksplit ( entryvec, v, &tinfo );
- PG_RETURN_POINTER(v);
-}
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
+ gbt_var_picksplit(entryvec, v, &tinfo);
+ PG_RETURN_POINTER(v);
+}
diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c
index d7d98e4a7b3..db4182fc047 100644
--- a/contrib/btree_gist/btree_oid.c
+++ b/contrib/btree_gist/btree_oid.c
@@ -3,9 +3,9 @@
typedef struct
{
- Oid lower;
- Oid upper;
-} oidKEY;
+ Oid lower;
+ Oid upper;
+} oidKEY;
/*
** OID ops
@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_oid_consistent);
PG_FUNCTION_INFO_V1(gbt_oid_penalty);
PG_FUNCTION_INFO_V1(gbt_oid_same);
-Datum gbt_oid_compress(PG_FUNCTION_ARGS);
-Datum gbt_oid_union(PG_FUNCTION_ARGS);
-Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
-Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
-Datum gbt_oid_same(PG_FUNCTION_ARGS);
+Datum gbt_oid_compress(PG_FUNCTION_ARGS);
+Datum gbt_oid_union(PG_FUNCTION_ARGS);
+Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
+Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
+Datum gbt_oid_same(PG_FUNCTION_ARGS);
-static bool gbt_oidgt (const void *a, const void *b)
+static bool
+gbt_oidgt(const void *a, const void *b)
{
- return ( *((Oid*)a) > *((Oid*)b) );
+ return (*((Oid *) a) > *((Oid *) b));
}
-static bool gbt_oidge (const void *a, const void *b)
+static bool
+gbt_oidge(const void *a, const void *b)
{
- return ( *((Oid*)a) >= *((Oid*)b) );
+ return (*((Oid *) a) >= *((Oid *) b));
}
-static bool gbt_oideq (const void *a, const void *b)
+static bool
+gbt_oideq(const void *a, const void *b)
{
- return ( *((Oid*)a) == *((Oid*)b) );
+ return (*((Oid *) a) == *((Oid *) b));
}
-static bool gbt_oidle (const void *a, const void *b)
+static bool
+gbt_oidle(const void *a, const void *b)
{
- return ( *((Oid*)a) <= *((Oid*)b) );
+ return (*((Oid *) a) <= *((Oid *) b));
}
-static bool gbt_oidlt (const void *a, const void *b)
+static bool
+gbt_oidlt(const void *a, const void *b)
{
- return ( *((Oid*)a) < *((Oid*)b) );
+ return (*((Oid *) a) < *((Oid *) b));
}
static int
gbt_oidkey_cmp(const void *a, const void *b)
{
- if ( *(Oid*)&(((Nsrt *) a)->t[0]) > *(Oid*)&(((Nsrt *) b)->t[0]) ){
- return 1;
- } else
- if ( *(Oid*)&(((Nsrt *) a)->t[0]) < *(Oid*)&(((Nsrt *) b)->t[0]) ){
- return -1;
- }
- return 0;
+ if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
+ return 1;
+ else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_oid,
- sizeof(Oid),
- gbt_oidgt,
- gbt_oidge,
- gbt_oideq,
- gbt_oidle,
- gbt_oidlt,
- gbt_oidkey_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_oid,
+ sizeof(Oid),
+ gbt_oidgt,
+ gbt_oidge,
+ gbt_oideq,
+ gbt_oidle,
+ gbt_oidlt,
+ gbt_oidkey_cmp
};
@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum
gbt_oid_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
@@ -92,69 +96,72 @@ Datum
gbt_oid_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- Oid query = PG_GETARG_OID(1);
- oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ Oid query = PG_GETARG_OID(1);
+ oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_oid_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(oidKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(oidKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_oid_penalty(PG_FUNCTION_ARGS)
{
- oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+
+ Oid res = 0;
- Oid res = 0 ;
+ *result = 0.0;
- *result = 0.0;
-
- penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower , newentry->upper );
+ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- if ( res > 0 ){
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- }
+ if (res > 0)
+ {
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
Datum
gbt_oid_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_oid_same(PG_FUNCTION_ARGS)
{
- oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
- oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
+ oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index fac9f554c0f..d2603e1d911 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -14,95 +14,102 @@ PG_FUNCTION_INFO_V1(gbt_bpchar_consistent);
PG_FUNCTION_INFO_V1(gbt_text_penalty);
PG_FUNCTION_INFO_V1(gbt_text_same);
-Datum gbt_text_compress(PG_FUNCTION_ARGS);
-Datum gbt_bpchar_compress(PG_FUNCTION_ARGS);
-Datum gbt_text_union(PG_FUNCTION_ARGS);
-Datum gbt_text_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_text_consistent(PG_FUNCTION_ARGS);
-Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS);
-Datum gbt_text_penalty(PG_FUNCTION_ARGS);
-Datum gbt_text_same(PG_FUNCTION_ARGS);
+Datum gbt_text_compress(PG_FUNCTION_ARGS);
+Datum gbt_bpchar_compress(PG_FUNCTION_ARGS);
+Datum gbt_text_union(PG_FUNCTION_ARGS);
+Datum gbt_text_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_text_consistent(PG_FUNCTION_ARGS);
+Datum gbt_bpchar_consistent(PG_FUNCTION_ARGS);
+Datum gbt_text_penalty(PG_FUNCTION_ARGS);
+Datum gbt_text_same(PG_FUNCTION_ARGS);
/* define for comparison */
-static bool gbt_textgt (const void *a, const void *b)
+static bool
+gbt_textgt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( text_gt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(text_gt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_textge (const void *a, const void *b)
+static bool
+gbt_textge(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( text_ge ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(text_ge, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_texteq (const void *a, const void *b)
+static bool
+gbt_texteq(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( texteq ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(texteq, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_textle (const void *a, const void *b)
+static bool
+gbt_textle(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( text_le ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(text_le, PointerGetDatum(a), PointerGetDatum(b))));
}
-static bool gbt_textlt (const void *a, const void *b)
+static bool
+gbt_textlt(const void *a, const void *b)
{
- return ( DatumGetBool(DirectFunctionCall2( text_lt ,PointerGetDatum( a ),PointerGetDatum( b ) ) ) );
+ return (DatumGetBool(DirectFunctionCall2(text_lt, PointerGetDatum(a), PointerGetDatum(b))));
}
-static int32 gbt_textcmp ( const bytea * a , const bytea * b )
+static int32
+gbt_textcmp(const bytea *a, const bytea *b)
{
- return strcmp( VARDATA(a), VARDATA(b) );
+ return strcmp(VARDATA(a), VARDATA(b));
}
-
+
/*
* Converts data of leaf using strxfrm ( locale support )
*/
static bytea *
-gbt_text_xfrm ( bytea * leaf )
+gbt_text_xfrm(bytea *leaf)
{
- bytea * out = leaf;
- int32 ilen = VARSIZE (leaf) - VARHDRSZ;
- int32 olen ;
- char * sin;
- char * sou;
+ bytea *out = leaf;
+ int32 ilen = VARSIZE(leaf) - VARHDRSZ;
+ int32 olen;
+ char *sin;
+ char *sou;
sin = palloc(ilen + 1);
- memcpy (sin, (void*) VARDATA(leaf) ,ilen );
- sin[ilen] = '\0';
-
- olen = strxfrm ( NULL, &sin[0], 0 ) + 1;
- sou = palloc ( olen );
- olen = strxfrm ( sou , &sin[0] , olen );
- olen += VARHDRSZ;
- out = palloc ( olen + 1 );
- out->vl_len = olen+1;
- memcpy( (void*) VARDATA(out), sou, olen-VARHDRSZ );
- ((char*)out)[olen] = '\0';
-
- pfree(sou);
- pfree(sin);
-
- return out;
+ memcpy(sin, (void *) VARDATA(leaf), ilen);
+ sin[ilen] = '\0';
+
+ olen = strxfrm(NULL, &sin[0], 0) + 1;
+ sou = palloc(olen);
+ olen = strxfrm(sou, &sin[0], olen);
+ olen += VARHDRSZ;
+ out = palloc(olen + 1);
+ out->vl_len = olen + 1;
+ memcpy((void *) VARDATA(out), sou, olen - VARHDRSZ);
+ ((char *) out)[olen] = '\0';
+
+ pfree(sou);
+ pfree(sin);
+
+ return out;
}
-static GBT_VARKEY * gbt_text_l2n ( GBT_VARKEY * leaf )
+static GBT_VARKEY *
+gbt_text_l2n(GBT_VARKEY * leaf)
{
-
- GBT_VARKEY *out = leaf ;
- GBT_VARKEY_R r = gbt_var_key_readable ( leaf );
- bytea * o ;
- o = gbt_text_xfrm ( r.lower );
- r.lower = r.upper = o;
- out = gbt_var_key_copy ( &r , TRUE );
- pfree(o);
+ GBT_VARKEY *out = leaf;
+ GBT_VARKEY_R r = gbt_var_key_readable(leaf);
+ bytea *o;
+
+ o = gbt_text_xfrm(r.lower);
+ r.lower = r.upper = o;
+ out = gbt_var_key_copy(&r, TRUE);
+ pfree(o);
- return out;
+ return out;
}
@@ -112,16 +119,16 @@ static GBT_VARKEY * gbt_text_l2n ( GBT_VARKEY * leaf )
static const gbtree_vinfo tinfo =
{
- gbt_t_text,
- TRUE,
- TRUE,
- gbt_textgt,
- gbt_textge,
- gbt_texteq,
- gbt_textle,
- gbt_textlt,
- gbt_textcmp,
- gbt_text_l2n
+ gbt_t_text,
+ TRUE,
+ TRUE,
+ gbt_textgt,
+ gbt_textge,
+ gbt_texteq,
+ gbt_textle,
+ gbt_textlt,
+ gbt_textcmp,
+ gbt_text_l2n
};
@@ -132,36 +139,38 @@ static const gbtree_vinfo tinfo =
Datum
-gbt_text_compress (PG_FUNCTION_ARGS)
+gbt_text_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+
+ PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
}
Datum
-gbt_bpchar_compress (PG_FUNCTION_ARGS)
+gbt_bpchar_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY * retval ;
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval;
- if (entry->leafkey)
- {
+ if (entry->leafkey)
+ {
- Datum d = DirectFunctionCall1 ( rtrim1, entry->key );
- GISTENTRY * trim = palloc(sizeof(GISTENTRY));
+ Datum d = DirectFunctionCall1(rtrim1, entry->key);
+ GISTENTRY *trim = palloc(sizeof(GISTENTRY));
- gistentryinit(*trim, d ,
- entry->rel, entry->page,
- entry->offset, VARSIZE(DatumGetPointer(d)), TRUE);
- retval = gbt_var_compress( trim , &tinfo ) ;
+ gistentryinit(*trim, d,
+ entry->rel, entry->page,
+ entry->offset, VARSIZE(DatumGetPointer(d)), TRUE);
+ retval = gbt_var_compress(trim, &tinfo);
- pfree ( trim );
- pfree ( DatumGetPointer(d) );
- } else
- retval = entry;
+ pfree(trim);
+ pfree(DatumGetPointer(d));
+ }
+ else
+ retval = entry;
- PG_RETURN_POINTER ( retval );
+ PG_RETURN_POINTER(retval);
}
@@ -169,68 +178,66 @@ gbt_bpchar_compress (PG_FUNCTION_ARGS)
Datum
gbt_text_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
- void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) );
- void *query = ( void * ) DatumGetTextP ( PG_GETARG_DATUM(1) );
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool retval = FALSE;
- GBT_VARKEY_R r = gbt_var_key_readable ( key );
-
- if ( GIST_LEAF(entry) )
- {
- retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo );
- } else {
- bytea * q = gbt_text_xfrm ( ( bytea * ) query );
- retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
- if ( q != query )
- pfree(q);
- }
-
- if ( ktst != key ){
- pfree ( key );
- }
- if ( qtst != query ){
- pfree ( query );
- }
-
- PG_RETURN_BOOL(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
+ void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool retval = FALSE;
+ GBT_VARKEY_R r = gbt_var_key_readable(key);
+
+ if (GIST_LEAF(entry))
+ retval = gbt_var_consistent(&r, query, &strategy, TRUE, &tinfo);
+ else
+ {
+ bytea *q = gbt_text_xfrm((bytea *) query);
+
+ retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
+ if (q != query)
+ pfree(q);
+ }
+
+ if (ktst != key)
+ pfree(key);
+ if (qtst != query)
+ pfree(query);
+
+ PG_RETURN_BOOL(retval);
}
Datum
gbt_bpchar_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ;
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) );
- void *qtst = ( void * ) DatumGetPointer ( PG_GETARG_DATUM(1) );
- void *query = ( void * ) DatumGetPointer (PG_DETOAST_DATUM( PG_GETARG_DATUM(1) ) );
- void *trim = ( void * ) DatumGetPointer ( DirectFunctionCall1 ( rtrim1, PointerGetDatum ( query ) ) ) ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- bool retval = FALSE;
- GBT_VARKEY_R r = gbt_var_key_readable ( key );
-
- if ( GIST_LEAF(entry) )
- {
- retval = gbt_var_consistent( &r, trim , &strategy, TRUE, &tinfo );
- } else {
- bytea * q = gbt_text_xfrm ( ( bytea * ) trim );
- retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
- if ( q != trim )
- pfree(q);
- }
-
- pfree(trim);
-
- if ( ktst != key ){
- pfree ( key );
- }
- if ( qtst != query ){
- pfree ( query );
- }
- PG_RETURN_BOOL(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
+ void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
+ void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ bool retval = FALSE;
+ GBT_VARKEY_R r = gbt_var_key_readable(key);
+
+ if (GIST_LEAF(entry))
+ retval = gbt_var_consistent(&r, trim, &strategy, TRUE, &tinfo);
+ else
+ {
+ bytea *q = gbt_text_xfrm((bytea *) trim);
+
+ retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
+ if (q != trim)
+ pfree(q);
+ }
+
+ pfree(trim);
+
+ if (ktst != key)
+ pfree(key);
+ if (qtst != query)
+ pfree(query);
+ PG_RETURN_BOOL(retval);
}
@@ -239,37 +246,40 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS)
Datum
gbt_text_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- int32 *size = (int *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ int32 *size = (int *) PG_GETARG_POINTER(1);
+
+ PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
}
-
+
Datum
gbt_text_picksplit(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
- gbt_var_picksplit ( entryvec, v, &tinfo );
- PG_RETURN_POINTER(v);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
+
+ gbt_var_picksplit(entryvec, v, &tinfo);
+ PG_RETURN_POINTER(v);
}
Datum
gbt_text_same(PG_FUNCTION_ARGS)
{
- Datum d1 = PG_GETARG_DATUM(0);
- Datum d2 = PG_GETARG_DATUM(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
- PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
+ Datum d1 = PG_GETARG_DATUM(0);
+ Datum d2 = PG_GETARG_DATUM(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
+
+ PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
}
Datum
gbt_text_penalty(PG_FUNCTION_ARGS)
{
- float *result = (float *) PG_GETARG_POINTER(2);
- GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1);
- PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
-}
+ float *result = (float *) PG_GETARG_POINTER(2);
+ GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
+ PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
+}
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index 410bec0fe43..cbbe05dc271 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -4,9 +4,9 @@
typedef struct
{
- TimeADT lower;
- TimeADT upper;
-} timeKEY;
+ TimeADT lower;
+ TimeADT upper;
+} timeKEY;
/*
** time ops
@@ -20,49 +20,54 @@ PG_FUNCTION_INFO_V1(gbt_timetz_consistent);
PG_FUNCTION_INFO_V1(gbt_time_penalty);
PG_FUNCTION_INFO_V1(gbt_time_same);
-Datum gbt_time_compress(PG_FUNCTION_ARGS);
-Datum gbt_timetz_compress(PG_FUNCTION_ARGS);
-Datum gbt_time_union(PG_FUNCTION_ARGS);
-Datum gbt_time_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_time_consistent(PG_FUNCTION_ARGS);
-Datum gbt_timetz_consistent(PG_FUNCTION_ARGS);
-Datum gbt_time_penalty(PG_FUNCTION_ARGS);
-Datum gbt_time_same(PG_FUNCTION_ARGS);
+Datum gbt_time_compress(PG_FUNCTION_ARGS);
+Datum gbt_timetz_compress(PG_FUNCTION_ARGS);
+Datum gbt_time_union(PG_FUNCTION_ARGS);
+Datum gbt_time_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_time_consistent(PG_FUNCTION_ARGS);
+Datum gbt_timetz_consistent(PG_FUNCTION_ARGS);
+Datum gbt_time_penalty(PG_FUNCTION_ARGS);
+Datum gbt_time_same(PG_FUNCTION_ARGS);
-static bool gbt_timegt (const void *a, const void *b)
+static bool
+gbt_timegt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(time_gt,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(time_gt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
+ );
}
-static bool gbt_timege (const void *a, const void *b)
+static bool
+gbt_timege(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(time_ge,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(time_ge, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
+ );
}
-static bool gbt_timeeq (const void *a, const void *b)
+static bool
+gbt_timeeq(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(time_eq,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(time_eq, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
+ );
}
-static bool gbt_timele (const void *a, const void *b)
+static bool
+gbt_timele(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(time_le,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(time_le, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
+ );
}
-static bool gbt_timelt (const void *a, const void *b)
+static bool
+gbt_timelt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(time_lt,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(time_lt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
+ );
}
@@ -70,26 +75,24 @@ static bool gbt_timelt (const void *a, const void *b)
static int
gbt_timekey_cmp(const void *a, const void *b)
{
- if ( gbt_timegt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return 1;
- } else
- if ( gbt_timelt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return -1;
- }
- return 0;
+ if (gbt_timegt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return 1;
+ else if (gbt_timelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
+static const gbtree_ninfo tinfo =
{
- gbt_t_time,
- sizeof(TimeADT),
- gbt_timegt,
- gbt_timege,
- gbt_timeeq,
- gbt_timele,
- gbt_timelt,
- gbt_timekey_cmp
+ gbt_t_time,
+ sizeof(TimeADT),
+ gbt_timegt,
+ gbt_timege,
+ gbt_timeeq,
+ gbt_timele,
+ gbt_timelt,
+ gbt_timekey_cmp
};
@@ -102,150 +105,154 @@ static const gbtree_ninfo tinfo =
Datum
gbt_time_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_timetz_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval;
-
- if (entry->leafkey)
- {
- timeKEY *r = (timeKEY *) palloc(sizeof(timeKEY));
- TimeTzADT *tz = DatumGetTimeTzADTP(entry->key);
-
- retval = palloc(sizeof(GISTENTRY));
-
- /* We are using the time + zone only to compress */
- r->lower = r->upper = ( tz->time + tz->zone ) ;
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, sizeof(timeKEY), FALSE);
- }
- else
- retval = entry;
- PG_RETURN_POINTER(retval);
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval;
+
+ if (entry->leafkey)
+ {
+ timeKEY *r = (timeKEY *) palloc(sizeof(timeKEY));
+ TimeTzADT *tz = DatumGetTimeTzADTP(entry->key);
+
+ retval = palloc(sizeof(GISTENTRY));
+
+ /* We are using the time + zone only to compress */
+ r->lower = r->upper = (tz->time + tz->zone);
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, sizeof(timeKEY), FALSE);
+ }
+ else
+ retval = entry;
+ PG_RETURN_POINTER(retval);
}
Datum
gbt_time_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- TimeADT query = PG_GETARG_TIMEADT( 1 );
- timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
-
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ TimeADT query = PG_GETARG_TIMEADT(1);
+ timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_timetz_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- TimeTzADT *query = PG_GETARG_TIMETZADT_P( 1 );
- TimeADT qqq = query->time + query->zone ;
- timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
-
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&qqq, &strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ TimeTzADT *query = PG_GETARG_TIMETZADT_P(1);
+ TimeADT qqq = query->time + query->zone;
+ timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_time_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(timeKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(timeKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
Datum
gbt_time_penalty(PG_FUNCTION_ARGS)
{
- timeKEY *origentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- Interval *intr;
+ timeKEY *origentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ Interval *intr;
+
#ifdef HAVE_INT64_TIMESTAMP
- int64 res;
+ int64 res;
+
#else
- double res;
+ double res;
#endif
- intr = DatumGetIntervalP(DirectFunctionCall2(
- time_mi_time,
- TimeADTGetDatum(newentry->upper),
- TimeADTGetDatum(origentry->upper)));
-
- /* see interval_larger */
- res = Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
-
- intr = DatumGetIntervalP(DirectFunctionCall2(
- time_mi_time,
- TimeADTGetDatum(origentry->lower),
- TimeADTGetDatum(newentry->lower)));
-
- /* see interval_larger */
- res += Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
-
- *result = 0.0;
-
- if ( res > 0 ){
- intr = DatumGetIntervalP(DirectFunctionCall2(
- time_mi_time,
- TimeADTGetDatum(origentry->upper),
- TimeADTGetDatum(origentry->lower)));
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + intr->time + intr->month * (30 * 86400) ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- pfree ( intr );
- }
-
- PG_RETURN_POINTER(result);
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ time_mi_time,
+ TimeADTGetDatum(newentry->upper),
+ TimeADTGetDatum(origentry->upper)));
+
+ /* see interval_larger */
+ res = Max(intr->time + intr->month * (30 * 86400), 0);
+ pfree(intr);
+
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ time_mi_time,
+ TimeADTGetDatum(origentry->lower),
+ TimeADTGetDatum(newentry->lower)));
+
+ /* see interval_larger */
+ res += Max(intr->time + intr->month * (30 * 86400), 0);
+ pfree(intr);
+
+ *result = 0.0;
+
+ if (res > 0)
+ {
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ time_mi_time,
+ TimeADTGetDatum(origentry->upper),
+ TimeADTGetDatum(origentry->lower)));
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ pfree(intr);
+ }
+
+ PG_RETURN_POINTER(result);
}
Datum
gbt_time_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_time_same(PG_FUNCTION_ARGS)
{
- timeKEY *b1 = (timeKEY *) PG_GETARG_POINTER(0);
- timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ timeKEY *b1 = (timeKEY *) PG_GETARG_POINTER(0);
+ timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 97f209ed74a..f9d801a3fc1 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -3,9 +3,9 @@
typedef struct
{
- Timestamp lower;
- Timestamp upper;
-} tsKEY;
+ Timestamp lower;
+ Timestamp upper;
+} tsKEY;
/*
** timestamp ops
@@ -19,75 +19,78 @@ PG_FUNCTION_INFO_V1(gbt_tstz_consistent);
PG_FUNCTION_INFO_V1(gbt_ts_penalty);
PG_FUNCTION_INFO_V1(gbt_ts_same);
-Datum gbt_ts_compress(PG_FUNCTION_ARGS);
-Datum gbt_tstz_compress(PG_FUNCTION_ARGS);
-Datum gbt_ts_union(PG_FUNCTION_ARGS);
-Datum gbt_ts_picksplit(PG_FUNCTION_ARGS);
-Datum gbt_ts_consistent(PG_FUNCTION_ARGS);
-Datum gbt_tstz_consistent(PG_FUNCTION_ARGS);
-Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
-Datum gbt_ts_same(PG_FUNCTION_ARGS);
+Datum gbt_ts_compress(PG_FUNCTION_ARGS);
+Datum gbt_tstz_compress(PG_FUNCTION_ARGS);
+Datum gbt_ts_union(PG_FUNCTION_ARGS);
+Datum gbt_ts_picksplit(PG_FUNCTION_ARGS);
+Datum gbt_ts_consistent(PG_FUNCTION_ARGS);
+Datum gbt_tstz_consistent(PG_FUNCTION_ARGS);
+Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
+Datum gbt_ts_same(PG_FUNCTION_ARGS);
-static bool gbt_tsgt (const void *a, const void *b)
+static bool
+gbt_tsgt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(timestamp_gt,PointerGetDatum( a ), PointerGetDatum( b ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(timestamp_gt, PointerGetDatum(a), PointerGetDatum(b))
+ );
}
-static bool gbt_tsge (const void *a, const void *b)
+static bool
+gbt_tsge(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(timestamp_ge,PointerGetDatum( a ), PointerGetDatum( b ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(timestamp_ge, PointerGetDatum(a), PointerGetDatum(b))
+ );
}
-static bool gbt_tseq (const void *a, const void *b)
+static bool
+gbt_tseq(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(timestamp_eq,PointerGetDatum( a ), PointerGetDatum( b ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(timestamp_eq, PointerGetDatum(a), PointerGetDatum(b))
+ );
}
-static bool gbt_tsle (const void *a, const void *b)
+static bool
+gbt_tsle(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(timestamp_le,PointerGetDatum( a ), PointerGetDatum( b ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(timestamp_le, PointerGetDatum(a), PointerGetDatum(b))
+ );
}
-static bool gbt_tslt (const void *a, const void *b)
+static bool
+gbt_tslt(const void *a, const void *b)
{
- return DatumGetBool(
- DirectFunctionCall2(timestamp_lt,PointerGetDatum( a ), PointerGetDatum( b ) )
- );
+ return DatumGetBool(
+ DirectFunctionCall2(timestamp_lt, PointerGetDatum(a), PointerGetDatum(b))
+ );
}
static int
gbt_tskey_cmp(const void *a, const void *b)
{
- if ( gbt_tsgt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return 1;
- } else
- if ( gbt_tslt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
- return -1;
- }
- return 0;
+ if (gbt_tsgt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return 1;
+ else if (gbt_tslt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
+ return -1;
+ return 0;
}
-static const gbtree_ninfo tinfo =
-{
- gbt_t_ts,
- sizeof(Timestamp),
- gbt_tsgt,
- gbt_tsge,
- gbt_tseq,
- gbt_tsle,
- gbt_tslt,
- gbt_tskey_cmp
+static const gbtree_ninfo tinfo =
+{
+ gbt_t_ts,
+ sizeof(Timestamp),
+ gbt_tsgt,
+ gbt_tsge,
+ gbt_tseq,
+ gbt_tsle,
+ gbt_tslt,
+ gbt_tskey_cmp
};
@@ -97,26 +100,28 @@ static const gbtree_ninfo tinfo =
-static Timestamp * tstz_to_ts_gmt ( Timestamp * gmt, TimestampTz * ts )
+static Timestamp *
+tstz_to_ts_gmt(Timestamp *gmt, TimestampTz *ts)
{
- int val, tz ;
+ int val,
+ tz;
+
+ *gmt = *ts;
+ DecodeSpecial(0, "gmt", &val);
- *gmt = *ts;
- DecodeSpecial(0, "gmt", &val);
-
- if ( ! TIMESTAMP_NOT_FINITE(*ts))
- {
- tz = val * 60;
+ if (!TIMESTAMP_NOT_FINITE(*ts))
+ {
+ tz = val * 60;
#ifdef HAVE_INT64_TIMESTAMP
- *gmt -= (tz * INT64CONST(1000000));
+ *gmt -= (tz * INT64CONST(1000000));
#else
- *gmt -= tz;
- *gmt = JROUND(*gmt);
+ *gmt -= tz;
+ *gmt = JROUND(*gmt);
#endif
-
- }
- return gmt;
+
+ }
+ return gmt;
}
@@ -125,84 +130,86 @@ static Timestamp * tstz_to_ts_gmt ( Timestamp * gmt, TimestampTz * ts )
Datum
gbt_ts_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = NULL;
+
+ PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}
Datum
gbt_tstz_compress(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval ;
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval;
- if (entry->leafkey)
- {
- tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY));
+ if (entry->leafkey)
+ {
+ tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY));
- TimestampTz ts = *(TimestampTz *) DatumGetPointer(entry->key);
- Timestamp gmt ;
+ TimestampTz ts = *(TimestampTz *) DatumGetPointer(entry->key);
+ Timestamp gmt;
- tstz_to_ts_gmt ( &gmt, &ts );
+ tstz_to_ts_gmt(&gmt, &ts);
- retval = palloc(sizeof(GISTENTRY));
- r->lower = r->upper = gmt ;
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, sizeof(tsKEY), FALSE);
- }
- else
- retval = entry;
+ retval = palloc(sizeof(GISTENTRY));
+ r->lower = r->upper = gmt;
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, sizeof(tsKEY), FALSE);
+ }
+ else
+ retval = entry;
- PG_RETURN_POINTER( retval );
+ PG_RETURN_POINTER(retval);
}
Datum
gbt_ts_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- Timestamp *query = (Timestamp *) PG_GETARG_POINTER(1);
- tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
-
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)query,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ Timestamp *query = (Timestamp *) PG_GETARG_POINTER(1);
+ tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
+ key.lower = (GBT_NUMKEY *) & kkk->lower;
+ key.upper = (GBT_NUMKEY *) & kkk->upper;
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_tstz_consistent(PG_FUNCTION_ARGS)
{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- TimestampTz *query = (Timestamp *) PG_GETARG_POINTER(1);
- char *kkk = (char *) DatumGetPointer(entry->key);
- GBT_NUMKEY_R key ;
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- Timestamp qqq ;
-
- key.lower = (GBT_NUMKEY*) &kkk[0];
- key.upper = (GBT_NUMKEY*) &kkk[MAXALIGN(tinfo.size)];
- tstz_to_ts_gmt ( &qqq, query );
-
- PG_RETURN_BOOL(
- gbt_num_consistent( &key, (void*)&qqq,&strategy,GIST_LEAF(entry),&tinfo)
- );
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ TimestampTz *query = (Timestamp *) PG_GETARG_POINTER(1);
+ char *kkk = (char *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ Timestamp qqq;
+
+ key.lower = (GBT_NUMKEY *) & kkk[0];
+ key.upper = (GBT_NUMKEY *) & kkk[MAXALIGN(tinfo.size)];
+ tstz_to_ts_gmt(&qqq, query);
+
+ PG_RETURN_BOOL(
+ gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
+ );
}
Datum
gbt_ts_union(PG_FUNCTION_ARGS)
{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- void *out = palloc(sizeof(tsKEY));
- *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
- PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) );
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ void *out = palloc(sizeof(tsKEY));
+
+ *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
+ PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}
@@ -210,52 +217,55 @@ Datum
gbt_ts_penalty(PG_FUNCTION_ARGS)
{
- tsKEY *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- Interval *intr;
+ tsKEY *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+ tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+ Interval *intr;
+
#ifdef HAVE_INT64_TIMESTAMP
- int64 res;
+ int64 res;
+
#else
- double res;
+ double res;
#endif
- intr = DatumGetIntervalP(DirectFunctionCall2(
- timestamp_mi,
- TimestampGetDatum(newentry->upper),
- TimestampGetDatum(origentry->upper)
- ));
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ timestamp_mi,
+ TimestampGetDatum(newentry->upper),
+ TimestampGetDatum(origentry->upper)
+ ));
- /* see interval_larger */
+ /* see interval_larger */
- res = Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
+ res = Max(intr->time + intr->month * (30 * 86400), 0);
+ pfree(intr);
- intr = DatumGetIntervalP(DirectFunctionCall2(
- timestamp_mi,
- TimestampGetDatum(origentry->lower),
- TimestampGetDatum(newentry->lower)
- ));
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ timestamp_mi,
+ TimestampGetDatum(origentry->lower),
+ TimestampGetDatum(newentry->lower)
+ ));
- /* see interval_larger */
- res += Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
+ /* see interval_larger */
+ res += Max(intr->time + intr->month * (30 * 86400), 0);
+ pfree(intr);
- *result = 0.0;
+ *result = 0.0;
- if ( res > 0 ){
- intr = DatumGetIntervalP(DirectFunctionCall2(
- timestamp_mi,
- TimestampGetDatum(origentry->upper),
- TimestampGetDatum(origentry->lower)
- ));
- *result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + intr->time + intr->month * (30 * 86400) ) ) );
- *result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
- pfree(intr);
- }
+ if (res > 0)
+ {
+ intr = DatumGetIntervalP(DirectFunctionCall2(
+ timestamp_mi,
+ TimestampGetDatum(origentry->upper),
+ TimestampGetDatum(origentry->lower)
+ ));
+ *result += FLT_MIN;
+ *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
+ *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
+ pfree(intr);
+ }
- PG_RETURN_POINTER(result);
+ PG_RETURN_POINTER(result);
}
@@ -263,21 +273,20 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
Datum
gbt_ts_picksplit(PG_FUNCTION_ARGS)
{
- PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
- &tinfo
- ));
+ PG_RETURN_POINTER(gbt_num_picksplit(
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ &tinfo
+ ));
}
Datum
gbt_ts_same(PG_FUNCTION_ARGS)
{
- tsKEY *b1 = (tsKEY *) PG_GETARG_POINTER(0);
- tsKEY *b2 = (tsKEY *) PG_GETARG_POINTER(1);
- bool *result = (bool *) PG_GETARG_POINTER(2);
+ tsKEY *b1 = (tsKEY *) PG_GETARG_POINTER(0);
+ tsKEY *b2 = (tsKEY *) PG_GETARG_POINTER(1);
+ bool *result = (bool *) PG_GETARG_POINTER(2);
- *result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo );
- PG_RETURN_POINTER(result);
+ *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
+ PG_RETURN_POINTER(result);
}
-
diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c
index bc104de96b3..f5244274245 100644
--- a/contrib/btree_gist/btree_utils_num.c
+++ b/contrib/btree_gist/btree_utils_num.c
@@ -3,58 +3,60 @@
#include "utils/date.h"
extern GISTENTRY *
-gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry , const gbtree_ninfo * tinfo )
+gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo * tinfo)
{
- if (entry->leafkey)
- {
-
- union {
- int16 i2;
- int32 i4;
- TimeADT ts;
- DateADT dt;
- } v ;
-
- GBT_NUMKEY *r = ( GBT_NUMKEY * ) palloc(2 * tinfo->size );
- void *leaf = NULL;
-
- switch ( tinfo->t )
- {
- case gbt_t_int2 :
- v.i2 = DatumGetInt16(entry->key);
- leaf = &v.i2;
- break;
- case gbt_t_int4 :
- v.i4 = DatumGetInt32(entry->key);
- leaf = &v.i4;
- break;
- case gbt_t_oid :
- v.i4 = DatumGetObjectId(entry->key);
- leaf = &v.i4;
- break;
- case gbt_t_time :
- v.ts = DatumGetTimeADT(entry->key);
- leaf = &v.ts;
- break;
- case gbt_t_date :
- v.dt = DatumGetDateADT(entry->key);
- leaf = &v.dt;
- break;
- default :
- leaf = DatumGetPointer(entry->key);
- }
-
- memset ( (void*) &r[0] , 0 , 2*tinfo->size );
- memcpy ( (void*) &r[0] , leaf, tinfo->size );
- memcpy ( (void*) &r[tinfo->size] , leaf, tinfo->size );
- retval = palloc(sizeof(GISTENTRY));
- gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
- entry->offset,( 2 * tinfo->size ), FALSE);
- } else
- retval = entry;
-
- return retval;
+ if (entry->leafkey)
+ {
+
+ union
+ {
+ int16 i2;
+ int32 i4;
+ TimeADT ts;
+ DateADT dt;
+ } v;
+
+ GBT_NUMKEY *r = (GBT_NUMKEY *) palloc(2 * tinfo->size);
+ void *leaf = NULL;
+
+ switch (tinfo->t)
+ {
+ case gbt_t_int2:
+ v.i2 = DatumGetInt16(entry->key);
+ leaf = &v.i2;
+ break;
+ case gbt_t_int4:
+ v.i4 = DatumGetInt32(entry->key);
+ leaf = &v.i4;
+ break;
+ case gbt_t_oid:
+ v.i4 = DatumGetObjectId(entry->key);
+ leaf = &v.i4;
+ break;
+ case gbt_t_time:
+ v.ts = DatumGetTimeADT(entry->key);
+ leaf = &v.ts;
+ break;
+ case gbt_t_date:
+ v.dt = DatumGetDateADT(entry->key);
+ leaf = &v.dt;
+ break;
+ default:
+ leaf = DatumGetPointer(entry->key);
+ }
+
+ memset((void *) &r[0], 0, 2 * tinfo->size);
+ memcpy((void *) &r[0], leaf, tinfo->size);
+ memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
+ retval = palloc(sizeof(GISTENTRY));
+ gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
+ entry->offset, (2 * tinfo->size), FALSE);
+ }
+ else
+ retval = entry;
+
+ return retval;
}
@@ -65,34 +67,35 @@ gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry , const gbtree_ninfo *
*/
extern void *
-gbt_num_union( GBT_NUMKEY * out, const GistEntryVector * entryvec, const gbtree_ninfo * tinfo )
+gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec, const gbtree_ninfo * tinfo)
{
- int i,
- numranges;
- GBT_NUMKEY * cur ;
- GBT_NUMKEY_R o, c;
+ int i,
+ numranges;
+ GBT_NUMKEY *cur;
+ GBT_NUMKEY_R o,
+ c;
- numranges = entryvec->n;
- cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
+ numranges = entryvec->n;
+ cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
- o.lower = &((GBT_NUMKEY *)out)[0];
- o.upper = &((GBT_NUMKEY *)out)[tinfo->size];
+ o.lower = &((GBT_NUMKEY *) out)[0];
+ o.upper = &((GBT_NUMKEY *) out)[tinfo->size];
- memcpy( (void*)out, (void*) cur, 2*tinfo->size );
+ memcpy((void *) out, (void *) cur, 2 * tinfo->size);
- for (i = 1; i < numranges; i++)
- {
- cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
- c.lower = &cur[0];
- c.upper = &cur[tinfo->size];
- if ( (*tinfo->f_gt)(o.lower, c.lower) ) /* out->lower > cur->lower */
- memcpy( (void* ) o.lower, (void*) c.lower, tinfo->size );
- if ( (*tinfo->f_lt)(o.upper, c.upper) ) /* out->upper < cur->upper */
- memcpy( (void*) o.upper, (void*) c.upper, tinfo->size );
- }
+ for (i = 1; i < numranges; i++)
+ {
+ cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
+ c.lower = &cur[0];
+ c.upper = &cur[tinfo->size];
+ if ((*tinfo->f_gt) (o.lower, c.lower)) /* out->lower > cur->lower */
+ memcpy((void *) o.lower, (void *) c.lower, tinfo->size);
+ if ((*tinfo->f_lt) (o.upper, c.upper)) /* out->upper < cur->upper */
+ memcpy((void *) o.upper, (void *) c.upper, tinfo->size);
+ }
- return out;
+ return out;
}
@@ -101,51 +104,54 @@ gbt_num_union( GBT_NUMKEY * out, const GistEntryVector * entryvec, const gbtree_
** The GiST same method for numerical values
*/
-extern bool gbt_num_same ( const GBT_NUMKEY * a, const GBT_NUMKEY * b, const gbtree_ninfo * tinfo )
+extern bool
+gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b, const gbtree_ninfo * tinfo)
{
- GBT_NUMKEY_R b1, b2 ;
+ GBT_NUMKEY_R b1,
+ b2;
- b1.lower = &(((GBT_NUMKEY *)a)[0]);
- b1.upper = &(((GBT_NUMKEY *)a)[tinfo->size]);
- b2.lower = &(((GBT_NUMKEY *)b)[0]);
- b2.upper = &(((GBT_NUMKEY *)b)[tinfo->size]);
+ b1.lower = &(((GBT_NUMKEY *) a)[0]);
+ b1.upper = &(((GBT_NUMKEY *) a)[tinfo->size]);
+ b2.lower = &(((GBT_NUMKEY *) b)[0]);
+ b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
+
+ if (
+ (*tinfo->f_eq) (b1.lower, b2.lower) &&
+ (*tinfo->f_eq) (b1.upper, b2.upper)
+ )
+ return TRUE;
+ return FALSE;
- if (
- (*tinfo->f_eq)( b1.lower, b2.lower) &&
- (*tinfo->f_eq)( b1.upper, b2.upper)
- )
- return TRUE;
- return FALSE;
-
}
extern void
-gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo )
+gbt_num_bin_union(Datum *u, GBT_NUMKEY * e, const gbtree_ninfo * tinfo)
{
- GBT_NUMKEY_R rd;
-
- rd.lower = &e[0];
- rd.upper = &e[tinfo->size];
-
- if (!DatumGetPointer(*u))
- {
- *u = PointerGetDatum(palloc(2 * tinfo->size));
- memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) , (void*)rd.lower , tinfo->size );
- memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[tinfo->size]) , (void*)rd.upper , tinfo->size );
- }
- else
- {
- GBT_NUMKEY_R ur ;
- ur.lower = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) ;
- ur.upper = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[tinfo->size]) ;
- if ( (*tinfo->f_gt)((void*)ur.lower, (void*)rd.lower) )
- memcpy( (void*) ur.lower, (void*) rd.lower, tinfo->size );
- if ( (*tinfo->f_lt)((void*)ur.upper, (void*)rd.upper) )
- memcpy( (void*) ur.upper, (void*) rd.upper, tinfo->size );
- }
+ GBT_NUMKEY_R rd;
+
+ rd.lower = &e[0];
+ rd.upper = &e[tinfo->size];
+
+ if (!DatumGetPointer(*u))
+ {
+ *u = PointerGetDatum(palloc(2 * tinfo->size));
+ memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]), (void *) rd.lower, tinfo->size);
+ memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]), (void *) rd.upper, tinfo->size);
+ }
+ else
+ {
+ GBT_NUMKEY_R ur;
+
+ ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]);
+ ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]);
+ if ((*tinfo->f_gt) ((void *) ur.lower, (void *) rd.lower))
+ memcpy((void *) ur.lower, (void *) rd.lower, tinfo->size);
+ if ((*tinfo->f_lt) ((void *) ur.upper, (void *) rd.upper))
+ memcpy((void *) ur.upper, (void *) rd.upper, tinfo->size);
+ }
}
@@ -154,98 +160,98 @@ gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo )
** The GiST consistent method
*/
-extern bool
+extern bool
gbt_num_consistent(
- const GBT_NUMKEY_R * key,
- const void * query,
- const StrategyNumber * strategy,
- bool is_leaf,
- const gbtree_ninfo * tinfo
+ const GBT_NUMKEY_R * key,
+ const void *query,
+ const StrategyNumber *strategy,
+ bool is_leaf,
+ const gbtree_ninfo * tinfo
)
{
- bool retval = FALSE;
-
- switch (*strategy)
- {
- case BTLessEqualStrategyNumber:
- retval = (*tinfo->f_ge)(query, key->lower);
- break;
- case BTLessStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_gt)(query, key->lower);
- else
- retval = (*tinfo->f_ge)(query, key->lower);
- break;
- case BTEqualStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_eq)(query, key->lower);
- else
- retval = (*tinfo->f_le)(key->lower, query) && (*tinfo->f_le)(query, key->upper );
- break;
- case BTGreaterStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_lt)(query, key->upper);
- else
- retval = (*tinfo->f_le)(query, key->upper);
- break;
- case BTGreaterEqualStrategyNumber:
- retval = (*tinfo->f_le)(query, key->upper);
- break;
- default:
- retval = FALSE;
- }
-
- return (retval);
+ bool retval = FALSE;
+
+ switch (*strategy)
+ {
+ case BTLessEqualStrategyNumber:
+ retval = (*tinfo->f_ge) (query, key->lower);
+ break;
+ case BTLessStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_gt) (query, key->lower);
+ else
+ retval = (*tinfo->f_ge) (query, key->lower);
+ break;
+ case BTEqualStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_eq) (query, key->lower);
+ else
+ retval = (*tinfo->f_le) (key->lower, query) && (*tinfo->f_le) (query, key->upper);
+ break;
+ case BTGreaterStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_lt) (query, key->upper);
+ else
+ retval = (*tinfo->f_le) (query, key->upper);
+ break;
+ case BTGreaterEqualStrategyNumber:
+ retval = (*tinfo->f_le) (query, key->upper);
+ break;
+ default:
+ retval = FALSE;
+ }
+
+ return (retval);
}
GIST_SPLITVEC *
-gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_ninfo * tinfo )
+gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
+ const gbtree_ninfo * tinfo)
{
- OffsetNumber i,
- maxoff = entryvec->n - 1;
- Nsrt *arr;
- int nbytes;
-
- arr = (Nsrt *) palloc((maxoff+1) * sizeof(Nsrt));
- nbytes = (maxoff + 2) * sizeof(OffsetNumber);
- v->spl_left = (OffsetNumber *) palloc(nbytes);
- v->spl_right = (OffsetNumber *) palloc(nbytes);
- v->spl_ldatum = PointerGetDatum(0);
- v->spl_rdatum = PointerGetDatum(0);
- v->spl_nleft = 0;
- v->spl_nright = 0;
-
- /* Sort entries */
-
- for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
- {
- arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
- arr[i].i = i;
- }
- qsort ( (void*) &arr[FirstOffsetNumber], maxoff-FirstOffsetNumber+1,sizeof(Nsrt), tinfo->f_cmp );
-
- /* We do simply create two parts */
-
- for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
- {
- if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
- {
- gbt_num_bin_union(&v->spl_ldatum, arr[i].t, tinfo);
- v->spl_left[v->spl_nleft] = arr[i].i;
- v->spl_nleft++;
- }
- else
- {
- gbt_num_bin_union(&v->spl_rdatum, arr[i].t, tinfo);
- v->spl_right[v->spl_nright] = arr[i].i;
- v->spl_nright++;
- }
- }
+ OffsetNumber i,
+ maxoff = entryvec->n - 1;
+ Nsrt *arr;
+ int nbytes;
+
+ arr = (Nsrt *) palloc((maxoff + 1) * sizeof(Nsrt));
+ nbytes = (maxoff + 2) * sizeof(OffsetNumber);
+ v->spl_left = (OffsetNumber *) palloc(nbytes);
+ v->spl_right = (OffsetNumber *) palloc(nbytes);
+ v->spl_ldatum = PointerGetDatum(0);
+ v->spl_rdatum = PointerGetDatum(0);
+ v->spl_nleft = 0;
+ v->spl_nright = 0;
+
+ /* Sort entries */
+
+ for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+ {
+ arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
+ arr[i].i = i;
+ }
+ qsort((void *) &arr[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, sizeof(Nsrt), tinfo->f_cmp);
+
+ /* We do simply create two parts */
+
+ for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+ {
+ if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
+ {
+ gbt_num_bin_union(&v->spl_ldatum, arr[i].t, tinfo);
+ v->spl_left[v->spl_nleft] = arr[i].i;
+ v->spl_nleft++;
+ }
+ else
+ {
+ gbt_num_bin_union(&v->spl_rdatum, arr[i].t, tinfo);
+ v->spl_right[v->spl_nright] = arr[i].i;
+ v->spl_nright++;
+ }
+ }
pfree(arr);
- return v;
+ return v;
}
diff --git a/contrib/btree_gist/btree_utils_num.h b/contrib/btree_gist/btree_utils_num.h
index 122fba379a1..714144f676e 100644
--- a/contrib/btree_gist/btree_utils_num.h
+++ b/contrib/btree_gist/btree_utils_num.h
@@ -4,16 +4,17 @@ typedef char GBT_NUMKEY;
/* Better readable key */
typedef struct
{
- const GBT_NUMKEY * lower, * upper;
-} GBT_NUMKEY_R;
+ const GBT_NUMKEY *lower,
+ *upper;
+} GBT_NUMKEY_R;
/* for sorting */
typedef struct
{
- int i;
- GBT_NUMKEY * t;
-} Nsrt;
+ int i;
+ GBT_NUMKEY *t;
+} Nsrt;
/* type description */
@@ -21,53 +22,53 @@ typedef struct
typedef struct
{
- /* Attribs */
+ /* Attribs */
- enum gbtree_type t ; /* data type */
- int32 size ; /* size of type , 0 means variable */
+ enum gbtree_type t; /* data type */
+ int32 size; /* size of type , 0 means variable */
- /* Methods */
+ /* Methods */
- bool (*f_gt) ( const void * , const void * ); /* greater then */
- bool (*f_ge) ( const void * , const void * ); /* greater equal */
- bool (*f_eq) ( const void * , const void * ); /* equal */
- bool (*f_le) ( const void * , const void * ); /* less equal */
- bool (*f_lt) ( const void * , const void * ); /* less then */
- int (*f_cmp) ( const void * , const void * ); /* key compare function */
-} gbtree_ninfo;
+ bool (*f_gt) (const void *, const void *); /* greater then */
+ bool (*f_ge) (const void *, const void *); /* greater equal */
+ bool (*f_eq) (const void *, const void *); /* equal */
+ bool (*f_le) (const void *, const void *); /* less equal */
+ bool (*f_lt) (const void *, const void *); /* less then */
+ int (*f_cmp) (const void *, const void *); /* key compare function */
+} gbtree_ninfo;
/*
- * Numeric btree functions
+ * Numeric btree functions
*/
#define penalty_range_enlarge(olower,oupper,nlower,nupper) do { \
res = 0; \
if ( (nupper) > (oupper) ) \
- res += ( (nupper) - (oupper) ); \
- if ( (olower) > (nlower) ) \
- res += ( (olower) - (nlower) ); \
+ res += ( (nupper) - (oupper) ); \
+ if ( (olower) > (nlower) ) \
+ res += ( (olower) - (nlower) ); \
} while (0);
-extern bool gbt_num_consistent( const GBT_NUMKEY_R * key , const void * query,
- const StrategyNumber * strategy , bool is_leaf,
- const gbtree_ninfo * tinfo );
+extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
+ const StrategyNumber *strategy, bool is_leaf,
+ const gbtree_ninfo * tinfo);
-extern GIST_SPLITVEC *gbt_num_picksplit ( const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_ninfo * tinfo );
+extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
+ const gbtree_ninfo * tinfo);
-extern GISTENTRY *gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry ,
- const gbtree_ninfo * tinfo );
+extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
+ const gbtree_ninfo * tinfo);
-extern void *gbt_num_union ( GBT_NUMKEY * out, const GistEntryVector * entryvec,
- const gbtree_ninfo * tinfo );
+extern void *gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec,
+ const gbtree_ninfo * tinfo);
-extern bool gbt_num_same ( const GBT_NUMKEY * a, const GBT_NUMKEY * b,
- const gbtree_ninfo * tinfo );
+extern bool gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b,
+ const gbtree_ninfo * tinfo);
-extern void gbt_num_bin_union(Datum * u , GBT_NUMKEY * e ,
- const gbtree_ninfo * tinfo );
+extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY * e,
+ const gbtree_ninfo * tinfo);
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index f8ced122267..01e29038163 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -4,52 +4,59 @@
/* Returns a better readable representaion of variable key ( sets pointer ) */
-extern GBT_VARKEY_R gbt_var_key_readable ( const GBT_VARKEY * k ){
-
- GBT_VARKEY_R r ;
- r.lower = ( bytea * ) &(((char*)k)[VARHDRSZ] ) ;
- if ( VARSIZE(k) > ( VARHDRSZ+(VARSIZE(r.lower)) ) )
- r.upper = ( bytea * ) &(((char*)k)[VARHDRSZ+INTALIGN(VARSIZE(r.lower))] ) ;
- else
- r.upper = r.lower;
- return r;
+extern GBT_VARKEY_R
+gbt_var_key_readable(const GBT_VARKEY * k)
+{
+
+ GBT_VARKEY_R r;
+
+ r.lower = (bytea *) &(((char *) k)[VARHDRSZ]);
+ if (VARSIZE(k) > (VARHDRSZ + (VARSIZE(r.lower))))
+ r.upper = (bytea *) &(((char *) k)[VARHDRSZ + INTALIGN(VARSIZE(r.lower))]);
+ else
+ r.upper = r.lower;
+ return r;
}
-extern GBT_VARKEY * gbt_var_key_copy ( const GBT_VARKEY_R * u , bool force_node ){
+extern GBT_VARKEY *
+gbt_var_key_copy(const GBT_VARKEY_R * u, bool force_node)
+{
- GBT_VARKEY * r = NULL;
+ GBT_VARKEY *r = NULL;
- if ( u->lower == u->upper && !force_node ){ /* leaf key mode */
+ if (u->lower == u->upper && !force_node)
+ { /* leaf key mode */
- r = (GBT_VARKEY *) palloc(VARSIZE(u->lower) + VARHDRSZ );
- memcpy ( (void*) VARDATA(r), (void*) u->lower , VARSIZE(u->lower) );
- r->vl_len = VARSIZE(u->lower) + VARHDRSZ ;
+ r = (GBT_VARKEY *) palloc(VARSIZE(u->lower) + VARHDRSZ);
+ memcpy((void *) VARDATA(r), (void *) u->lower, VARSIZE(u->lower));
+ r->vl_len = VARSIZE(u->lower) + VARHDRSZ;
- } else { /* node key mode */
+ }
+ else
+ { /* node key mode */
- r = (GBT_VARKEY *) palloc(INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ );
- memcpy ( (void*) VARDATA(r) , (void*) u->lower , VARSIZE(u->lower) );
- memcpy ( (void*)&(((char *)r)[VARHDRSZ+INTALIGN(VARSIZE(u->lower))]), (void*) u->upper , VARSIZE(u->upper) );
- r->vl_len = INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ ;
+ r = (GBT_VARKEY *) palloc(INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ);
+ memcpy((void *) VARDATA(r), (void *) u->lower, VARSIZE(u->lower));
+ memcpy((void *) &(((char *) r)[VARHDRSZ + INTALIGN(VARSIZE(u->lower))]), (void *) u->upper, VARSIZE(u->upper));
+ r->vl_len = INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ;
- }
- return r;
+ }
+ return r;
}
-static GBT_VARKEY * gbt_var_leaf2node ( GBT_VARKEY * leaf, const gbtree_vinfo * tinfo )
+static GBT_VARKEY *
+gbt_var_leaf2node(GBT_VARKEY * leaf, const gbtree_vinfo * tinfo)
{
- GBT_VARKEY *out = leaf ;
+ GBT_VARKEY *out = leaf;
- if ( tinfo->f_l2n )
- {
- out = (*tinfo->f_l2n) (leaf);
- }
+ if (tinfo->f_l2n)
+ out = (*tinfo->f_l2n) (leaf);
- return out;
+ return out;
}
@@ -57,28 +64,27 @@ static GBT_VARKEY * gbt_var_leaf2node ( GBT_VARKEY * leaf, const gbtree_vinfo *
/*
* returns the common prefix length of a node key
*/
-static int32 gbt_var_node_cp_len ( const GBT_VARKEY * node , const gbtree_vinfo * tinfo )
+static int32
+gbt_var_node_cp_len(const GBT_VARKEY * node, const gbtree_vinfo * tinfo)
{
- int32 i ;
- int32 s = (tinfo->str)?(1):(0);
- GBT_VARKEY_R r = gbt_var_key_readable ( node );
- int32 t1len = VARSIZE(r.lower) - VARHDRSZ - s;
- int32 t2len = VARSIZE(r.upper) - VARHDRSZ - s;
- int32 ml = Min(t1len,t2len) ;
-
- char * p1 = VARDATA(r.lower) ,
- * p2 = VARDATA(r.upper) ;
-
- for ( i=0 ; i<ml; i++ )
- {
- if ( *p1 != *p2 )
- {
- return i;
- }
- p1++;
- p2++;
- }
- return ( ml );
+ int32 i;
+ int32 s = (tinfo->str) ? (1) : (0);
+ GBT_VARKEY_R r = gbt_var_key_readable(node);
+ int32 t1len = VARSIZE(r.lower) - VARHDRSZ - s;
+ int32 t2len = VARSIZE(r.upper) - VARHDRSZ - s;
+ int32 ml = Min(t1len, t2len);
+
+ char *p1 = VARDATA(r.lower),
+ *p2 = VARDATA(r.upper);
+
+ for (i = 0; i < ml; i++)
+ {
+ if (*p1 != *p2)
+ return i;
+ p1++;
+ p2++;
+ }
+ return (ml);
}
@@ -87,34 +93,38 @@ static int32 gbt_var_node_cp_len ( const GBT_VARKEY * node , const gbtree_vinfo
* returns true, if query matches prefix using common prefix
*/
-static bool gbt_bytea_pf_match ( const bytea * pf , const bytea * query , const gbtree_vinfo * tinfo )
+static bool
+gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo * tinfo)
{
- int k ;
- int32 s = (tinfo->str)?(1):(0);
- bool out = FALSE ;
- int32 qlen = VARSIZE(query) - VARHDRSZ - s ;
- int32 nlen = VARSIZE(pf) - VARHDRSZ - s ;
- if ( nlen <= qlen )
- {
- char *q = VARDATA(query) ;
- char *n = VARDATA(pf) ;
- out = TRUE;
- for ( k=0 ; k<nlen; k++ )
- {
- if ( *n != *q ){
- out = FALSE;
- break;
- }
- if ( k < (nlen-1) )
- {
- q++;
- n++;
- }
- }
- }
-
- return out;
+ int k;
+ int32 s = (tinfo->str) ? (1) : (0);
+ bool out = FALSE;
+ int32 qlen = VARSIZE(query) - VARHDRSZ - s;
+ int32 nlen = VARSIZE(pf) - VARHDRSZ - s;
+
+ if (nlen <= qlen)
+ {
+ char *q = VARDATA(query);
+ char *n = VARDATA(pf);
+
+ out = TRUE;
+ for (k = 0; k < nlen; k++)
+ {
+ if (*n != *q)
+ {
+ out = FALSE;
+ break;
+ }
+ if (k < (nlen - 1))
+ {
+ q++;
+ n++;
+ }
+ }
+ }
+
+ return out;
}
@@ -124,13 +134,14 @@ static bool gbt_bytea_pf_match ( const bytea * pf , const bytea * query , const
* returns true, if query matches node using common prefix
*/
-static bool gbt_var_node_pf_match ( const GBT_VARKEY_R * node , const bytea * query , const gbtree_vinfo * tinfo )
+static bool
+gbt_var_node_pf_match(const GBT_VARKEY_R * node, const bytea *query, const gbtree_vinfo * tinfo)
{
- return (
- gbt_bytea_pf_match ( node->lower, query , tinfo ) ||
- gbt_bytea_pf_match ( node->upper, query , tinfo )
- );
+ return (
+ gbt_bytea_pf_match(node->lower, query, tinfo) ||
+ gbt_bytea_pf_match(node->upper, query, tinfo)
+ );
}
@@ -138,280 +149,299 @@ static bool gbt_var_node_pf_match ( const GBT_VARKEY_R * node , const bytea * qu
/*
* truncates / compresses the node key
*/
-static GBT_VARKEY * gbt_var_node_truncate ( const GBT_VARKEY * node , int32 length , const gbtree_vinfo * tinfo )
+static GBT_VARKEY *
+gbt_var_node_truncate(const GBT_VARKEY * node, int32 length, const gbtree_vinfo * tinfo)
{
- int32 s = (tinfo->str)?(1):(0);
- GBT_VARKEY * out = NULL;
- GBT_VARKEY_R r = gbt_var_key_readable ( node );
- int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
- int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
- int32 si = 0;
-
- if (tinfo->str)
- length++; /* because of tailing '\0' */
-
- len1 = Min( len1, length ) ;
- len2 = Min( len2, length ) ;
- si = 2*VARHDRSZ + INTALIGN(VARHDRSZ+len1) + len2;
- out = (GBT_VARKEY *) palloc ( si );
- out->vl_len = si;
- memcpy ( (void*) &(((char*)out)[VARHDRSZ]) , (void*)r.lower, len1+VARHDRSZ-s );
- memcpy ( (void*) &(((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)]) , (void*)r.upper, len2+VARHDRSZ-s );
-
- if (tinfo->str)
- {
- ((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)-1] = '\0';
- ((char*)out)[2*VARHDRSZ+INTALIGN(VARHDRSZ+len1)+len2-1] = '\0';
- }
- *((int32*)&(((char*)out)[VARHDRSZ])) = len1 + VARHDRSZ;
- *((int32*)&(((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)])) = len2 + VARHDRSZ;
-
- return out;
+ int32 s = (tinfo->str) ? (1) : (0);
+ GBT_VARKEY *out = NULL;
+ GBT_VARKEY_R r = gbt_var_key_readable(node);
+ int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
+ int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
+ int32 si = 0;
+
+ if (tinfo->str)
+ length++; /* because of tailing '\0' */
+
+ len1 = Min(len1, length);
+ len2 = Min(len2, length);
+ si = 2 * VARHDRSZ + INTALIGN(VARHDRSZ + len1) + len2;
+ out = (GBT_VARKEY *) palloc(si);
+ out->vl_len = si;
+ memcpy((void *) &(((char *) out)[VARHDRSZ]), (void *) r.lower, len1 + VARHDRSZ - s);
+ memcpy((void *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)]), (void *) r.upper, len2 + VARHDRSZ - s);
+
+ if (tinfo->str)
+ {
+ ((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1) - 1] = '\0';
+ ((char *) out)[2 * VARHDRSZ + INTALIGN(VARHDRSZ + len1) + len2 - 1] = '\0';
+ }
+ *((int32 *) &(((char *) out)[VARHDRSZ])) = len1 + VARHDRSZ;
+ *((int32 *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)])) = len2 + VARHDRSZ;
+
+ return out;
}
extern void
-gbt_var_bin_union ( Datum * u , GBT_VARKEY * e , const gbtree_vinfo * tinfo )
+gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
{
- GBT_VARKEY * nk = NULL;
- GBT_VARKEY * tmp = NULL;
- GBT_VARKEY_R nr ;
- GBT_VARKEY_R eo = gbt_var_key_readable ( e );
-
-
- if ( eo.lower == eo.upper ) /* leaf */
- {
- tmp = gbt_var_leaf2node ( e , tinfo );
- if ( tmp != e )
- eo = gbt_var_key_readable ( tmp );
- }
-
- if ( DatumGetPointer(*u))
- {
-
- GBT_VARKEY_R ro = gbt_var_key_readable ( ( GBT_VARKEY *) DatumGetPointer (*u) );
-
- if ( (*tinfo->f_cmp) ( (bytea*)ro.lower, (bytea*)eo.lower ) > 0 ) {
- nr.lower = eo.lower;
- nr.upper = ro.upper;
- nk = gbt_var_key_copy ( &nr, TRUE );
- }
- if ( (*tinfo->f_cmp) ( (bytea*)ro.upper, (bytea*)eo.upper ) < 0 ) {
- nr.upper = eo.upper;
- nr.lower = ro.lower;
- nk = gbt_var_key_copy ( &nr, TRUE );
- }
- if ( nk )
- {
- pfree( DatumGetPointer (*u) );
- *u = PointerGetDatum(nk);
- }
-
-
-
- }
- else
- {
- nr.lower = eo.lower;
- nr.upper = eo.upper;
- *u = PointerGetDatum( gbt_var_key_copy ( &nr, TRUE ) );
- }
-
- if ( tmp && tmp != e )
- pfree ( tmp );
+ GBT_VARKEY *nk = NULL;
+ GBT_VARKEY *tmp = NULL;
+ GBT_VARKEY_R nr;
+ GBT_VARKEY_R eo = gbt_var_key_readable(e);
+
+
+ if (eo.lower == eo.upper) /* leaf */
+ {
+ tmp = gbt_var_leaf2node(e, tinfo);
+ if (tmp != e)
+ eo = gbt_var_key_readable(tmp);
+ }
+
+ if (DatumGetPointer(*u))
+ {
+
+ GBT_VARKEY_R ro = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(*u));
+
+ if ((*tinfo->f_cmp) ((bytea *) ro.lower, (bytea *) eo.lower) > 0)
+ {
+ nr.lower = eo.lower;
+ nr.upper = ro.upper;
+ nk = gbt_var_key_copy(&nr, TRUE);
+ }
+ if ((*tinfo->f_cmp) ((bytea *) ro.upper, (bytea *) eo.upper) < 0)
+ {
+ nr.upper = eo.upper;
+ nr.lower = ro.lower;
+ nk = gbt_var_key_copy(&nr, TRUE);
+ }
+ if (nk)
+ {
+ pfree(DatumGetPointer(*u));
+ *u = PointerGetDatum(nk);
+ }
+
+
+
+ }
+ else
+ {
+ nr.lower = eo.lower;
+ nr.upper = eo.upper;
+ *u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
+ }
+
+ if (tmp && tmp != e)
+ pfree(tmp);
}
-extern GISTENTRY *
-gbt_var_compress ( GISTENTRY *entry , const gbtree_vinfo * tinfo )
+extern GISTENTRY *
+gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo)
{
- GISTENTRY * retval;
+ GISTENTRY *retval;
- if (entry->leafkey)
- {
- GBT_VARKEY * r = NULL;
- bytea * tstd = ( bytea * ) DatumGetPointer ( entry->key ); /* toasted */
- bytea * leaf = ( bytea * ) DatumGetPointer ( PG_DETOAST_DATUM ( entry->key ) ); /* untoasted */
- GBT_VARKEY_R u ;
+ if (entry->leafkey)
+ {
+ GBT_VARKEY *r = NULL;
+ bytea *tstd = (bytea *) DatumGetPointer(entry->key); /* toasted */
+ bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); /* untoasted */
+ GBT_VARKEY_R u;
- u.lower = u.upper = leaf;
- r = gbt_var_key_copy ( &u , FALSE );
+ u.lower = u.upper = leaf;
+ r = gbt_var_key_copy(&u, FALSE);
- if ( tstd != leaf ){
- pfree(leaf);
- }
- retval = palloc(sizeof(GISTENTRY));
- gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page,
- entry->offset, VARSIZE(r), TRUE);
- } else {
- retval = entry;
+ if (tstd != leaf)
+ pfree(leaf);
+ retval = palloc(sizeof(GISTENTRY));
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, VARSIZE(r), TRUE);
+ }
+ else
+ {
+ retval = entry;
- }
+ }
- return (retval);
+ return (retval);
}
extern GBT_VARKEY *
-gbt_var_union ( const GistEntryVector * entryvec , int32 * size , const gbtree_vinfo * tinfo )
+gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo * tinfo)
{
- int i = 0,
- numranges = entryvec->n;
- GBT_VARKEY *cur,
- *tst=NULL;
- Datum out;
- GBT_VARKEY_R rk;
+ int i = 0,
+ numranges = entryvec->n;
+ GBT_VARKEY *cur,
+ *tst = NULL;
+ Datum out;
+ GBT_VARKEY_R rk;
- *size = sizeof(GBT_VARKEY);
+ *size = sizeof(GBT_VARKEY);
- tst = (GBT_VARKEY *) DatumGetPointer((entryvec->vector[0].key));
- cur = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[0].key)));
- rk = gbt_var_key_readable ( cur );
- out = PointerGetDatum ( gbt_var_key_copy( &rk, TRUE ) );
- if ( tst != cur ) pfree ( cur );
+ tst = (GBT_VARKEY *) DatumGetPointer((entryvec->vector[0].key));
+ cur = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[0].key)));
+ rk = gbt_var_key_readable(cur);
+ out = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
+ if (tst != cur)
+ pfree(cur);
- for (i = 1; i < numranges; i++)
- {
- tst = (GBT_VARKEY *) DatumGetPointer((entryvec->vector[i].key));
- cur = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[i].key)));
- gbt_var_bin_union ( &out , cur , tinfo );
- if ( tst != cur ) pfree ( cur );
- }
+ for (i = 1; i < numranges; i++)
+ {
+ tst = (GBT_VARKEY *) DatumGetPointer((entryvec->vector[i].key));
+ cur = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[i].key)));
+ gbt_var_bin_union(&out, cur, tinfo);
+ if (tst != cur)
+ pfree(cur);
+ }
- /* Truncate (=compress) key */
+ /* Truncate (=compress) key */
- if ( tinfo->trnc )
- {
- int32 plen ;
- GBT_VARKEY *trc = NULL;
+ if (tinfo->trnc)
+ {
+ int32 plen;
+ GBT_VARKEY *trc = NULL;
- plen = gbt_var_node_cp_len ( (GBT_VARKEY *) DatumGetPointer(out) , tinfo );
- trc = gbt_var_node_truncate ( (GBT_VARKEY *) DatumGetPointer(out) , plen+1 , tinfo ) ;
+ plen = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(out), tinfo);
+ trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
- pfree ( DatumGetPointer(out) );
- out = PointerGetDatum ( trc );
- }
+ pfree(DatumGetPointer(out));
+ out = PointerGetDatum(trc);
+ }
- return ( (GBT_VARKEY *) DatumGetPointer ( out ) );
+ return ((GBT_VARKEY *) DatumGetPointer(out));
}
-extern bool gbt_var_same ( bool * result, const Datum d1 , const Datum d2 , const gbtree_vinfo * tinfo ){
-
- GBT_VARKEY *tst1 = (GBT_VARKEY *) DatumGetPointer(d1);
- GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer( PG_DETOAST_DATUM(d1) );
- GBT_VARKEY *tst2 = (GBT_VARKEY *) DatumGetPointer(d2);
- GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer( PG_DETOAST_DATUM(d2) );
- GBT_VARKEY_R r1, r2;
- r1 = gbt_var_key_readable ( t1 );
- r2 = gbt_var_key_readable ( t2 );
-
- if (t1 && t2){
- *result = ( ( (*tinfo->f_cmp ) ( (bytea*)r1.lower, (bytea*)r2.lower) == 0
- && (*tinfo->f_cmp) ( (bytea*)r1.upper, (bytea*)r2.upper) == 0 ) ? TRUE : FALSE );
- } else
- *result = (t1 == NULL && t2 == NULL) ? TRUE : FALSE;
-
- if ( tst1 != t1 ) pfree (t1);
- if ( tst2 != t2 ) pfree (t2);
+extern bool
+gbt_var_same(bool *result, const Datum d1, const Datum d2, const gbtree_vinfo * tinfo)
+{
- PG_RETURN_POINTER(result);
+ GBT_VARKEY *tst1 = (GBT_VARKEY *) DatumGetPointer(d1);
+ GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(d1));
+ GBT_VARKEY *tst2 = (GBT_VARKEY *) DatumGetPointer(d2);
+ GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(d2));
+ GBT_VARKEY_R r1,
+ r2;
+
+ r1 = gbt_var_key_readable(t1);
+ r2 = gbt_var_key_readable(t2);
+
+ if (t1 && t2)
+ {
+ *result = (((*tinfo->f_cmp) ((bytea *) r1.lower, (bytea *) r2.lower) == 0
+ && (*tinfo->f_cmp) ((bytea *) r1.upper, (bytea *) r2.upper) == 0) ? TRUE : FALSE);
+ }
+ else
+ *result = (t1 == NULL && t2 == NULL) ? TRUE : FALSE;
+
+ if (tst1 != t1)
+ pfree(t1);
+ if (tst2 != t2)
+ pfree(t2);
+
+ PG_RETURN_POINTER(result);
}
extern float *
-gbt_var_penalty ( float * res , const GISTENTRY * o , const GISTENTRY * n, const gbtree_vinfo * tinfo )
+gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, const gbtree_vinfo * tinfo)
{
- GBT_VARKEY *orgt = (GBT_VARKEY *) DatumGetPointer(o->key);
- GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer( PG_DETOAST_DATUM(o->key) );
- GBT_VARKEY *newt = (GBT_VARKEY *) DatumGetPointer(n->key);
- GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer( PG_DETOAST_DATUM(n->key) );
- GBT_VARKEY_R ok , nk;
- GBT_VARKEY *tmp = NULL;
- int32 s = (tinfo->str)?(1):(0);
-
- *res = 0.0;
-
- nk = gbt_var_key_readable ( newe );
- if ( nk.lower == nk.upper ) /* leaf */
- {
- tmp = gbt_var_leaf2node ( newe , tinfo );
- if ( tmp != newe )
- nk = gbt_var_key_readable ( tmp );
- }
- ok = gbt_var_key_readable ( orge );
-
- if ( ( VARSIZE(ok.lower) - VARHDRSZ ) == s && ( VARSIZE(ok.upper) - VARHDRSZ ) == s )
- {
- *res = 0.0;
- } else
- if ( ! (
- (
- ( (*tinfo->f_cmp) (nk.lower, ok.lower)>=0 || gbt_bytea_pf_match(ok.lower, nk.lower, tinfo ) ) &&
- ( (*tinfo->f_cmp) (nk.upper, ok.upper)<=0 || gbt_bytea_pf_match(ok.upper, nk.upper, tinfo ) )
- )
- ) )
- {
- Datum d = PointerGetDatum (0);
- double dres = 0.0;
- int32 ol, ul;
-
- gbt_var_bin_union ( &d , orge , tinfo );
- ol = gbt_var_node_cp_len ( ( GBT_VARKEY *) DatumGetPointer(d), tinfo );
- gbt_var_bin_union ( &d , newe , tinfo );
- ul = gbt_var_node_cp_len ( ( GBT_VARKEY *) DatumGetPointer(d), tinfo );
-
- if ( ul < ol ) {
- dres = ( ol-ul ) ; /* lost of common prefix len */
- } else {
- GBT_VARKEY_R uk = gbt_var_key_readable ( ( GBT_VARKEY *) DatumGetPointer(d) );
- if ( tinfo->str )
- {
- dres = ( VARDATA(ok.lower)[ul]-VARDATA(uk.lower)[ul] ) +
- ( VARDATA(uk.upper)[ul]-VARDATA(ok.upper)[ul] );
- } else {
- char tmp[4];
- tmp[0] = ( ( VARSIZE(ok.lower) - VARHDRSZ ) == ul )?(CHAR_MIN):(VARDATA(ok.lower)[ul]);
- tmp[1] = ( ( VARSIZE(uk.lower) - VARHDRSZ ) == ul )?(CHAR_MIN):(VARDATA(uk.lower)[ul]);
- tmp[2] = ( ( VARSIZE(ok.upper) - VARHDRSZ ) == ul )?(CHAR_MIN):(VARDATA(ok.upper)[ul]);
- tmp[3] = ( ( VARSIZE(uk.upper) - VARHDRSZ ) == ul )?(CHAR_MIN):(VARDATA(uk.upper)[ul]);
- dres = ( tmp[0] - tmp[1] ) +
- ( tmp[3] - tmp[2] );
- }
- dres /= 256.0;
- }
- pfree ( DatumGetPointer(d) );
-
- *res += FLT_MIN ;
- *res += (float) ( dres / ( (double) ( ol +1 ) ) );
- *res *= ( FLT_MAX / ( o->rel->rd_att->natts + 1 ) );
-
- }
-
- if ( tmp && tmp != newe )
- pfree (tmp);
-
- if ( newe != newt ){
- pfree ( newe );
- }
-
- if ( orge != orgt ){
- pfree ( orge );
- }
- return res ;
+ GBT_VARKEY *orgt = (GBT_VARKEY *) DatumGetPointer(o->key);
+ GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(o->key));
+ GBT_VARKEY *newt = (GBT_VARKEY *) DatumGetPointer(n->key);
+ GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(n->key));
+ GBT_VARKEY_R ok,
+ nk;
+ GBT_VARKEY *tmp = NULL;
+ int32 s = (tinfo->str) ? (1) : (0);
+
+ *res = 0.0;
+
+ nk = gbt_var_key_readable(newe);
+ if (nk.lower == nk.upper) /* leaf */
+ {
+ tmp = gbt_var_leaf2node(newe, tinfo);
+ if (tmp != newe)
+ nk = gbt_var_key_readable(tmp);
+ }
+ ok = gbt_var_key_readable(orge);
+
+ if ((VARSIZE(ok.lower) - VARHDRSZ) == s && (VARSIZE(ok.upper) - VARHDRSZ) == s)
+ *res = 0.0;
+ else if (!(
+ (
+ ((*tinfo->f_cmp) (nk.lower, ok.lower) >= 0 || gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
+ ((*tinfo->f_cmp) (nk.upper, ok.upper) <= 0 || gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))
+ )
+ ))
+ {
+ Datum d = PointerGetDatum(0);
+ double dres = 0.0;
+ int32 ol,
+ ul;
+
+ gbt_var_bin_union(&d, orge, tinfo);
+ ol = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
+ gbt_var_bin_union(&d, newe, tinfo);
+ ul = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(d), tinfo);
+
+ if (ul < ol)
+ {
+ dres = (ol - ul); /* lost of common prefix len */
+ }
+ else
+ {
+ GBT_VARKEY_R uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(d));
+
+ if (tinfo->str)
+ {
+ dres = (VARDATA(ok.lower)[ul] - VARDATA(uk.lower)[ul]) +
+ (VARDATA(uk.upper)[ul] - VARDATA(ok.upper)[ul]);
+ }
+ else
+ {
+ char tmp[4];
+
+ tmp[0] = ((VARSIZE(ok.lower) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(ok.lower)[ul]);
+ tmp[1] = ((VARSIZE(uk.lower) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(uk.lower)[ul]);
+ tmp[2] = ((VARSIZE(ok.upper) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(ok.upper)[ul]);
+ tmp[3] = ((VARSIZE(uk.upper) - VARHDRSZ) == ul) ? (CHAR_MIN) : (VARDATA(uk.upper)[ul]);
+ dres = (tmp[0] - tmp[1]) +
+ (tmp[3] - tmp[2]);
+ }
+ dres /= 256.0;
+ }
+ pfree(DatumGetPointer(d));
+
+ *res += FLT_MIN;
+ *res += (float) (dres / ((double) (ol + 1)));
+ *res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
+
+ }
+
+ if (tmp && tmp != newe)
+ pfree(tmp);
+
+ if (newe != newt)
+ pfree(newe);
+
+ if (orge != orgt)
+ pfree(orge);
+ return res;
}
@@ -419,198 +449,194 @@ gbt_var_penalty ( float * res , const GISTENTRY * o , const GISTENTRY * n, const
/*
* Fortunately, this sort comparsion routine needn't be reentrant...
*/
-static const gbtree_vinfo * gbt_vsrt_cmp_tinfo;
+static const gbtree_vinfo *gbt_vsrt_cmp_tinfo;
static int
gbt_vsrt_cmp(const void *a, const void *b)
{
- GBT_VARKEY_R ar = gbt_var_key_readable ( ((const Vsrt *) a)->t );
- GBT_VARKEY_R br = gbt_var_key_readable ( ((const Vsrt *) b)->t );
+ GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
+ GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
- return (*gbt_vsrt_cmp_tinfo->f_cmp) ( ar.lower, br.lower );
+ return (*gbt_vsrt_cmp_tinfo->f_cmp) (ar.lower, br.lower);
}
extern GIST_SPLITVEC *
-gbt_var_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo * tinfo )
+gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo * tinfo)
{
- OffsetNumber i,
- maxoff = entryvec->n - 1;
- Vsrt *arr;
- int pfrcntr = 0 ,
- svcntr = 0 ,
- nbytes ;
- char * tst ,
- * cur ;
- char **pfr = NULL ;
- GBT_VARKEY **sv = NULL;
-
- arr = (Vsrt *) palloc((maxoff+1) * sizeof(Vsrt));
- nbytes = (maxoff + 2) * sizeof(OffsetNumber);
- v->spl_left = (OffsetNumber *) palloc(nbytes);
- v->spl_right = (OffsetNumber *) palloc(nbytes);
- v->spl_ldatum = PointerGetDatum(0);
- v->spl_rdatum = PointerGetDatum(0);
- v->spl_nleft = 0;
- v->spl_nright = 0;
-
- pfr = palloc ( sizeof ( GBT_VARKEY* ) * (maxoff+1) );
- sv = palloc ( sizeof ( bytea * ) * (maxoff+1) );
-
- /* Sort entries */
-
- for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
- {
- GBT_VARKEY_R ro;
- tst = (char *) DatumGetPointer((entryvec->vector[i].key));
- cur = (char *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[i].key)));
- if ( tst != cur ){
- pfr[pfrcntr] = cur ;
- pfrcntr++;
- }
- ro = gbt_var_key_readable( ( GBT_VARKEY *) cur );
- if ( ro.lower == ro.upper ) /* leaf */
- {
- sv[svcntr] = gbt_var_leaf2node ( ( GBT_VARKEY *) cur , tinfo );
- arr[i].t = sv[svcntr];
- if ( sv[svcntr] != ( GBT_VARKEY *) cur )
- svcntr++;
- } else {
- arr[i].t = ( GBT_VARKEY *) cur;
- }
- arr[i].i = i;
- }
-
- /* sort */
+ OffsetNumber i,
+ maxoff = entryvec->n - 1;
+ Vsrt *arr;
+ int pfrcntr = 0,
+ svcntr = 0,
+ nbytes;
+ char *tst,
+ *cur;
+ char **pfr = NULL;
+ GBT_VARKEY **sv = NULL;
+
+ arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt));
+ nbytes = (maxoff + 2) * sizeof(OffsetNumber);
+ v->spl_left = (OffsetNumber *) palloc(nbytes);
+ v->spl_right = (OffsetNumber *) palloc(nbytes);
+ v->spl_ldatum = PointerGetDatum(0);
+ v->spl_rdatum = PointerGetDatum(0);
+ v->spl_nleft = 0;
+ v->spl_nright = 0;
+
+ pfr = palloc(sizeof(GBT_VARKEY *) * (maxoff + 1));
+ sv = palloc(sizeof(bytea *) * (maxoff + 1));
+
+ /* Sort entries */
+
+ for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+ {
+ GBT_VARKEY_R ro;
+
+ tst = (char *) DatumGetPointer((entryvec->vector[i].key));
+ cur = (char *) DatumGetPointer(PG_DETOAST_DATUM((entryvec->vector[i].key)));
+ if (tst != cur)
+ {
+ pfr[pfrcntr] = cur;
+ pfrcntr++;
+ }
+ ro = gbt_var_key_readable((GBT_VARKEY *) cur);
+ if (ro.lower == ro.upper) /* leaf */
+ {
+ sv[svcntr] = gbt_var_leaf2node((GBT_VARKEY *) cur, tinfo);
+ arr[i].t = sv[svcntr];
+ if (sv[svcntr] != (GBT_VARKEY *) cur)
+ svcntr++;
+ }
+ else
+ arr[i].t = (GBT_VARKEY *) cur;
+ arr[i].i = i;
+ }
+
+ /* sort */
gbt_vsrt_cmp_tinfo = tinfo;
- qsort((void*) &arr[FirstOffsetNumber],
- maxoff-FirstOffsetNumber+1,
+ qsort((void *) &arr[FirstOffsetNumber],
+ maxoff - FirstOffsetNumber + 1,
sizeof(Vsrt),
gbt_vsrt_cmp);
- /* We do simply create two parts */
-
- for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
- {
- if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
- {
- gbt_var_bin_union(&v->spl_ldatum, arr[i].t, tinfo);
- v->spl_left[v->spl_nleft] = arr[i].i;
- v->spl_nleft++;
- }
- else
- {
- gbt_var_bin_union(&v->spl_rdatum, arr[i].t, tinfo);
- v->spl_right[v->spl_nright] = arr[i].i;
- v->spl_nright++;
- }
- }
-
- /* Free detoasted keys */
- for ( i=0 ; i<pfrcntr; i++ ){
- pfree( pfr[i] );
- }
-
- /* Free strxfrm'ed leafs */
- for ( i=0 ; i<svcntr; i++ ){
- pfree( sv[i] );
- }
-
- if ( pfr )
- {
- pfree (pfr);
- }
-
- if ( sv )
- {
- pfree (sv);
- }
-
- /* Truncate (=compress) key */
-
- if ( tinfo->trnc )
- {
-
- int32 ll = gbt_var_node_cp_len ( (GBT_VARKEY *) DatumGetPointer(v->spl_ldatum) , tinfo );
- int32 lr = gbt_var_node_cp_len ( (GBT_VARKEY *) DatumGetPointer(v->spl_rdatum) , tinfo );
- GBT_VARKEY * dl ;
- GBT_VARKEY * dr ;
-
- ll = Max (ll,lr);
- ll++;
-
- dl = gbt_var_node_truncate ( (GBT_VARKEY *) DatumGetPointer(v->spl_ldatum) , ll, tinfo ) ;
- dr = gbt_var_node_truncate ( (GBT_VARKEY *) DatumGetPointer(v->spl_rdatum) , ll, tinfo ) ;
- pfree( DatumGetPointer(v->spl_ldatum) );
- pfree( DatumGetPointer(v->spl_rdatum) );
- v->spl_ldatum = PointerGetDatum ( dl );
- v->spl_rdatum = PointerGetDatum ( dr );
-
- }
+ /* We do simply create two parts */
+
+ for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+ {
+ if (i <= (maxoff - FirstOffsetNumber + 1) / 2)
+ {
+ gbt_var_bin_union(&v->spl_ldatum, arr[i].t, tinfo);
+ v->spl_left[v->spl_nleft] = arr[i].i;
+ v->spl_nleft++;
+ }
+ else
+ {
+ gbt_var_bin_union(&v->spl_rdatum, arr[i].t, tinfo);
+ v->spl_right[v->spl_nright] = arr[i].i;
+ v->spl_nright++;
+ }
+ }
+
+ /* Free detoasted keys */
+ for (i = 0; i < pfrcntr; i++)
+ pfree(pfr[i]);
+
+ /* Free strxfrm'ed leafs */
+ for (i = 0; i < svcntr; i++)
+ pfree(sv[i]);
+
+ if (pfr)
+ pfree(pfr);
+
+ if (sv)
+ pfree(sv);
+
+ /* Truncate (=compress) key */
+
+ if (tinfo->trnc)
+ {
+
+ int32 ll = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), tinfo);
+ int32 lr = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), tinfo);
+ GBT_VARKEY *dl;
+ GBT_VARKEY *dr;
+
+ ll = Max(ll, lr);
+ ll++;
+
+ dl = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), ll, tinfo);
+ dr = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), ll, tinfo);
+ pfree(DatumGetPointer(v->spl_ldatum));
+ pfree(DatumGetPointer(v->spl_rdatum));
+ v->spl_ldatum = PointerGetDatum(dl);
+ v->spl_rdatum = PointerGetDatum(dr);
+
+ }
pfree(arr);
- return v;
+ return v;
}
/*
* The GiST consistent method
*/
-extern bool
-gbt_var_consistent(
- GBT_VARKEY_R * key,
- const void * query,
- const StrategyNumber * strategy,
- bool is_leaf,
- const gbtree_vinfo * tinfo
+extern bool
+gbt_var_consistent(
+ GBT_VARKEY_R * key,
+ const void *query,
+ const StrategyNumber *strategy,
+ bool is_leaf,
+ const gbtree_vinfo * tinfo
)
{
- bool retval = FALSE;
-
- switch (*strategy)
- {
- case BTLessEqualStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_ge)(query, (void*) key->lower);
- else
- retval = (*tinfo->f_cmp)((bytea*) query, key->lower) >= 0
- || gbt_var_node_pf_match( key ,query, tinfo );
- break;
- case BTLessStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_gt)(query, (void*) key->lower);
- else
- retval = (*tinfo->f_cmp)((bytea*)query, key->lower) >= 0
- || gbt_var_node_pf_match( key, query , tinfo );
- break;
- case BTEqualStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_eq)(query, (void*) key->lower);
- else
- retval = (
- (
- (*tinfo->f_cmp) (key->lower,(bytea*) query)<=0 &&
- (*tinfo->f_cmp) ((bytea*)query, (void*) key->upper)<=0
- ) || gbt_var_node_pf_match( key, query, tinfo )
- );
- break;
- case BTGreaterStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_lt)(query, (void*) key->upper);
- else
- retval = (*tinfo->f_cmp)((bytea*)query, key->upper)<=0
- || gbt_var_node_pf_match( key, query, tinfo );
- break;
- case BTGreaterEqualStrategyNumber:
- if ( is_leaf )
- retval = (*tinfo->f_le)(query, (void*) key->upper);
- else
- retval = (*tinfo->f_cmp)((bytea*) query, key->upper)<=0
- || gbt_var_node_pf_match( key, query, tinfo );
- break;
- default:
- retval = FALSE;
- }
-
- return (retval);
+ bool retval = FALSE;
+
+ switch (*strategy)
+ {
+ case BTLessEqualStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_ge) (query, (void *) key->lower);
+ else
+ retval = (*tinfo->f_cmp) ((bytea *) query, key->lower) >= 0
+ || gbt_var_node_pf_match(key, query, tinfo);
+ break;
+ case BTLessStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_gt) (query, (void *) key->lower);
+ else
+ retval = (*tinfo->f_cmp) ((bytea *) query, key->lower) >= 0
+ || gbt_var_node_pf_match(key, query, tinfo);
+ break;
+ case BTEqualStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_eq) (query, (void *) key->lower);
+ else
+ retval = (
+ (
+ (*tinfo->f_cmp) (key->lower, (bytea *) query) <= 0 &&
+ (*tinfo->f_cmp) ((bytea *) query, (void *) key->upper) <= 0
+ ) || gbt_var_node_pf_match(key, query, tinfo)
+ );
+ break;
+ case BTGreaterStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_lt) (query, (void *) key->upper);
+ else
+ retval = (*tinfo->f_cmp) ((bytea *) query, key->upper) <= 0
+ || gbt_var_node_pf_match(key, query, tinfo);
+ break;
+ case BTGreaterEqualStrategyNumber:
+ if (is_leaf)
+ retval = (*tinfo->f_le) (query, (void *) key->upper);
+ else
+ retval = (*tinfo->f_cmp) ((bytea *) query, key->upper) <= 0
+ || gbt_var_node_pf_match(key, query, tinfo);
+ break;
+ default:
+ retval = FALSE;
+ }
+
+ return (retval);
}
diff --git a/contrib/btree_gist/btree_utils_var.h b/contrib/btree_gist/btree_utils_var.h
index 086891b158f..ecb3f3f3f13 100644
--- a/contrib/btree_gist/btree_utils_var.h
+++ b/contrib/btree_gist/btree_utils_var.h
@@ -5,15 +5,16 @@ typedef bytea GBT_VARKEY;
/* Better readable key */
typedef struct
{
- bytea * lower, * upper;
-} GBT_VARKEY_R;
+ bytea *lower,
+ *upper;
+} GBT_VARKEY_R;
/* used for key sorting */
typedef struct
{
- int i ;
- GBT_VARKEY * t ;
-} Vsrt ;
+ int i;
+ GBT_VARKEY *t;
+} Vsrt;
/*
type description
@@ -23,45 +24,45 @@ typedef struct
typedef struct
{
- /* Attribs */
+ /* Attribs */
- enum gbtree_type t ; /* data type */
- bool str ; /* true, if string ( else binary ) */
- bool trnc ; /* truncate (=compress) key */
+ enum gbtree_type t; /* data type */
+ bool str; /* true, if string ( else binary ) */
+ bool trnc; /* truncate (=compress) key */
- /* Methods */
+ /* Methods */
- bool (*f_gt) ( const void * , const void * ); /* greater then */
- bool (*f_ge) ( const void * , const void * ); /* greater equal */
- bool (*f_eq) ( const void * , const void * ); /* equal */
- bool (*f_le) ( const void * , const void * ); /* less equal */
- bool (*f_lt) ( const void * , const void * ); /* less then */
- int32 (*f_cmp) ( const bytea * , const bytea * ); /* node compare */
- GBT_VARKEY* (*f_l2n) ( GBT_VARKEY * ); /* convert leaf to node */
-} gbtree_vinfo;
+ bool (*f_gt) (const void *, const void *); /* greater then */
+ bool (*f_ge) (const void *, const void *); /* greater equal */
+ bool (*f_eq) (const void *, const void *); /* equal */
+ bool (*f_le) (const void *, const void *); /* less equal */
+ bool (*f_lt) (const void *, const void *); /* less then */
+ int32 (*f_cmp) (const bytea *, const bytea *); /* node compare */
+ GBT_VARKEY *(*f_l2n) (GBT_VARKEY *); /* convert leaf to node */
+} gbtree_vinfo;
-extern GBT_VARKEY_R gbt_var_key_readable ( const GBT_VARKEY * k );
+extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY * k);
-extern GBT_VARKEY *gbt_var_key_copy ( const GBT_VARKEY_R * u, bool force_node );
+extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R * u, bool force_node);
-extern GISTENTRY *gbt_var_compress ( GISTENTRY *entry , const gbtree_vinfo * tinfo );
+extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo);
-extern GBT_VARKEY *gbt_var_union ( const GistEntryVector * entryvec , int32 * size ,
- const gbtree_vinfo * tinfo );
+extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size,
+ const gbtree_vinfo * tinfo);
-extern bool gbt_var_same ( bool * result, const Datum d1 , const Datum d2 ,
- const gbtree_vinfo * tinfo );
+extern bool gbt_var_same(bool *result, const Datum d1, const Datum d2,
+ const gbtree_vinfo * tinfo);
-extern float *gbt_var_penalty ( float * res , const GISTENTRY * o , const GISTENTRY * n,
- const gbtree_vinfo * tinfo );
+extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
+ const gbtree_vinfo * tinfo);
-extern bool gbt_var_consistent( GBT_VARKEY_R * key , const void * query,
- const StrategyNumber * strategy , bool is_leaf,
- const gbtree_vinfo * tinfo );
+extern bool gbt_var_consistent(GBT_VARKEY_R * key, const void *query,
+ const StrategyNumber *strategy, bool is_leaf,
+ const gbtree_vinfo * tinfo);
-extern GIST_SPLITVEC *gbt_var_picksplit ( const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_vinfo * tinfo );
-extern void gbt_var_bin_union ( Datum * u , GBT_VARKEY * e ,
- const gbtree_vinfo * tinfo );
+extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
+ const gbtree_vinfo * tinfo);
+extern void gbt_var_bin_union(Datum *u, GBT_VARKEY * e,
+ const gbtree_vinfo * tinfo);