Commit b6b71b85 authored by Bruce Momjian's avatar Bruce Momjian

Pgindent run for 8.0.

parent 90cb9c30
...@@ -25,63 +25,70 @@ Datum gbt_bit_same(PG_FUNCTION_ARGS); ...@@ -25,63 +25,70 @@ Datum gbt_bit_same(PG_FUNCTION_ARGS);
/* define for comparison */ /* 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 return
( DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b) ) ) ); (DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
} }
static bytea * static bytea *
gbt_bit_xfrm ( bytea * leaf ) gbt_bit_xfrm(bytea *leaf)
{ {
bytea * out = leaf; bytea *out = leaf;
int s = VARBITBYTES(leaf) + VARHDRSZ; int s = VARBITBYTES(leaf) + VARHDRSZ;
out = palloc ( s ); out = palloc(s);
VARATT_SIZEP(out) = s; VARATT_SIZEP(out) = s;
memcpy ( (void*)VARDATA(out), (void*)VARBITS(leaf), VARBITBYTES(leaf) ); memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
return out; 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 *out = leaf;
GBT_VARKEY_R r = gbt_var_key_readable ( leaf ); GBT_VARKEY_R r = gbt_var_key_readable(leaf);
bytea *o ; bytea *o;
o = gbt_bit_xfrm (r.lower); o = gbt_bit_xfrm(r.lower);
r.upper = r.lower = o; r.upper = r.lower = o;
out = gbt_var_key_copy( &r, TRUE ); out = gbt_var_key_copy(&r, TRUE);
pfree(o); pfree(o);
return out; return out;
...@@ -108,39 +115,39 @@ static const gbtree_vinfo tinfo = ...@@ -108,39 +115,39 @@ static const gbtree_vinfo tinfo =
**************************************************/ **************************************************/
Datum Datum
gbt_bit_compress (PG_FUNCTION_ARGS) gbt_bit_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
} }
Datum Datum
gbt_bit_consistent(PG_FUNCTION_ARGS) gbt_bit_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ; GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) ); GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) ); void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
void *query = ( void * ) DatumGetByteaP ( PG_GETARG_DATUM(1) ); void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE; bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable ( key ); GBT_VARKEY_R r = gbt_var_key_readable(key);
if ( GIST_LEAF(entry) ) if (GIST_LEAF(entry))
retval = gbt_var_consistent(&r, query, &strategy, TRUE, &tinfo);
else
{ {
retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo ); bytea *q = gbt_bit_xfrm((bytea *) query);
} else {
bytea * q = gbt_bit_xfrm ( ( bytea * ) query ); retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
pfree(q); pfree(q);
} }
if ( ktst != key ){ if (ktst != key)
pfree ( key ); pfree(key);
} if (qtst != query)
if ( qtst != query ){ pfree(query);
pfree ( query );
}
PG_RETURN_BOOL(retval); PG_RETURN_BOOL(retval);
} }
...@@ -149,9 +156,10 @@ gbt_bit_consistent(PG_FUNCTION_ARGS) ...@@ -149,9 +156,10 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
Datum Datum
gbt_bit_union(PG_FUNCTION_ARGS) gbt_bit_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector * entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 * size = (int *) PG_GETARG_POINTER(1); int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
} }
...@@ -160,7 +168,8 @@ gbt_bit_picksplit(PG_FUNCTION_ARGS) ...@@ -160,7 +168,8 @@ gbt_bit_picksplit(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit ( entryvec, v, &tinfo );
gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v); PG_RETURN_POINTER(v);
} }
...@@ -170,7 +179,8 @@ gbt_bit_same(PG_FUNCTION_ARGS) ...@@ -170,7 +179,8 @@ gbt_bit_same(PG_FUNCTION_ARGS)
Datum d1 = PG_GETARG_DATUM(0); Datum d1 = PG_GETARG_DATUM(0);
Datum d2 = PG_GETARG_DATUM(1); Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
} }
...@@ -178,8 +188,8 @@ Datum ...@@ -178,8 +188,8 @@ Datum
gbt_bit_penalty(PG_FUNCTION_ARGS) gbt_bit_penalty(PG_FUNCTION_ARGS)
{ {
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1); GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
}
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
}
...@@ -23,36 +23,42 @@ Datum gbt_bytea_same(PG_FUNCTION_ARGS); ...@@ -23,36 +23,42 @@ Datum gbt_bytea_same(PG_FUNCTION_ARGS);
/* define for comparison */ /* 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 return
( DatumGetInt32(DirectFunctionCall2(byteacmp,PointerGetDatum(a),PointerGetDatum(b) ) ) ); (DatumGetInt32(DirectFunctionCall2(byteacmp, PointerGetDatum(a), PointerGetDatum(b))));
} }
...@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo = ...@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo =
Datum Datum
gbt_bytea_compress (PG_FUNCTION_ARGS) gbt_bytea_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
} }
...@@ -89,22 +96,20 @@ Datum ...@@ -89,22 +96,20 @@ Datum
gbt_bytea_consistent(PG_FUNCTION_ARGS) gbt_bytea_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ; GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) ); GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) ); void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
void *query = ( void * ) DatumGetByteaP ( PG_GETARG_DATUM(1) ); void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE; bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable ( key ); GBT_VARKEY_R r = gbt_var_key_readable(key);
retval = gbt_var_consistent( &r, query, &strategy, GIST_LEAF(entry), &tinfo ); retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
if ( ktst != key ){ if (ktst != key)
pfree ( key ); pfree(key);
} if (qtst != query)
if ( qtst != query ){ pfree(query);
pfree ( query );
}
PG_RETURN_BOOL(retval); PG_RETURN_BOOL(retval);
} }
...@@ -113,9 +118,10 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS) ...@@ -113,9 +118,10 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
Datum Datum
gbt_bytea_union(PG_FUNCTION_ARGS) gbt_bytea_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector * entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 * size = (int *) PG_GETARG_POINTER(1); int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
} }
...@@ -124,7 +130,8 @@ gbt_bytea_picksplit(PG_FUNCTION_ARGS) ...@@ -124,7 +130,8 @@ gbt_bytea_picksplit(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit ( entryvec, v, &tinfo );
gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v); PG_RETURN_POINTER(v);
} }
...@@ -134,7 +141,8 @@ gbt_bytea_same(PG_FUNCTION_ARGS) ...@@ -134,7 +141,8 @@ gbt_bytea_same(PG_FUNCTION_ARGS)
Datum d1 = PG_GETARG_DATUM(0); Datum d1 = PG_GETARG_DATUM(0);
Datum d2 = PG_GETARG_DATUM(1); Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
} }
...@@ -142,8 +150,8 @@ Datum ...@@ -142,8 +150,8 @@ Datum
gbt_bytea_penalty(PG_FUNCTION_ARGS) gbt_bytea_penalty(PG_FUNCTION_ARGS)
{ {
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1); GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
}
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
}
...@@ -25,37 +25,40 @@ Datum gbt_cash_consistent(PG_FUNCTION_ARGS); ...@@ -25,37 +25,40 @@ Datum gbt_cash_consistent(PG_FUNCTION_ARGS);
Datum gbt_cash_penalty(PG_FUNCTION_ARGS); Datum gbt_cash_penalty(PG_FUNCTION_ARGS);
Datum gbt_cash_same(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 static int
gbt_cashkey_cmp(const void *a, const void *b) gbt_cashkey_cmp(const void *a, const void *b)
{ {
if ( *(Cash*)&(((Nsrt *) a)->t[0]) > *(Cash*)&(((Nsrt *) b)->t[0]) ){ if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
if ( *(Cash*)&(((Nsrt *) a)->t[0]) < *(Cash*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -84,7 +87,8 @@ gbt_cash_compress(PG_FUNCTION_ARGS) ...@@ -84,7 +87,8 @@ gbt_cash_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -94,13 +98,14 @@ gbt_cash_consistent(PG_FUNCTION_ARGS) ...@@ -94,13 +98,14 @@ gbt_cash_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Cash query = (*((Cash *) PG_GETARG_POINTER(1))); Cash query = (*((Cash *) PG_GETARG_POINTER(1)));
cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key); cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -110,8 +115,9 @@ gbt_cash_union(PG_FUNCTION_ARGS) ...@@ -110,8 +115,9 @@ gbt_cash_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(cashKEY)); void *out = palloc(sizeof(cashKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -122,16 +128,17 @@ gbt_cash_penalty(PG_FUNCTION_ARGS) ...@@ -122,16 +128,17 @@ gbt_cash_penalty(PG_FUNCTION_ARGS)
cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -155,8 +162,6 @@ gbt_cash_same(PG_FUNCTION_ARGS) ...@@ -155,8 +162,6 @@ gbt_cash_same(PG_FUNCTION_ARGS)
cashKEY *b2 = (cashKEY *) PG_GETARG_POINTER(1); cashKEY *b2 = (cashKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -25,38 +25,43 @@ Datum gbt_date_consistent(PG_FUNCTION_ARGS); ...@@ -25,38 +25,43 @@ Datum gbt_date_consistent(PG_FUNCTION_ARGS);
Datum gbt_date_penalty(PG_FUNCTION_ARGS); Datum gbt_date_penalty(PG_FUNCTION_ARGS);
Datum gbt_date_same(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( return DatumGetBool(
DirectFunctionCall2(date_gt,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(date_ge,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(date_eq,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(date_le,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(date_lt,DateADTGetDatum( *((DateADT*)a) ), DateADTGetDatum( *((DateADT*)b) ) ) DirectFunctionCall2(date_lt, DateADTGetDatum(*((DateADT *) a)), DateADTGetDatum(*((DateADT *) b)))
); );
} }
...@@ -65,12 +70,10 @@ static bool gbt_datelt (const void *a, const void *b) ...@@ -65,12 +70,10 @@ static bool gbt_datelt (const void *a, const void *b)
static int static int
gbt_datekey_cmp(const void *a, const void *b) gbt_datekey_cmp(const void *a, const void *b)
{ {
if ( gbt_dategt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){ if (gbt_dategt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1; return 1;
} else else if (gbt_datelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
if ( gbt_datelt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -99,7 +102,8 @@ gbt_date_compress(PG_FUNCTION_ARGS) ...@@ -99,7 +102,8 @@ gbt_date_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -108,16 +112,16 @@ Datum ...@@ -108,16 +112,16 @@ Datum
gbt_date_consistent(PG_FUNCTION_ARGS) gbt_date_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
DateADT query = PG_GETARG_DATEADT( 1 ); DateADT query = PG_GETARG_DATEADT(1);
dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key); dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -127,8 +131,9 @@ gbt_date_union(PG_FUNCTION_ARGS) ...@@ -127,8 +131,9 @@ gbt_date_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(dateKEY)); void *out = palloc(sizeof(dateKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -138,7 +143,8 @@ gbt_date_penalty(PG_FUNCTION_ARGS) ...@@ -138,7 +143,8 @@ gbt_date_penalty(PG_FUNCTION_ARGS)
dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); dateKEY *origentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
dateKEY *newentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); dateKEY *newentry = (dateKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
int32 diff, res ; int32 diff,
res;
diff = DatumGetInt32(DirectFunctionCall2( diff = DatumGetInt32(DirectFunctionCall2(
date_mi, date_mi,
...@@ -156,14 +162,15 @@ gbt_date_penalty(PG_FUNCTION_ARGS) ...@@ -156,14 +162,15 @@ gbt_date_penalty(PG_FUNCTION_ARGS)
*result = 0.0; *result = 0.0;
if ( res > 0 ){ if (res > 0)
{
diff = DatumGetInt32(DirectFunctionCall2( diff = DatumGetInt32(DirectFunctionCall2(
date_mi, date_mi,
DateADTGetDatum(origentry->upper), DateADTGetDatum(origentry->upper),
DateADTGetDatum(origentry->lower))); DateADTGetDatum(origentry->lower)));
*result += FLT_MIN ; *result += FLT_MIN;
*result += (float) ( res / ( (double) ( res + diff ) ) ); *result += (float) (res / ((double) (res + diff)));
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
} }
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
...@@ -187,6 +194,6 @@ gbt_date_same(PG_FUNCTION_ARGS) ...@@ -187,6 +194,6 @@ gbt_date_same(PG_FUNCTION_ARGS)
dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1); dateKEY *b2 = (dateKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -24,37 +24,40 @@ Datum gbt_float4_consistent(PG_FUNCTION_ARGS); ...@@ -24,37 +24,40 @@ Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
Datum gbt_float4_penalty(PG_FUNCTION_ARGS); Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
Datum gbt_float4_same(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 static int
gbt_float4key_cmp(const void *a, const void *b) gbt_float4key_cmp(const void *a, const void *b)
{ {
if ( *(float4*)&(((Nsrt *) a)->t[0]) > *(float4*)&(((Nsrt *) b)->t[0]) ){ if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
if ( *(float4*)&(((Nsrt *) a)->t[0]) < *(float4*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -83,7 +86,8 @@ gbt_float4_compress(PG_FUNCTION_ARGS) ...@@ -83,7 +86,8 @@ gbt_float4_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -93,13 +97,14 @@ gbt_float4_consistent(PG_FUNCTION_ARGS) ...@@ -93,13 +97,14 @@ gbt_float4_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
float4 query = PG_GETARG_FLOAT4(1); float4 query = PG_GETARG_FLOAT4(1);
float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key); float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -109,8 +114,9 @@ gbt_float4_union(PG_FUNCTION_ARGS) ...@@ -109,8 +114,9 @@ gbt_float4_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(float4KEY)); void *out = palloc(sizeof(float4KEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY); *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -121,16 +127,17 @@ gbt_float4_penalty(PG_FUNCTION_ARGS) ...@@ -121,16 +127,17 @@ gbt_float4_penalty(PG_FUNCTION_ARGS)
float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
float4 res ; float4 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -154,7 +161,6 @@ gbt_float4_same(PG_FUNCTION_ARGS) ...@@ -154,7 +161,6 @@ gbt_float4_same(PG_FUNCTION_ARGS)
float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1); float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -25,37 +25,40 @@ Datum gbt_float8_penalty(PG_FUNCTION_ARGS); ...@@ -25,37 +25,40 @@ Datum gbt_float8_penalty(PG_FUNCTION_ARGS);
Datum gbt_float8_same(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 static int
gbt_float8key_cmp(const void *a, const void *b) gbt_float8key_cmp(const void *a, const void *b)
{ {
if ( *(float8*)&(((Nsrt *) a)->t[0]) > *(float8*)&(((Nsrt *) b)->t[0]) ){ if (*(float8 *) &(((Nsrt *) a)->t[0]) > *(float8 *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(float8 *) &(((Nsrt *) a)->t[0]) < *(float8 *) &(((Nsrt *) b)->t[0]))
if ( *(float8*)&(((Nsrt *) a)->t[0]) < *(float8*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -84,7 +87,8 @@ gbt_float8_compress(PG_FUNCTION_ARGS) ...@@ -84,7 +87,8 @@ gbt_float8_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -95,13 +99,14 @@ gbt_float8_consistent(PG_FUNCTION_ARGS) ...@@ -95,13 +99,14 @@ gbt_float8_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
float8 query = PG_GETARG_FLOAT8(1); float8 query = PG_GETARG_FLOAT8(1);
float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key); float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -111,8 +116,9 @@ gbt_float8_union(PG_FUNCTION_ARGS) ...@@ -111,8 +116,9 @@ gbt_float8_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(float8KEY)); void *out = palloc(sizeof(float8KEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY); *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -123,16 +129,17 @@ gbt_float8_penalty(PG_FUNCTION_ARGS) ...@@ -123,16 +129,17 @@ gbt_float8_penalty(PG_FUNCTION_ARGS)
float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -156,6 +163,6 @@ gbt_float8_same(PG_FUNCTION_ARGS) ...@@ -156,6 +163,6 @@ gbt_float8_same(PG_FUNCTION_ARGS)
float8KEY *b2 = (float8KEY *) PG_GETARG_POINTER(1); float8KEY *b2 = (float8KEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -42,4 +42,3 @@ gbt_decompress(PG_FUNCTION_ARGS) ...@@ -42,4 +42,3 @@ gbt_decompress(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(PG_GETARG_POINTER(0)); PG_RETURN_POINTER(PG_GETARG_POINTER(0));
} }
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
enum gbtree_type enum gbtree_type
{ {
gbt_t_var , gbt_t_var,
gbt_t_int2 , gbt_t_int2,
gbt_t_int4 , gbt_t_int4,
gbt_t_int8 , gbt_t_int8,
gbt_t_float4 , gbt_t_float4,
gbt_t_float8 , gbt_t_float8,
gbt_t_numeric, gbt_t_numeric,
gbt_t_ts, gbt_t_ts,
gbt_t_cash, gbt_t_cash,
...@@ -34,6 +34,6 @@ enum gbtree_type ...@@ -34,6 +34,6 @@ enum gbtree_type
* Generic btree functions * 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);
...@@ -32,37 +32,40 @@ Datum gbt_inet_penalty(PG_FUNCTION_ARGS); ...@@ -32,37 +32,40 @@ Datum gbt_inet_penalty(PG_FUNCTION_ARGS);
Datum gbt_inet_same(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 static int
gbt_inetkey_cmp(const void *a, const void *b) gbt_inetkey_cmp(const void *a, const void *b)
{ {
if ( *(double*)(&((Nsrt *) a)->t[0]) > *(double*)(&((Nsrt *) b)->t[0]) ){ if (*(double *) (&((Nsrt *) a)->t[0]) > *(double *) (&((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(double *) (&((Nsrt *) a)->t[0]) < *(double *) (&((Nsrt *) b)->t[0]))
if ( *(double*)(&((Nsrt *) a)->t[0]) < *(double*)(&((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -88,15 +91,16 @@ static const gbtree_ninfo tinfo = ...@@ -88,15 +91,16 @@ static const gbtree_ninfo tinfo =
static GISTENTRY * static GISTENTRY *
gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid) gbt_inet_compress_inetrnal(GISTENTRY *retval, GISTENTRY *entry, Oid typid)
{ {
if (entry->leafkey) if (entry->leafkey)
{ {
inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY)); inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
r->lower = convert_network_to_scalar(entry->key, typid ); r->lower = convert_network_to_scalar(entry->key, typid);
r->upper = r->lower ; r->upper = r->lower;
gistentryinit(*retval, PointerGetDatum(r), gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page, entry->rel, entry->page,
entry->offset, sizeof(inetKEY), FALSE); entry->offset, sizeof(inetKEY), FALSE);
...@@ -104,7 +108,7 @@ gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid) ...@@ -104,7 +108,7 @@ gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid)
else else
retval = entry; retval = entry;
return ( retval ); return (retval);
} }
...@@ -114,7 +118,8 @@ gbt_inet_compress(PG_FUNCTION_ARGS) ...@@ -114,7 +118,8 @@ gbt_inet_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_inet_compress_inetrnal(retval ,entry ,INETOID ) );
PG_RETURN_POINTER(gbt_inet_compress_inetrnal(retval, entry, INETOID));
} }
Datum Datum
...@@ -122,24 +127,26 @@ gbt_cidr_compress(PG_FUNCTION_ARGS) ...@@ -122,24 +127,26 @@ gbt_cidr_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_inet_compress_inetrnal(retval ,entry ,CIDROID ) );
PG_RETURN_POINTER(gbt_inet_compress_inetrnal(retval, entry, CIDROID));
} }
static bool static bool
gbt_inet_consistent_internal ( gbt_inet_consistent_internal(
const GISTENTRY * entry, const GISTENTRY *entry,
const double * query, const double *query,
const StrategyNumber * strategy const StrategyNumber *strategy
){ )
{
inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key); inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
return ( return (
gbt_num_consistent( &key, (void*)query,strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) query, strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -148,11 +155,11 @@ Datum ...@@ -148,11 +155,11 @@ Datum
gbt_inet_consistent(PG_FUNCTION_ARGS) gbt_inet_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
double query = convert_network_to_scalar( PG_GETARG_DATUM(1) ,INETOID ); double query = convert_network_to_scalar(PG_GETARG_DATUM(1), INETOID);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_inet_consistent_internal ( entry, &query, &strategy ) gbt_inet_consistent_internal(entry, &query, &strategy)
); );
} }
...@@ -160,11 +167,11 @@ Datum ...@@ -160,11 +167,11 @@ Datum
gbt_cidr_consistent(PG_FUNCTION_ARGS) gbt_cidr_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
double query = convert_network_to_scalar( PG_GETARG_DATUM(1) ,CIDROID ); double query = convert_network_to_scalar(PG_GETARG_DATUM(1), CIDROID);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_inet_consistent_internal ( entry, &query, &strategy ) gbt_inet_consistent_internal(entry, &query, &strategy)
); );
} }
...@@ -174,8 +181,9 @@ gbt_inet_union(PG_FUNCTION_ARGS) ...@@ -174,8 +181,9 @@ gbt_inet_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(inetKEY)); void *out = palloc(sizeof(inetKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -186,16 +194,17 @@ gbt_inet_penalty(PG_FUNCTION_ARGS) ...@@ -186,16 +194,17 @@ gbt_inet_penalty(PG_FUNCTION_ARGS)
inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -219,6 +228,6 @@ gbt_inet_same(PG_FUNCTION_ARGS) ...@@ -219,6 +228,6 @@ gbt_inet_same(PG_FUNCTION_ARGS)
inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1); inetKEY *b2 = (inetKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -24,37 +24,40 @@ Datum gbt_int2_consistent(PG_FUNCTION_ARGS); ...@@ -24,37 +24,40 @@ Datum gbt_int2_consistent(PG_FUNCTION_ARGS);
Datum gbt_int2_penalty(PG_FUNCTION_ARGS); Datum gbt_int2_penalty(PG_FUNCTION_ARGS);
Datum gbt_int2_same(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 static int
gbt_int2key_cmp(const void *a, const void *b) gbt_int2key_cmp(const void *a, const void *b)
{ {
if ( *(int16*)(&((Nsrt *) a)->t[0]) > *(int16*)&(((Nsrt *) b)->t[0]) ){ if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
if ( *(int16*)&(((Nsrt *) a)->t[0]) < *(int16*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -87,7 +90,8 @@ gbt_int2_compress(PG_FUNCTION_ARGS) ...@@ -87,7 +90,8 @@ gbt_int2_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -97,13 +101,14 @@ gbt_int2_consistent(PG_FUNCTION_ARGS) ...@@ -97,13 +101,14 @@ gbt_int2_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int16 query = PG_GETARG_INT16(1); int16 query = PG_GETARG_INT16(1);
int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key); int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -113,8 +118,9 @@ gbt_int2_union(PG_FUNCTION_ARGS) ...@@ -113,8 +118,9 @@ gbt_int2_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(int16KEY)); void *out = palloc(sizeof(int16KEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY); *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -124,16 +130,17 @@ gbt_int2_penalty(PG_FUNCTION_ARGS) ...@@ -124,16 +130,17 @@ gbt_int2_penalty(PG_FUNCTION_ARGS)
int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
int2 res ; 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -156,6 +163,6 @@ gbt_int2_same(PG_FUNCTION_ARGS) ...@@ -156,6 +163,6 @@ gbt_int2_same(PG_FUNCTION_ARGS)
int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1); int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -25,37 +25,40 @@ Datum gbt_int4_penalty(PG_FUNCTION_ARGS); ...@@ -25,37 +25,40 @@ Datum gbt_int4_penalty(PG_FUNCTION_ARGS);
Datum gbt_int4_same(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 static int
gbt_int4key_cmp(const void *a, const void *b) gbt_int4key_cmp(const void *a, const void *b)
{ {
if ( *(int32*)&(((Nsrt *) a)->t[0]) > *(int32*)&(((Nsrt *) b)->t[0]) ){ if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
if ( *(int32*)&(((Nsrt *) a)->t[0]) < *(int32*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -84,7 +87,8 @@ gbt_int4_compress(PG_FUNCTION_ARGS) ...@@ -84,7 +87,8 @@ gbt_int4_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -95,13 +99,14 @@ gbt_int4_consistent(PG_FUNCTION_ARGS) ...@@ -95,13 +99,14 @@ gbt_int4_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int32 query = PG_GETARG_INT32(1); int32 query = PG_GETARG_INT32(1);
int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key); int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -110,9 +115,10 @@ Datum ...@@ -110,9 +115,10 @@ Datum
gbt_int4_union(PG_FUNCTION_ARGS) gbt_int4_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc( sizeof(int32KEY) ); void *out = palloc(sizeof(int32KEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY); *(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -122,16 +128,17 @@ gbt_int4_penalty(PG_FUNCTION_ARGS) ...@@ -122,16 +128,17 @@ gbt_int4_penalty(PG_FUNCTION_ARGS)
int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
int4 res ; 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -154,6 +161,6 @@ gbt_int4_same(PG_FUNCTION_ARGS) ...@@ -154,6 +161,6 @@ gbt_int4_same(PG_FUNCTION_ARGS)
int32KEY *b2 = (int32KEY *) PG_GETARG_POINTER(1); int32KEY *b2 = (int32KEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -25,37 +25,40 @@ Datum gbt_int8_penalty(PG_FUNCTION_ARGS); ...@@ -25,37 +25,40 @@ Datum gbt_int8_penalty(PG_FUNCTION_ARGS);
Datum gbt_int8_same(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 static int
gbt_int8key_cmp(const void *a, const void *b) gbt_int8key_cmp(const void *a, const void *b)
{ {
if ( *(int64*)&(((Nsrt *) a)->t[0]) > *(int64*)&(((Nsrt *) b)->t[0]) ){ if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
if ( *(int64*)&(((Nsrt *) a)->t[0]) < *(int64*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -84,7 +87,8 @@ gbt_int8_compress(PG_FUNCTION_ARGS) ...@@ -84,7 +87,8 @@ gbt_int8_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -94,13 +98,14 @@ gbt_int8_consistent(PG_FUNCTION_ARGS) ...@@ -94,13 +98,14 @@ gbt_int8_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int64 query = PG_GETARG_INT64(1); int64 query = PG_GETARG_INT64(1);
int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key); int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -110,8 +115,9 @@ gbt_int8_union(PG_FUNCTION_ARGS) ...@@ -110,8 +115,9 @@ gbt_int8_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(int64KEY)); void *out = palloc(sizeof(int64KEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY); *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -121,16 +127,17 @@ gbt_int8_penalty(PG_FUNCTION_ARGS) ...@@ -121,16 +127,17 @@ gbt_int8_penalty(PG_FUNCTION_ARGS)
int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
int64 res ; 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -154,7 +161,6 @@ gbt_int8_same(PG_FUNCTION_ARGS) ...@@ -154,7 +161,6 @@ gbt_int8_same(PG_FUNCTION_ARGS)
int64KEY *b2 = (int64KEY *) PG_GETARG_POINTER(1); int64KEY *b2 = (int64KEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
typedef struct typedef struct
{ {
Interval lower, upper; Interval lower,
upper;
} intvKEY; } intvKEY;
...@@ -27,58 +28,65 @@ Datum gbt_intv_penalty(PG_FUNCTION_ARGS); ...@@ -27,58 +28,65 @@ Datum gbt_intv_penalty(PG_FUNCTION_ARGS);
Datum gbt_intv_same(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 static int
gbt_intvkey_cmp(const void *a, const void *b) gbt_intvkey_cmp(const void *a, const void *b)
{ {
return DatumGetInt32 ( return DatumGetInt32(
DirectFunctionCall2 ( interval_cmp , DirectFunctionCall2(interval_cmp,
IntervalPGetDatum(((Nsrt *) a)->t) , IntervalPGetDatum(((Nsrt *) a)->t),
IntervalPGetDatum(((Nsrt *) b)->t) IntervalPGetDatum(((Nsrt *) b)->t)
) )
); );
} }
static double intr2num ( const Interval * i ) static double
intr2num(const Interval *i)
{ {
double ret = 0.0; double ret = 0.0;
struct pg_tm tm; struct pg_tm tm;
fsec_t fsec; fsec_t fsec;
interval2tm( *i, &tm, &fsec);
ret += ( tm.tm_year * 360.0 * 86400.0 ) ; interval2tm(*i, &tm, &fsec);
ret += ( tm.tm_mon * 12.0 * 86400.0 ) ; ret += (tm.tm_year * 360.0 * 86400.0);
ret += ( tm.tm_mday * 86400.0 ) ; ret += (tm.tm_mon * 12.0 * 86400.0);
ret += ( tm.tm_hour * 3600.0 ) ; ret += (tm.tm_mday * 86400.0);
ret += ( tm.tm_min * 60.0 ) ; ret += (tm.tm_hour * 3600.0);
ret += ( tm.tm_sec ) ; ret += (tm.tm_min * 60.0);
ret += ( fsec / 1000000.0 ); ret += (tm.tm_sec);
ret += (fsec / 1000000.0);
return ( ret );
return (ret);
} }
#define INTERVALSIZE 12 #define INTERVALSIZE 12
...@@ -106,17 +114,24 @@ gbt_intv_compress(PG_FUNCTION_ARGS) ...@@ -106,17 +114,24 @@ gbt_intv_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = entry; GISTENTRY *retval = entry;
if ( entry->leafkey || INTERVALSIZE != sizeof(Interval) ) {
char *r = ( char * ) palloc(2 * INTERVALSIZE); if (entry->leafkey || INTERVALSIZE != sizeof(Interval))
{
char *r = (char *) palloc(2 * INTERVALSIZE);
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
if ( entry->leafkey ) { if (entry->leafkey)
{
Interval *key = DatumGetIntervalP(entry->key); Interval *key = DatumGetIntervalP(entry->key);
memcpy( (void*) r , (void*)key, INTERVALSIZE);
memcpy( (void*)(r + INTERVALSIZE), (void*)key, INTERVALSIZE); memcpy((void *) r, (void *) key, INTERVALSIZE);
} else { memcpy((void *) (r + INTERVALSIZE), (void *) key, INTERVALSIZE);
intvKEY *key = ( intvKEY * ) DatumGetPointer(entry->key); }
else
{
intvKEY *key = (intvKEY *) DatumGetPointer(entry->key);
memcpy(r, &key->lower, INTERVALSIZE); memcpy(r, &key->lower, INTERVALSIZE);
memcpy(r + INTERVALSIZE, &key->upper, INTERVALSIZE); memcpy(r + INTERVALSIZE, &key->upper, INTERVALSIZE);
} }
...@@ -135,13 +150,14 @@ gbt_intv_decompress(PG_FUNCTION_ARGS) ...@@ -135,13 +150,14 @@ gbt_intv_decompress(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = entry; GISTENTRY *retval = entry;
if ( INTERVALSIZE != sizeof(Interval) ) { if (INTERVALSIZE != sizeof(Interval))
{
intvKEY *r = palloc(sizeof(intvKEY)); intvKEY *r = palloc(sizeof(intvKEY));
char *key = DatumGetPointer(entry->key); char *key = DatumGetPointer(entry->key);
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
memcpy( &r->lower, key, INTERVALSIZE); memcpy(&r->lower, key, INTERVALSIZE);
memcpy( &r->upper, key+ INTERVALSIZE, INTERVALSIZE); memcpy(&r->upper, key + INTERVALSIZE, INTERVALSIZE);
gistentryinit(*retval, PointerGetDatum(r), gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page, entry->rel, entry->page,
...@@ -157,14 +173,14 @@ gbt_intv_consistent(PG_FUNCTION_ARGS) ...@@ -157,14 +173,14 @@ gbt_intv_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Interval *query = PG_GETARG_INTERVAL_P(1); Interval *query = PG_GETARG_INTERVAL_P(1);
intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key); intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)query ,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -174,8 +190,9 @@ gbt_intv_union(PG_FUNCTION_ARGS) ...@@ -174,8 +190,9 @@ gbt_intv_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(intvKEY)); void *out = palloc(sizeof(intvKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(intvKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(intvKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -185,21 +202,24 @@ gbt_intv_penalty(PG_FUNCTION_ARGS) ...@@ -185,21 +202,24 @@ gbt_intv_penalty(PG_FUNCTION_ARGS)
intvKEY *origentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); intvKEY *origentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
double iorg[2], inew[2], res; double iorg[2],
inew[2],
res;
iorg[0] = intr2num ( &origentry->lower ); iorg[0] = intr2num(&origentry->lower);
iorg[1] = intr2num ( &origentry->upper ); iorg[1] = intr2num(&origentry->upper);
inew[0] = intr2num ( &newentry->lower ); inew[0] = intr2num(&newentry->lower);
inew[1] = intr2num ( &newentry->upper ); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( res + iorg[1] - iorg[0] ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -223,7 +243,6 @@ gbt_intv_same(PG_FUNCTION_ARGS) ...@@ -223,7 +243,6 @@ gbt_intv_same(PG_FUNCTION_ARGS)
intvKEY *b2 = (intvKEY *) PG_GETARG_POINTER(1); intvKEY *b2 = (intvKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -27,28 +27,33 @@ Datum gbt_macad_penalty(PG_FUNCTION_ARGS); ...@@ -27,28 +27,33 @@ Datum gbt_macad_penalty(PG_FUNCTION_ARGS);
Datum gbt_macad_same(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)));
} }
...@@ -57,9 +62,9 @@ gbt_macadkey_cmp(const void *a, const void *b) ...@@ -57,9 +62,9 @@ gbt_macadkey_cmp(const void *a, const void *b)
{ {
return DatumGetInt32( return DatumGetInt32(
DirectFunctionCall2( DirectFunctionCall2(
macaddr_cmp , macaddr_cmp,
PointerGetDatum (&((Nsrt *) a)->t[0]), PointerGetDatum(&((Nsrt *) a)->t[0]),
PointerGetDatum (&((Nsrt *) b)->t[0]) PointerGetDatum(&((Nsrt *) b)->t[0])
) )
); );
} }
...@@ -84,13 +89,15 @@ static const gbtree_ninfo tinfo = ...@@ -84,13 +89,15 @@ static const gbtree_ninfo tinfo =
static uint64 mac_2_uint64 ( macaddr * m ){ static uint64
unsigned char * mi = ( unsigned char * ) m; mac_2_uint64(macaddr *m)
{
unsigned char *mi = (unsigned char *) m;
uint64 res = 0; uint64 res = 0;
int i; int i;
for (i=0; i<6; i++ ){
res += ( ( (uint64) mi[i] ) << ( (uint64) ( (5-i)*8 ) ) ); for (i = 0; i < 6; i++)
} res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
return res; return res;
} }
...@@ -101,7 +108,8 @@ gbt_macad_compress(PG_FUNCTION_ARGS) ...@@ -101,7 +108,8 @@ gbt_macad_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -112,13 +120,14 @@ gbt_macad_consistent(PG_FUNCTION_ARGS) ...@@ -112,13 +120,14 @@ gbt_macad_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
macaddr *query = (macaddr *) PG_GETARG_POINTER(1); macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
macKEY *kkk = (macKEY *) DatumGetPointer(entry->key); macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -128,8 +137,9 @@ gbt_macad_union(PG_FUNCTION_ARGS) ...@@ -128,8 +137,9 @@ gbt_macad_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(macKEY)); void *out = palloc(sizeof(macKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(macKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -139,22 +149,24 @@ gbt_macad_penalty(PG_FUNCTION_ARGS) ...@@ -139,22 +149,24 @@ gbt_macad_penalty(PG_FUNCTION_ARGS)
macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
uint64 iorg[2], inew[2]; uint64 iorg[2],
inew[2];
uint64 res; uint64 res;
iorg[0] = mac_2_uint64 ( &origentry->lower ); iorg[0] = mac_2_uint64(&origentry->lower);
iorg[1] = mac_2_uint64 ( &origentry->upper ); iorg[1] = mac_2_uint64(&origentry->upper);
inew[0] = mac_2_uint64 ( &newentry->lower ); inew[0] = mac_2_uint64(&newentry->lower);
inew[1] = mac_2_uint64 ( &newentry->upper ); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( ( (double)res ) / ( (double)res + (double)iorg[1] - (double)iorg[0] ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -178,7 +190,6 @@ gbt_macad_same(PG_FUNCTION_ARGS) ...@@ -178,7 +190,6 @@ gbt_macad_same(PG_FUNCTION_ARGS)
macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1); macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -23,36 +23,42 @@ Datum gbt_numeric_same(PG_FUNCTION_ARGS); ...@@ -23,36 +23,42 @@ Datum gbt_numeric_same(PG_FUNCTION_ARGS);
/* define for comparison */ /* 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 return
( DatumGetInt32(DirectFunctionCall2(numeric_cmp,PointerGetDatum(a),PointerGetDatum(b) ) ) ); (DatumGetInt32(DirectFunctionCall2(numeric_cmp, PointerGetDatum(a), PointerGetDatum(b))));
} }
...@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo = ...@@ -77,10 +83,11 @@ static const gbtree_vinfo tinfo =
Datum Datum
gbt_numeric_compress (PG_FUNCTION_ARGS) gbt_numeric_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
} }
...@@ -90,22 +97,20 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS) ...@@ -90,22 +97,20 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ; GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) ); GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
void *qtst = ( void * ) DatumGetPointer ( PG_GETARG_DATUM(1) ); void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
void *query = ( void * ) DatumGetNumeric ( PG_GETARG_DATUM(1) ); void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE; bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable ( key ); GBT_VARKEY_R r = gbt_var_key_readable(key);
retval = gbt_var_consistent( &r, query, &strategy, GIST_LEAF(entry), &tinfo ); retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
if ( ktst != key ){ if (ktst != key)
pfree ( key ); pfree(key);
} if (qtst != query)
if ( qtst != query ){ pfree(query);
pfree ( query );
}
PG_RETURN_BOOL(retval); PG_RETURN_BOOL(retval);
} }
...@@ -115,8 +120,9 @@ Datum ...@@ -115,8 +120,9 @@ Datum
gbt_numeric_union(PG_FUNCTION_ARGS) gbt_numeric_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 * size = (int *) PG_GETARG_POINTER(1); int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
} }
...@@ -126,29 +132,34 @@ gbt_numeric_same(PG_FUNCTION_ARGS) ...@@ -126,29 +132,34 @@ gbt_numeric_same(PG_FUNCTION_ARGS)
Datum d1 = PG_GETARG_DATUM(0); Datum d1 = PG_GETARG_DATUM(0);
Datum d2 = PG_GETARG_DATUM(1); Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
} }
Datum Datum
gbt_numeric_penalty (PG_FUNCTION_ARGS) gbt_numeric_penalty(PG_FUNCTION_ARGS)
{ {
GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1); GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2); 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 *org = (GBT_VARKEY *) DatumGetPointer(o->key);
GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key); GBT_VARKEY *newe = (GBT_VARKEY *) DatumGetPointer(n->key);
Datum uni ; Datum uni;
GBT_VARKEY_R rk , ok, uk ; GBT_VARKEY_R rk,
ok,
uk;
rk = gbt_var_key_readable ( org ); rk = gbt_var_key_readable(org);
uni = PointerGetDatum( gbt_var_key_copy( &rk, TRUE ) ); uni = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
gbt_var_bin_union ( &uni , newe, &tinfo ); gbt_var_bin_union(&uni, newe, &tinfo);
ok = gbt_var_key_readable ( org ); ok = gbt_var_key_readable(org);
uk = gbt_var_key_readable ( (GBT_VARKEY *) DatumGetPointer(uni) ); uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
us = DatumGetNumeric(DirectFunctionCall2( us = DatumGetNumeric(DirectFunctionCall2(
numeric_sub, numeric_sub,
...@@ -156,7 +167,7 @@ gbt_numeric_penalty (PG_FUNCTION_ARGS) ...@@ -156,7 +167,7 @@ gbt_numeric_penalty (PG_FUNCTION_ARGS)
PointerGetDatum(uk.lower) PointerGetDatum(uk.lower)
)); ));
pfree ( DatumGetPointer(uni) ); pfree(DatumGetPointer(uni));
os = DatumGetNumeric(DirectFunctionCall2( os = DatumGetNumeric(DirectFunctionCall2(
numeric_sub, numeric_sub,
...@@ -170,48 +181,48 @@ gbt_numeric_penalty (PG_FUNCTION_ARGS) ...@@ -170,48 +181,48 @@ gbt_numeric_penalty (PG_FUNCTION_ARGS)
NumericGetDatum(os) NumericGetDatum(os)
)); ));
pfree ( os ); pfree(os);
if ( NUMERIC_IS_NAN( us ) ) if (NUMERIC_IS_NAN(us))
{ {
if ( NUMERIC_IS_NAN( os ) ) if (NUMERIC_IS_NAN(os))
{
*result = 0.0; *result = 0.0;
} else { else
*result = 1.0; *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 ; *result += FLT_MIN;
os = DatumGetNumeric(DirectFunctionCall2( os = DatumGetNumeric(DirectFunctionCall2(
numeric_div, numeric_div,
NumericGetDatum(ds), NumericGetDatum(ds),
NumericGetDatum(us) NumericGetDatum(us)
)); ));
*result += ( float4 ) DatumGetFloat8( DirectFunctionCall1( numeric_float8_no_overflow , NumericGetDatum(os) ) ); *result += (float4) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, NumericGetDatum(os)));
pfree ( os ); pfree(os);
} }
pfree ( nul ); pfree(nul);
} }
if ( *result > 0 ) if (*result > 0)
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree ( us ); pfree(us);
pfree ( ds ); pfree(ds);
PG_RETURN_POINTER( result ); PG_RETURN_POINTER(result);
} }
...@@ -221,7 +232,7 @@ gbt_numeric_picksplit(PG_FUNCTION_ARGS) ...@@ -221,7 +232,7 @@ gbt_numeric_picksplit(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit ( entryvec, v, &tinfo );
gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v); PG_RETURN_POINTER(v);
} }
...@@ -25,37 +25,40 @@ Datum gbt_oid_penalty(PG_FUNCTION_ARGS); ...@@ -25,37 +25,40 @@ Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
Datum gbt_oid_same(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 static int
gbt_oidkey_cmp(const void *a, const void *b) gbt_oidkey_cmp(const void *a, const void *b)
{ {
if ( *(Oid*)&(((Nsrt *) a)->t[0]) > *(Oid*)&(((Nsrt *) b)->t[0]) ){ if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
return 1; return 1;
} else else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
if ( *(Oid*)&(((Nsrt *) a)->t[0]) < *(Oid*)&(((Nsrt *) b)->t[0]) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -84,7 +87,8 @@ gbt_oid_compress(PG_FUNCTION_ARGS) ...@@ -84,7 +87,8 @@ gbt_oid_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -95,13 +99,14 @@ gbt_oid_consistent(PG_FUNCTION_ARGS) ...@@ -95,13 +99,14 @@ gbt_oid_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Oid query = PG_GETARG_OID(1); Oid query = PG_GETARG_OID(1);
oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key); oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -111,8 +116,9 @@ gbt_oid_union(PG_FUNCTION_ARGS) ...@@ -111,8 +116,9 @@ gbt_oid_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(oidKEY)); void *out = palloc(sizeof(oidKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -123,16 +129,17 @@ gbt_oid_penalty(PG_FUNCTION_ARGS) ...@@ -123,16 +129,17 @@ gbt_oid_penalty(PG_FUNCTION_ARGS)
oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); 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 ){ if (res > 0)
*result += FLT_MIN ; {
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) ); *result += FLT_MIN;
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *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);
...@@ -155,6 +162,6 @@ gbt_oid_same(PG_FUNCTION_ARGS) ...@@ -155,6 +162,6 @@ gbt_oid_same(PG_FUNCTION_ARGS)
oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1); oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -26,34 +26,40 @@ Datum gbt_text_same(PG_FUNCTION_ARGS); ...@@ -26,34 +26,40 @@ Datum gbt_text_same(PG_FUNCTION_ARGS);
/* define for comparison */ /* 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));
} }
...@@ -62,26 +68,26 @@ static int32 gbt_textcmp ( const bytea * a , const bytea * b ) ...@@ -62,26 +68,26 @@ static int32 gbt_textcmp ( const bytea * a , const bytea * b )
*/ */
static bytea * static bytea *
gbt_text_xfrm ( bytea * leaf ) gbt_text_xfrm(bytea *leaf)
{ {
bytea * out = leaf; bytea *out = leaf;
int32 ilen = VARSIZE (leaf) - VARHDRSZ; int32 ilen = VARSIZE(leaf) - VARHDRSZ;
int32 olen ; int32 olen;
char * sin; char *sin;
char * sou; char *sou;
sin = palloc(ilen + 1); sin = palloc(ilen + 1);
memcpy (sin, (void*) VARDATA(leaf) ,ilen ); memcpy(sin, (void *) VARDATA(leaf), ilen);
sin[ilen] = '\0'; sin[ilen] = '\0';
olen = strxfrm ( NULL, &sin[0], 0 ) + 1; olen = strxfrm(NULL, &sin[0], 0) + 1;
sou = palloc ( olen ); sou = palloc(olen);
olen = strxfrm ( sou , &sin[0] , olen ); olen = strxfrm(sou, &sin[0], olen);
olen += VARHDRSZ; olen += VARHDRSZ;
out = palloc ( olen + 1 ); out = palloc(olen + 1);
out->vl_len = olen+1; out->vl_len = olen + 1;
memcpy( (void*) VARDATA(out), sou, olen-VARHDRSZ ); memcpy((void *) VARDATA(out), sou, olen - VARHDRSZ);
((char*)out)[olen] = '\0'; ((char *) out)[olen] = '\0';
pfree(sou); pfree(sou);
pfree(sin); pfree(sin);
...@@ -90,16 +96,17 @@ gbt_text_xfrm ( bytea * leaf ) ...@@ -90,16 +96,17 @@ gbt_text_xfrm ( bytea * leaf )
} }
static GBT_VARKEY * gbt_text_l2n ( GBT_VARKEY * leaf ) static GBT_VARKEY *
gbt_text_l2n(GBT_VARKEY * leaf)
{ {
GBT_VARKEY *out = leaf ; GBT_VARKEY *out = leaf;
GBT_VARKEY_R r = gbt_var_key_readable ( leaf ); GBT_VARKEY_R r = gbt_var_key_readable(leaf);
bytea * o ; bytea *o;
o = gbt_text_xfrm ( r.lower ); o = gbt_text_xfrm(r.lower);
r.lower = r.upper = o; r.lower = r.upper = o;
out = gbt_var_key_copy ( &r , TRUE ); out = gbt_var_key_copy(&r, TRUE);
pfree(o); pfree(o);
return out; return out;
...@@ -132,36 +139,38 @@ static const gbtree_vinfo tinfo = ...@@ -132,36 +139,38 @@ static const gbtree_vinfo tinfo =
Datum Datum
gbt_text_compress (PG_FUNCTION_ARGS) gbt_text_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
PG_RETURN_POINTER ( gbt_var_compress( entry, &tinfo ) );
PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
} }
Datum Datum
gbt_bpchar_compress (PG_FUNCTION_ARGS) gbt_bpchar_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY * retval ; GISTENTRY *retval;
if (entry->leafkey) if (entry->leafkey)
{ {
Datum d = DirectFunctionCall1 ( rtrim1, entry->key ); Datum d = DirectFunctionCall1(rtrim1, entry->key);
GISTENTRY * trim = palloc(sizeof(GISTENTRY)); GISTENTRY *trim = palloc(sizeof(GISTENTRY));
gistentryinit(*trim, d , gistentryinit(*trim, d,
entry->rel, entry->page, entry->rel, entry->page,
entry->offset, VARSIZE(DatumGetPointer(d)), TRUE); entry->offset, VARSIZE(DatumGetPointer(d)), TRUE);
retval = gbt_var_compress( trim , &tinfo ) ; retval = gbt_var_compress(trim, &tinfo);
pfree ( trim ); pfree(trim);
pfree ( DatumGetPointer(d) ); pfree(DatumGetPointer(d));
} else }
else
retval = entry; retval = entry;
PG_RETURN_POINTER ( retval ); PG_RETURN_POINTER(retval);
} }
...@@ -170,30 +179,29 @@ Datum ...@@ -170,30 +179,29 @@ Datum
gbt_text_consistent(PG_FUNCTION_ARGS) gbt_text_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ; GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) ); GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
void *qtst = ( void * ) DatumGetPointer( PG_GETARG_DATUM(1) ); void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
void *query = ( void * ) DatumGetTextP ( PG_GETARG_DATUM(1) ); void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE; bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable ( key ); GBT_VARKEY_R r = gbt_var_key_readable(key);
if ( GIST_LEAF(entry) ) if (GIST_LEAF(entry))
retval = gbt_var_consistent(&r, query, &strategy, TRUE, &tinfo);
else
{ {
retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo ); bytea *q = gbt_text_xfrm((bytea *) query);
} else {
bytea * q = gbt_text_xfrm ( ( bytea * ) query ); retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo ); if (q != query)
if ( q != query )
pfree(q); pfree(q);
} }
if ( ktst != key ){ if (ktst != key)
pfree ( key ); pfree(key);
} if (qtst != query)
if ( qtst != query ){ pfree(query);
pfree ( query );
}
PG_RETURN_BOOL(retval); PG_RETURN_BOOL(retval);
} }
...@@ -203,33 +211,32 @@ Datum ...@@ -203,33 +211,32 @@ Datum
gbt_bpchar_consistent(PG_FUNCTION_ARGS) gbt_bpchar_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer ( entry->key ) ; GBT_VARKEY *ktst = (GBT_VARKEY *) DatumGetPointer(entry->key);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer ( PG_DETOAST_DATUM( entry->key ) ); GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
void *qtst = ( void * ) DatumGetPointer ( PG_GETARG_DATUM(1) ); void *qtst = (void *) DatumGetPointer(PG_GETARG_DATUM(1));
void *query = ( void * ) DatumGetPointer (PG_DETOAST_DATUM( PG_GETARG_DATUM(1) ) ); void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
void *trim = ( void * ) DatumGetPointer ( DirectFunctionCall1 ( rtrim1, PointerGetDatum ( query ) ) ) ; void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE; bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable ( key ); GBT_VARKEY_R r = gbt_var_key_readable(key);
if ( GIST_LEAF(entry) ) if (GIST_LEAF(entry))
retval = gbt_var_consistent(&r, trim, &strategy, TRUE, &tinfo);
else
{ {
retval = gbt_var_consistent( &r, trim , &strategy, TRUE, &tinfo ); bytea *q = gbt_text_xfrm((bytea *) trim);
} else {
bytea * q = gbt_text_xfrm ( ( bytea * ) trim ); retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo ); if (q != trim)
if ( q != trim )
pfree(q); pfree(q);
} }
pfree(trim); pfree(trim);
if ( ktst != key ){ if (ktst != key)
pfree ( key ); pfree(key);
} if (qtst != query)
if ( qtst != query ){ pfree(query);
pfree ( query );
}
PG_RETURN_BOOL(retval); PG_RETURN_BOOL(retval);
} }
...@@ -241,7 +248,8 @@ gbt_text_union(PG_FUNCTION_ARGS) ...@@ -241,7 +248,8 @@ gbt_text_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int32 *size = (int *) PG_GETARG_POINTER(1); int32 *size = (int *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_union ( entryvec , size , &tinfo ) );
PG_RETURN_POINTER(gbt_var_union(entryvec, size, &tinfo));
} }
...@@ -250,7 +258,8 @@ gbt_text_picksplit(PG_FUNCTION_ARGS) ...@@ -250,7 +258,8 @@ gbt_text_picksplit(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
gbt_var_picksplit ( entryvec, v, &tinfo );
gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v); PG_RETURN_POINTER(v);
} }
...@@ -260,7 +269,8 @@ gbt_text_same(PG_FUNCTION_ARGS) ...@@ -260,7 +269,8 @@ gbt_text_same(PG_FUNCTION_ARGS)
Datum d1 = PG_GETARG_DATUM(0); Datum d1 = PG_GETARG_DATUM(0);
Datum d2 = PG_GETARG_DATUM(1); Datum d2 = PG_GETARG_DATUM(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
PG_RETURN_POINTER( gbt_var_same ( result, d1 , d2 , &tinfo ));
PG_RETURN_POINTER(gbt_var_same(result, d1, d2, &tinfo));
} }
...@@ -268,8 +278,8 @@ Datum ...@@ -268,8 +278,8 @@ Datum
gbt_text_penalty(PG_FUNCTION_ARGS) gbt_text_penalty(PG_FUNCTION_ARGS)
{ {
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
GISTENTRY * o = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *o = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY * n = (GISTENTRY *) PG_GETARG_POINTER(1); GISTENTRY *n = (GISTENTRY *) PG_GETARG_POINTER(1);
PG_RETURN_POINTER( gbt_var_penalty ( result ,o , n, &tinfo ) );
}
PG_RETURN_POINTER(gbt_var_penalty(result, o, n, &tinfo));
}
...@@ -30,38 +30,43 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS); ...@@ -30,38 +30,43 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS);
Datum gbt_time_same(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( return DatumGetBool(
DirectFunctionCall2(time_gt,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(time_ge,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(time_eq,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(time_le,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) ) 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( return DatumGetBool(
DirectFunctionCall2(time_lt,TimeADTGetDatum( *((TimeADT*)a) ), TimeADTGetDatum( *((TimeADT*)b) ) ) DirectFunctionCall2(time_lt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
); );
} }
...@@ -70,12 +75,10 @@ static bool gbt_timelt (const void *a, const void *b) ...@@ -70,12 +75,10 @@ static bool gbt_timelt (const void *a, const void *b)
static int static int
gbt_timekey_cmp(const void *a, const void *b) gbt_timekey_cmp(const void *a, const void *b)
{ {
if ( gbt_timegt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){ if (gbt_timegt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1; return 1;
} else else if (gbt_timelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
if ( gbt_timelt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -104,7 +107,8 @@ gbt_time_compress(PG_FUNCTION_ARGS) ...@@ -104,7 +107,8 @@ gbt_time_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -122,7 +126,7 @@ gbt_timetz_compress(PG_FUNCTION_ARGS) ...@@ -122,7 +126,7 @@ gbt_timetz_compress(PG_FUNCTION_ARGS)
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
/* We are using the time + zone only to compress */ /* We are using the time + zone only to compress */
r->lower = r->upper = ( tz->time + tz->zone ) ; r->lower = r->upper = (tz->time + tz->zone);
gistentryinit(*retval, PointerGetDatum(r), gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page, entry->rel, entry->page,
entry->offset, sizeof(timeKEY), FALSE); entry->offset, sizeof(timeKEY), FALSE);
...@@ -137,17 +141,17 @@ Datum ...@@ -137,17 +141,17 @@ Datum
gbt_time_consistent(PG_FUNCTION_ARGS) gbt_time_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeADT query = PG_GETARG_TIMEADT( 1 ); TimeADT query = PG_GETARG_TIMEADT(1);
timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key); timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -155,17 +159,17 @@ Datum ...@@ -155,17 +159,17 @@ Datum
gbt_timetz_consistent(PG_FUNCTION_ARGS) gbt_timetz_consistent(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeTzADT *query = PG_GETARG_TIMETZADT_P( 1 ); TimeTzADT *query = PG_GETARG_TIMETZADT_P(1);
TimeADT qqq = query->time + query->zone ; TimeADT qqq = query->time + query->zone;
timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key); timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&qqq, &strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -175,8 +179,9 @@ gbt_time_union(PG_FUNCTION_ARGS) ...@@ -175,8 +179,9 @@ gbt_time_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(timeKEY)); void *out = palloc(sizeof(timeKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(timeKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -187,8 +192,10 @@ gbt_time_penalty(PG_FUNCTION_ARGS) ...@@ -187,8 +192,10 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
Interval *intr; Interval *intr;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
int64 res; int64 res;
#else #else
double res; double res;
#endif #endif
...@@ -213,15 +220,16 @@ gbt_time_penalty(PG_FUNCTION_ARGS) ...@@ -213,15 +220,16 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
*result = 0.0; *result = 0.0;
if ( res > 0 ){ if (res > 0)
{
intr = DatumGetIntervalP(DirectFunctionCall2( intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time, time_mi_time,
TimeADTGetDatum(origentry->upper), TimeADTGetDatum(origentry->upper),
TimeADTGetDatum(origentry->lower))); TimeADTGetDatum(origentry->lower)));
*result += FLT_MIN ; *result += FLT_MIN;
*result += (float) ( res / ( (double) ( res + intr->time + intr->month * (30 * 86400) ) ) ); *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree ( intr ); pfree(intr);
} }
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
...@@ -245,7 +253,6 @@ gbt_time_same(PG_FUNCTION_ARGS) ...@@ -245,7 +253,6 @@ gbt_time_same(PG_FUNCTION_ARGS)
timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1); timeKEY *b2 = (timeKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -29,38 +29,43 @@ Datum gbt_ts_penalty(PG_FUNCTION_ARGS); ...@@ -29,38 +29,43 @@ Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
Datum gbt_ts_same(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( return DatumGetBool(
DirectFunctionCall2(timestamp_gt,PointerGetDatum( a ), PointerGetDatum( b ) ) 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( return DatumGetBool(
DirectFunctionCall2(timestamp_ge,PointerGetDatum( a ), PointerGetDatum( b ) ) 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( return DatumGetBool(
DirectFunctionCall2(timestamp_eq,PointerGetDatum( a ), PointerGetDatum( b ) ) 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( return DatumGetBool(
DirectFunctionCall2(timestamp_le,PointerGetDatum( a ), PointerGetDatum( b ) ) 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( return DatumGetBool(
DirectFunctionCall2(timestamp_lt,PointerGetDatum( a ), PointerGetDatum( b ) ) DirectFunctionCall2(timestamp_lt, PointerGetDatum(a), PointerGetDatum(b))
); );
} }
...@@ -68,12 +73,10 @@ static bool gbt_tslt (const void *a, const void *b) ...@@ -68,12 +73,10 @@ static bool gbt_tslt (const void *a, const void *b)
static int static int
gbt_tskey_cmp(const void *a, const void *b) gbt_tskey_cmp(const void *a, const void *b)
{ {
if ( gbt_tsgt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){ if (gbt_tsgt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1; return 1;
} else else if (gbt_tslt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
if ( gbt_tslt( (void*)&(((Nsrt *) a)->t[0]) , (void*)&(((Nsrt *) b)->t[0]) ) ){
return -1; return -1;
}
return 0; return 0;
} }
...@@ -97,14 +100,16 @@ static const gbtree_ninfo tinfo = ...@@ -97,14 +100,16 @@ 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; *gmt = *ts;
DecodeSpecial(0, "gmt", &val); DecodeSpecial(0, "gmt", &val);
if ( ! TIMESTAMP_NOT_FINITE(*ts)) if (!TIMESTAMP_NOT_FINITE(*ts))
{ {
tz = val * 60; tz = val * 60;
...@@ -127,7 +132,8 @@ gbt_ts_compress(PG_FUNCTION_ARGS) ...@@ -127,7 +132,8 @@ gbt_ts_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval = NULL; GISTENTRY *retval = NULL;
PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
} }
...@@ -135,19 +141,19 @@ Datum ...@@ -135,19 +141,19 @@ Datum
gbt_tstz_compress(PG_FUNCTION_ARGS) gbt_tstz_compress(PG_FUNCTION_ARGS)
{ {
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval ; GISTENTRY *retval;
if (entry->leafkey) if (entry->leafkey)
{ {
tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY)); tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY));
TimestampTz ts = *(TimestampTz *) DatumGetPointer(entry->key); TimestampTz ts = *(TimestampTz *) DatumGetPointer(entry->key);
Timestamp gmt ; Timestamp gmt;
tstz_to_ts_gmt ( &gmt, &ts ); tstz_to_ts_gmt(&gmt, &ts);
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
r->lower = r->upper = gmt ; r->lower = r->upper = gmt;
gistentryinit(*retval, PointerGetDatum(r), gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page, entry->rel, entry->page,
entry->offset, sizeof(tsKEY), FALSE); entry->offset, sizeof(tsKEY), FALSE);
...@@ -155,7 +161,7 @@ gbt_tstz_compress(PG_FUNCTION_ARGS) ...@@ -155,7 +161,7 @@ gbt_tstz_compress(PG_FUNCTION_ARGS)
else else
retval = entry; retval = entry;
PG_RETURN_POINTER( retval ); PG_RETURN_POINTER(retval);
} }
...@@ -165,14 +171,14 @@ gbt_ts_consistent(PG_FUNCTION_ARGS) ...@@ -165,14 +171,14 @@ gbt_ts_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Timestamp *query = (Timestamp *) PG_GETARG_POINTER(1); Timestamp *query = (Timestamp *) PG_GETARG_POINTER(1);
tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key); tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ; key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY*) &kkk->upper ; key.upper = (GBT_NUMKEY *) & kkk->upper;
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)query,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -182,16 +188,16 @@ gbt_tstz_consistent(PG_FUNCTION_ARGS) ...@@ -182,16 +188,16 @@ gbt_tstz_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimestampTz *query = (Timestamp *) PG_GETARG_POINTER(1); TimestampTz *query = (Timestamp *) PG_GETARG_POINTER(1);
char *kkk = (char *) DatumGetPointer(entry->key); char *kkk = (char *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ; GBT_NUMKEY_R key;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
Timestamp qqq ; Timestamp qqq;
key.lower = (GBT_NUMKEY*) &kkk[0]; key.lower = (GBT_NUMKEY *) & kkk[0];
key.upper = (GBT_NUMKEY*) &kkk[MAXALIGN(tinfo.size)]; key.upper = (GBT_NUMKEY *) & kkk[MAXALIGN(tinfo.size)];
tstz_to_ts_gmt ( &qqq, query ); tstz_to_ts_gmt(&qqq, query);
PG_RETURN_BOOL( PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&qqq,&strategy,GIST_LEAF(entry),&tinfo) gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -201,8 +207,9 @@ gbt_ts_union(PG_FUNCTION_ARGS) ...@@ -201,8 +207,9 @@ gbt_ts_union(PG_FUNCTION_ARGS)
{ {
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
void *out = palloc(sizeof(tsKEY)); void *out = palloc(sizeof(tsKEY));
*(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY); *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
...@@ -214,8 +221,10 @@ gbt_ts_penalty(PG_FUNCTION_ARGS) ...@@ -214,8 +221,10 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2); float *result = (float *) PG_GETARG_POINTER(2);
Interval *intr; Interval *intr;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
int64 res; int64 res;
#else #else
double res; double res;
#endif #endif
...@@ -243,15 +252,16 @@ gbt_ts_penalty(PG_FUNCTION_ARGS) ...@@ -243,15 +252,16 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
*result = 0.0; *result = 0.0;
if ( res > 0 ){ if (res > 0)
{
intr = DatumGetIntervalP(DirectFunctionCall2( intr = DatumGetIntervalP(DirectFunctionCall2(
timestamp_mi, timestamp_mi,
TimestampGetDatum(origentry->upper), TimestampGetDatum(origentry->upper),
TimestampGetDatum(origentry->lower) TimestampGetDatum(origentry->lower)
)); ));
*result += FLT_MIN ; *result += FLT_MIN;
*result += (float) ( res / ( (double) ( res + intr->time + intr->month * (30 * 86400) ) ) ); *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree(intr); pfree(intr);
} }
...@@ -277,7 +287,6 @@ gbt_ts_same(PG_FUNCTION_ARGS) ...@@ -277,7 +287,6 @@ gbt_ts_same(PG_FUNCTION_ARGS)
tsKEY *b2 = (tsKEY *) PG_GETARG_POINTER(1); tsKEY *b2 = (tsKEY *) PG_GETARG_POINTER(1);
bool *result = (bool *) PG_GETARG_POINTER(2); bool *result = (bool *) PG_GETARG_POINTER(2);
*result = gbt_num_same ( (void*)b1, (void*)b2, &tinfo ); *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
} }
...@@ -3,55 +3,57 @@ ...@@ -3,55 +3,57 @@
#include "utils/date.h" #include "utils/date.h"
extern GISTENTRY * 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) if (entry->leafkey)
{ {
union { union
{
int16 i2; int16 i2;
int32 i4; int32 i4;
TimeADT ts; TimeADT ts;
DateADT dt; DateADT dt;
} v ; } v;
GBT_NUMKEY *r = ( GBT_NUMKEY * ) palloc(2 * tinfo->size ); GBT_NUMKEY *r = (GBT_NUMKEY *) palloc(2 * tinfo->size);
void *leaf = NULL; void *leaf = NULL;
switch ( tinfo->t ) switch (tinfo->t)
{ {
case gbt_t_int2 : case gbt_t_int2:
v.i2 = DatumGetInt16(entry->key); v.i2 = DatumGetInt16(entry->key);
leaf = &v.i2; leaf = &v.i2;
break; break;
case gbt_t_int4 : case gbt_t_int4:
v.i4 = DatumGetInt32(entry->key); v.i4 = DatumGetInt32(entry->key);
leaf = &v.i4; leaf = &v.i4;
break; break;
case gbt_t_oid : case gbt_t_oid:
v.i4 = DatumGetObjectId(entry->key); v.i4 = DatumGetObjectId(entry->key);
leaf = &v.i4; leaf = &v.i4;
break; break;
case gbt_t_time : case gbt_t_time:
v.ts = DatumGetTimeADT(entry->key); v.ts = DatumGetTimeADT(entry->key);
leaf = &v.ts; leaf = &v.ts;
break; break;
case gbt_t_date : case gbt_t_date:
v.dt = DatumGetDateADT(entry->key); v.dt = DatumGetDateADT(entry->key);
leaf = &v.dt; leaf = &v.dt;
break; break;
default : default:
leaf = DatumGetPointer(entry->key); leaf = DatumGetPointer(entry->key);
} }
memset ( (void*) &r[0] , 0 , 2*tinfo->size ); memset((void *) &r[0], 0, 2 * tinfo->size);
memcpy ( (void*) &r[0] , leaf, tinfo->size ); memcpy((void *) &r[0], leaf, tinfo->size);
memcpy ( (void*) &r[tinfo->size] , leaf, tinfo->size ); memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
retval = palloc(sizeof(GISTENTRY)); retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page, gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
entry->offset,( 2 * tinfo->size ), FALSE); entry->offset, (2 * tinfo->size), FALSE);
} else }
else
retval = entry; retval = entry;
return retval; return retval;
...@@ -65,31 +67,32 @@ gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry , const gbtree_ninfo * ...@@ -65,31 +67,32 @@ gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry , const gbtree_ninfo *
*/ */
extern void * 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, int i,
numranges; numranges;
GBT_NUMKEY * cur ; GBT_NUMKEY *cur;
GBT_NUMKEY_R o, c; GBT_NUMKEY_R o,
c;
numranges = entryvec->n; numranges = entryvec->n;
cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key)); cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
o.lower = &((GBT_NUMKEY *)out)[0]; o.lower = &((GBT_NUMKEY *) out)[0];
o.upper = &((GBT_NUMKEY *)out)[tinfo->size]; 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++) for (i = 1; i < numranges; i++)
{ {
cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key)); cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
c.lower = &cur[0]; c.lower = &cur[0];
c.upper = &cur[tinfo->size]; c.upper = &cur[tinfo->size];
if ( (*tinfo->f_gt)(o.lower, c.lower) ) /* out->lower > cur->lower */ if ((*tinfo->f_gt) (o.lower, c.lower)) /* out->lower > cur->lower */
memcpy( (void* ) o.lower, (void*) c.lower, tinfo->size ); memcpy((void *) o.lower, (void *) c.lower, tinfo->size);
if ( (*tinfo->f_lt)(o.upper, c.upper) ) /* out->upper < cur->upper */ if ((*tinfo->f_lt) (o.upper, c.upper)) /* out->upper < cur->upper */
memcpy( (void*) o.upper, (void*) c.upper, tinfo->size ); memcpy((void *) o.upper, (void *) c.upper, tinfo->size);
} }
return out; return out;
...@@ -101,19 +104,21 @@ gbt_num_union( GBT_NUMKEY * out, const GistEntryVector * entryvec, const gbtree_ ...@@ -101,19 +104,21 @@ gbt_num_union( GBT_NUMKEY * out, const GistEntryVector * entryvec, const gbtree_
** The GiST same method for numerical values ** 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.lower = &(((GBT_NUMKEY *) a)[0]);
b1.upper = &(((GBT_NUMKEY *)a)[tinfo->size]); b1.upper = &(((GBT_NUMKEY *) a)[tinfo->size]);
b2.lower = &(((GBT_NUMKEY *)b)[0]); b2.lower = &(((GBT_NUMKEY *) b)[0]);
b2.upper = &(((GBT_NUMKEY *)b)[tinfo->size]); b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
if ( if (
(*tinfo->f_eq)( b1.lower, b2.lower) && (*tinfo->f_eq) (b1.lower, b2.lower) &&
(*tinfo->f_eq)( b1.upper, b2.upper) (*tinfo->f_eq) (b1.upper, b2.upper)
) )
return TRUE; return TRUE;
return FALSE; return FALSE;
...@@ -122,7 +127,7 @@ extern bool gbt_num_same ( const GBT_NUMKEY * a, const GBT_NUMKEY * b, const gbt ...@@ -122,7 +127,7 @@ extern bool gbt_num_same ( const GBT_NUMKEY * a, const GBT_NUMKEY * b, const gbt
extern void 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; GBT_NUMKEY_R rd;
...@@ -133,18 +138,19 @@ gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo ) ...@@ -133,18 +138,19 @@ gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo )
if (!DatumGetPointer(*u)) if (!DatumGetPointer(*u))
{ {
*u = PointerGetDatum(palloc(2 * tinfo->size)); *u = PointerGetDatum(palloc(2 * tinfo->size));
memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) , (void*)rd.lower , 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 ); memcpy((void *) &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]), (void *) rd.upper, tinfo->size);
} }
else else
{ {
GBT_NUMKEY_R ur ; GBT_NUMKEY_R ur;
ur.lower = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) ;
ur.upper = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[tinfo->size]) ; ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]);
if ( (*tinfo->f_gt)((void*)ur.lower, (void*)rd.lower) ) ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]);
memcpy( (void*) ur.lower, (void*) rd.lower, tinfo->size ); if ((*tinfo->f_gt) ((void *) ur.lower, (void *) rd.lower))
if ( (*tinfo->f_lt)((void*)ur.upper, (void*)rd.upper) ) memcpy((void *) ur.lower, (void *) rd.lower, tinfo->size);
memcpy( (void*) ur.upper, (void*) rd.upper, tinfo->size ); if ((*tinfo->f_lt) ((void *) ur.upper, (void *) rd.upper))
memcpy((void *) ur.upper, (void *) rd.upper, tinfo->size);
} }
} }
...@@ -157,8 +163,8 @@ gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo ) ...@@ -157,8 +163,8 @@ gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , const gbtree_ninfo * tinfo )
extern bool extern bool
gbt_num_consistent( gbt_num_consistent(
const GBT_NUMKEY_R * key, const GBT_NUMKEY_R * key,
const void * query, const void *query,
const StrategyNumber * strategy, const StrategyNumber *strategy,
bool is_leaf, bool is_leaf,
const gbtree_ninfo * tinfo const gbtree_ninfo * tinfo
) )
...@@ -169,28 +175,28 @@ gbt_num_consistent( ...@@ -169,28 +175,28 @@ gbt_num_consistent(
switch (*strategy) switch (*strategy)
{ {
case BTLessEqualStrategyNumber: case BTLessEqualStrategyNumber:
retval = (*tinfo->f_ge)(query, key->lower); retval = (*tinfo->f_ge) (query, key->lower);
break; break;
case BTLessStrategyNumber: case BTLessStrategyNumber:
if ( is_leaf ) if (is_leaf)
retval = (*tinfo->f_gt)(query, key->lower); retval = (*tinfo->f_gt) (query, key->lower);
else else
retval = (*tinfo->f_ge)(query, key->lower); retval = (*tinfo->f_ge) (query, key->lower);
break; break;
case BTEqualStrategyNumber: case BTEqualStrategyNumber:
if ( is_leaf ) if (is_leaf)
retval = (*tinfo->f_eq)(query, key->lower); retval = (*tinfo->f_eq) (query, key->lower);
else else
retval = (*tinfo->f_le)(key->lower, query) && (*tinfo->f_le)(query, key->upper ); retval = (*tinfo->f_le) (key->lower, query) && (*tinfo->f_le) (query, key->upper);
break; break;
case BTGreaterStrategyNumber: case BTGreaterStrategyNumber:
if ( is_leaf ) if (is_leaf)
retval = (*tinfo->f_lt)(query, key->upper); retval = (*tinfo->f_lt) (query, key->upper);
else else
retval = (*tinfo->f_le)(query, key->upper); retval = (*tinfo->f_le) (query, key->upper);
break; break;
case BTGreaterEqualStrategyNumber: case BTGreaterEqualStrategyNumber:
retval = (*tinfo->f_le)(query, key->upper); retval = (*tinfo->f_le) (query, key->upper);
break; break;
default: default:
retval = FALSE; retval = FALSE;
...@@ -201,15 +207,15 @@ gbt_num_consistent( ...@@ -201,15 +207,15 @@ gbt_num_consistent(
GIST_SPLITVEC * GIST_SPLITVEC *
gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_ninfo * tinfo ) const gbtree_ninfo * tinfo)
{ {
OffsetNumber i, OffsetNumber i,
maxoff = entryvec->n - 1; maxoff = entryvec->n - 1;
Nsrt *arr; Nsrt *arr;
int nbytes; int nbytes;
arr = (Nsrt *) palloc((maxoff+1) * sizeof(Nsrt)); arr = (Nsrt *) palloc((maxoff + 1) * sizeof(Nsrt));
nbytes = (maxoff + 2) * sizeof(OffsetNumber); nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes);
...@@ -225,7 +231,7 @@ gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, ...@@ -225,7 +231,7 @@ gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v,
arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key)); arr[i].t = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
arr[i].i = i; arr[i].i = i;
} }
qsort ( (void*) &arr[FirstOffsetNumber], maxoff-FirstOffsetNumber+1,sizeof(Nsrt), tinfo->f_cmp ); qsort((void *) &arr[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, sizeof(Nsrt), tinfo->f_cmp);
/* We do simply create two parts */ /* We do simply create two parts */
......
...@@ -4,7 +4,8 @@ typedef char GBT_NUMKEY; ...@@ -4,7 +4,8 @@ typedef char GBT_NUMKEY;
/* Better readable key */ /* Better readable key */
typedef struct typedef struct
{ {
const GBT_NUMKEY * lower, * upper; const GBT_NUMKEY *lower,
*upper;
} GBT_NUMKEY_R; } GBT_NUMKEY_R;
...@@ -12,7 +13,7 @@ typedef struct ...@@ -12,7 +13,7 @@ typedef struct
typedef struct typedef struct
{ {
int i; int i;
GBT_NUMKEY * t; GBT_NUMKEY *t;
} Nsrt; } Nsrt;
...@@ -23,17 +24,17 @@ typedef struct ...@@ -23,17 +24,17 @@ typedef struct
/* Attribs */ /* Attribs */
enum gbtree_type t ; /* data type */ enum gbtree_type t; /* data type */
int32 size ; /* size of type , 0 means variable */ int32 size; /* size of type , 0 means variable */
/* Methods */ /* Methods */
bool (*f_gt) ( const void * , const void * ); /* greater then */ bool (*f_gt) (const void *, const void *); /* greater then */
bool (*f_ge) ( const void * , const void * ); /* greater equal */ bool (*f_ge) (const void *, const void *); /* greater equal */
bool (*f_eq) ( const void * , const void * ); /* equal */ bool (*f_eq) (const void *, const void *); /* equal */
bool (*f_le) ( const void * , const void * ); /* less equal */ bool (*f_le) (const void *, const void *); /* less equal */
bool (*f_lt) ( const void * , const void * ); /* less then */ bool (*f_lt) (const void *, const void *); /* less then */
int (*f_cmp) ( const void * , const void * ); /* key compare function */ int (*f_cmp) (const void *, const void *); /* key compare function */
} gbtree_ninfo; } gbtree_ninfo;
...@@ -52,22 +53,22 @@ typedef struct ...@@ -52,22 +53,22 @@ typedef struct
extern bool gbt_num_consistent( const GBT_NUMKEY_R * key , const void * query, extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
const StrategyNumber * strategy , bool is_leaf, const StrategyNumber *strategy, bool is_leaf,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
extern GIST_SPLITVEC *gbt_num_picksplit ( const GistEntryVector *entryvec, GIST_SPLITVEC *v, extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
extern GISTENTRY *gbt_num_compress( GISTENTRY *retval , GISTENTRY *entry , extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
extern void *gbt_num_union ( GBT_NUMKEY * out, const GistEntryVector * entryvec, extern void *gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
extern bool gbt_num_same ( const GBT_NUMKEY * a, const GBT_NUMKEY * b, extern bool gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
extern void gbt_num_bin_union(Datum * u , GBT_NUMKEY * e , extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY * e,
const gbtree_ninfo * tinfo ); const gbtree_ninfo * tinfo);
This diff is collapsed.
...@@ -5,15 +5,16 @@ typedef bytea GBT_VARKEY; ...@@ -5,15 +5,16 @@ typedef bytea GBT_VARKEY;
/* Better readable key */ /* Better readable key */
typedef struct typedef struct
{ {
bytea * lower, * upper; bytea *lower,
*upper;
} GBT_VARKEY_R; } GBT_VARKEY_R;
/* used for key sorting */ /* used for key sorting */
typedef struct typedef struct
{ {
int i ; int i;
GBT_VARKEY * t ; GBT_VARKEY *t;
} Vsrt ; } Vsrt;
/* /*
type description type description
...@@ -25,43 +26,43 @@ typedef struct ...@@ -25,43 +26,43 @@ typedef struct
/* Attribs */ /* Attribs */
enum gbtree_type t ; /* data type */ enum gbtree_type t; /* data type */
bool str ; /* true, if string ( else binary ) */ bool str; /* true, if string ( else binary ) */
bool trnc ; /* truncate (=compress) key */ bool trnc; /* truncate (=compress) key */
/* Methods */ /* Methods */
bool (*f_gt) ( const void * , const void * ); /* greater then */ bool (*f_gt) (const void *, const void *); /* greater then */
bool (*f_ge) ( const void * , const void * ); /* greater equal */ bool (*f_ge) (const void *, const void *); /* greater equal */
bool (*f_eq) ( const void * , const void * ); /* equal */ bool (*f_eq) (const void *, const void *); /* equal */
bool (*f_le) ( const void * , const void * ); /* less equal */ bool (*f_le) (const void *, const void *); /* less equal */
bool (*f_lt) ( const void * , const void * ); /* less then */ bool (*f_lt) (const void *, const void *); /* less then */
int32 (*f_cmp) ( const bytea * , const bytea * ); /* node compare */ int32 (*f_cmp) (const bytea *, const bytea *); /* node compare */
GBT_VARKEY* (*f_l2n) ( GBT_VARKEY * ); /* convert leaf to node */ GBT_VARKEY *(*f_l2n) (GBT_VARKEY *); /* convert leaf to node */
} gbtree_vinfo; } 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 , extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
extern bool gbt_var_same ( bool * result, const Datum d1 , const Datum d2 , extern bool gbt_var_same(bool *result, const Datum d1, const Datum d2,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
extern float *gbt_var_penalty ( float * res , const GISTENTRY * o , const GISTENTRY * n, extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
extern bool gbt_var_consistent( GBT_VARKEY_R * key , const void * query, extern bool gbt_var_consistent(GBT_VARKEY_R * key, const void *query,
const StrategyNumber * strategy , bool is_leaf, const StrategyNumber *strategy, bool is_leaf,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
extern GIST_SPLITVEC *gbt_var_picksplit ( const GistEntryVector *entryvec, GIST_SPLITVEC *v, extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
extern void gbt_var_bin_union ( Datum * u , GBT_VARKEY * e , extern void gbt_var_bin_union(Datum *u, GBT_VARKEY * e,
const gbtree_vinfo * tinfo ); const gbtree_vinfo * tinfo);
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
static int64 static int64
get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK); get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK);
static char * static char *
psnprintf(size_t len, const char *fmt,...) psnprintf(size_t len, const char *fmt,...)
...@@ -50,6 +50,7 @@ database_size(PG_FUNCTION_ARGS) ...@@ -50,6 +50,7 @@ database_size(PG_FUNCTION_ARGS)
Oid dbid; Oid dbid;
int64 totalsize; int64 totalsize;
#ifdef SYMLINK #ifdef SYMLINK
Relation dbrel; Relation dbrel;
HeapScanDesc scan; HeapScanDesc scan;
...@@ -69,10 +70,11 @@ database_size(PG_FUNCTION_ARGS) ...@@ -69,10 +70,11 @@ database_size(PG_FUNCTION_ARGS)
totalsize = 0; totalsize = 0;
while((tuple = heap_getnext(scan, ForwardScanDirection))) while ((tuple = heap_getnext(scan, ForwardScanDirection)))
{ {
Oid spcid = HeapTupleGetOid(tuple); Oid spcid = HeapTupleGetOid(tuple);
if(spcid != GLOBALTABLESPACE_OID)
if (spcid != GLOBALTABLESPACE_OID)
totalsize += get_tablespace_size(dbid, spcid, true); totalsize += get_tablespace_size(dbid, spcid, true);
} }
heap_endscan(scan); heap_endscan(scan);
...@@ -104,7 +106,7 @@ get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK) ...@@ -104,7 +106,7 @@ get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK)
dirdesc = AllocateDir(dbpath); dirdesc = AllocateDir(dbpath);
if (!dirdesc) if (!dirdesc)
{ {
if(baddirOK) if (baddirOK)
return 0; return 0;
else else
ereport(ERROR, ereport(ERROR,
......
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
/* /*
* $Revision: 1.2 $ * $Revision: 1.3 $
* $Id: dmetaphone.c,v 1.2 2004/08/20 19:48:14 momjian Exp $ * $Id: dmetaphone.c,v 1.3 2004/08/29 05:06:35 momjian Exp $
*/ */
...@@ -109,7 +109,6 @@ The remaining code is authored by Andrew Dunstan <amdunstan@ncshp.org> and ...@@ -109,7 +109,6 @@ The remaining code is authored by Andrew Dunstan <amdunstan@ncshp.org> and
/* turn off assertions for embedded function */ /* turn off assertions for embedded function */
#define NDEBUG #define NDEBUG
#endif #endif
#include <stdio.h> #include <stdio.h>
...@@ -124,7 +123,7 @@ extern Datum dmetaphone_alt(PG_FUNCTION_ARGS); ...@@ -124,7 +123,7 @@ extern Datum dmetaphone_alt(PG_FUNCTION_ARGS);
/* prototype for the main function we got from the perl module */ /* prototype for the main function we got from the perl module */
static void static void
DoubleMetaphone(char *, char **); DoubleMetaphone(char *, char **);
#ifndef DMETAPHONE_MAIN #ifndef DMETAPHONE_MAIN
...@@ -138,37 +137,41 @@ PG_FUNCTION_INFO_V1(dmetaphone); ...@@ -138,37 +137,41 @@ PG_FUNCTION_INFO_V1(dmetaphone);
Datum Datum
dmetaphone(PG_FUNCTION_ARGS) dmetaphone(PG_FUNCTION_ARGS)
{ {
text * arg, * result; text *arg,
int alen, rsize; *result;
char * aptr, *codes[2], * code, * rptr; int alen,
rsize;
char *aptr,
*codes[2],
*code,
*rptr;
#ifdef DMETAPHONE_NOSTRICT #ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
PG_RETURNNULL(); PG_RETURNNULL();
#endif #endif
arg = PG_GETARG_TEXT_P(0); arg = PG_GETARG_TEXT_P(0);
alen = VARSIZE(arg)-VARHDRSZ; alen = VARSIZE(arg) - VARHDRSZ;
/* /*
* Postgres' string values might not have trailing nuls. * Postgres' string values might not have trailing nuls. The VARSIZE
* The VARSIZE will not include the nul in any case * will not include the nul in any case so we copy things out and add
* so we copy things out and add a trailing nul. * a trailing nul. When we copy back we ignore the nul (and we don't
* When we copy back we ignore the nul * make space for it).
* (and we don't make space for it).
*/ */
aptr = palloc(alen+1); aptr = palloc(alen + 1);
memcpy(aptr,VARDATA(arg),alen); memcpy(aptr, VARDATA(arg), alen);
aptr[alen]=0; aptr[alen] = 0;
DoubleMetaphone(aptr,codes); DoubleMetaphone(aptr, codes);
code = codes[0]; code = codes[0];
if (!code) if (!code)
code = ""; code = "";
rsize = VARHDRSZ + strlen(code) ; rsize = VARHDRSZ + strlen(code);
result = (text *) palloc(rsize); result = (text *) palloc(rsize);
memset(result,0,rsize); memset(result, 0, rsize);
rptr = VARDATA(result); rptr = VARDATA(result);
memcpy(rptr,code,strlen(code)); memcpy(rptr, code, strlen(code));
VARATT_SIZEP(result) = rsize; VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
} }
...@@ -183,28 +186,33 @@ PG_FUNCTION_INFO_V1(dmetaphone_alt); ...@@ -183,28 +186,33 @@ PG_FUNCTION_INFO_V1(dmetaphone_alt);
Datum Datum
dmetaphone_alt(PG_FUNCTION_ARGS) dmetaphone_alt(PG_FUNCTION_ARGS)
{ {
text * arg, * result; text *arg,
int alen, rsize; *result;
char * aptr, * codes[2], * code, * rptr; int alen,
rsize;
char *aptr,
*codes[2],
*code,
*rptr;
#ifdef DMETAPHONE_NOSTRICT #ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
PG_RETURNNULL(); PG_RETURNNULL();
#endif #endif
arg = PG_GETARG_TEXT_P(0); arg = PG_GETARG_TEXT_P(0);
alen = VARSIZE(arg)-VARHDRSZ; alen = VARSIZE(arg) - VARHDRSZ;
aptr = palloc(alen+1); aptr = palloc(alen + 1);
memcpy(aptr,VARDATA(arg),alen); memcpy(aptr, VARDATA(arg), alen);
aptr[alen]=0; aptr[alen] = 0;
DoubleMetaphone(aptr,codes); DoubleMetaphone(aptr, codes);
code = codes[1]; code = codes[1];
if (!code) if (!code)
code = ""; code = "";
rsize = VARHDRSZ + strlen(code) ; rsize = VARHDRSZ + strlen(code);
result = (text *) palloc(rsize); result = (text *) palloc(rsize);
memset(result,0,rsize); memset(result, 0, rsize);
rptr = VARDATA(result); rptr = VARDATA(result);
memcpy(rptr,code,strlen(code)); memcpy(rptr, code, strlen(code));
VARATT_SIZEP(result) = rsize; VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
} }
...@@ -240,7 +248,6 @@ dmetaphone_alt(PG_FUNCTION_ARGS) ...@@ -240,7 +248,6 @@ dmetaphone_alt(PG_FUNCTION_ARGS)
(v = (t*)realloc((v),((n)*sizeof(t)))) (v = (t*)realloc((v),((n)*sizeof(t))))
#define META_FREE(x) free((x)) #define META_FREE(x) free((x))
#endif /* defined DMETAPHONE_MAIN */ #endif /* defined DMETAPHONE_MAIN */
...@@ -254,7 +261,8 @@ typedef struct ...@@ -254,7 +261,8 @@ typedef struct
int bufsize; int bufsize;
int free_string_on_destroy; int free_string_on_destroy;
} }
metastring;
metastring;
/* /*
* remaining perl module funcs unchanged except for declaring them static * remaining perl module funcs unchanged except for declaring them static
...@@ -269,7 +277,7 @@ NewMetaString(char *init_str) ...@@ -269,7 +277,7 @@ NewMetaString(char *init_str)
char empty_string[] = ""; char empty_string[] = "";
META_MALLOC(s, 1, metastring); META_MALLOC(s, 1, metastring);
assert( s != NULL ); assert(s != NULL);
if (init_str == NULL) if (init_str == NULL)
init_str = empty_string; init_str = empty_string;
...@@ -278,7 +286,7 @@ NewMetaString(char *init_str) ...@@ -278,7 +286,7 @@ NewMetaString(char *init_str)
s->bufsize = s->length + 7; s->bufsize = s->length + 7;
META_MALLOC(s->str, s->bufsize, char); META_MALLOC(s->str, s->bufsize, char);
assert( s->str != NULL ); assert(s->str != NULL);
strncpy(s->str, init_str, s->length + 1); strncpy(s->str, init_str, s->length + 1);
s->free_string_on_destroy = 1; s->free_string_on_destroy = 1;
...@@ -304,7 +312,7 @@ static void ...@@ -304,7 +312,7 @@ static void
IncreaseBuffer(metastring * s, int chars_needed) IncreaseBuffer(metastring * s, int chars_needed)
{ {
META_REALLOC(s->str, (s->bufsize + chars_needed + 10), char); META_REALLOC(s->str, (s->bufsize + chars_needed + 10), char);
assert( s->str != NULL ); assert(s->str != NULL);
s->bufsize = s->bufsize + chars_needed + 10; s->bufsize = s->bufsize + chars_needed + 10;
} }
...@@ -315,9 +323,7 @@ MakeUpper(metastring * s) ...@@ -315,9 +323,7 @@ MakeUpper(metastring * s)
char *i; char *i;
for (i = s->str; *i; i++) for (i = s->str; *i; i++)
{
*i = toupper(*i); *i = toupper(*i);
}
} }
...@@ -330,8 +336,8 @@ IsVowel(metastring * s, int pos) ...@@ -330,8 +336,8 @@ IsVowel(metastring * s, int pos)
return 0; return 0;
c = *(s->str + pos); c = *(s->str + pos);
if ((c == 'A') || (c == 'E') || (c == 'I') || (c =='O') || if ((c == 'A') || (c == 'E') || (c == 'I') || (c == 'O') ||
(c =='U') || (c == 'Y')) (c == 'U') || (c == 'Y'))
return 1; return 1;
return 0; return 0;
...@@ -378,7 +384,7 @@ SetAt(metastring * s, int pos, char c) ...@@ -378,7 +384,7 @@ SetAt(metastring * s, int pos, char c)
Caveats: the START value is 0 based Caveats: the START value is 0 based
*/ */
static int static int
StringAt(metastring * s, int start, int length, ...) StringAt(metastring * s, int start, int length,...)
{ {
char *test; char *test;
char *pos; char *pos;
...@@ -414,9 +420,7 @@ MetaphAdd(metastring * s, char *new_str) ...@@ -414,9 +420,7 @@ MetaphAdd(metastring * s, char *new_str)
add_length = strlen(new_str); add_length = strlen(new_str);
if ((s->length + add_length) > (s->bufsize - 1)) if ((s->length + add_length) > (s->bufsize - 1))
{
IncreaseBuffer(s, add_length); IncreaseBuffer(s, add_length);
}
strcat(s->str, new_str); strcat(s->str, new_str);
s->length += add_length; s->length += add_length;
...@@ -574,8 +578,10 @@ DoubleMetaphone(char *str, char **codes) ...@@ -574,8 +578,10 @@ DoubleMetaphone(char *str, char **codes)
|| ((StringAt(original, (current - 1), 1, || ((StringAt(original, (current - 1), 1,
"A", "O", "U", "E", "") "A", "O", "U", "E", "")
|| (current == 0)) || (current == 0))
/* e.g., 'wachtler', 'wechsler',
but not 'tichner' */ /*
* e.g., 'wachtler', 'wechsler', but not 'tichner'
*/
&& StringAt(original, (current + 2), 1, "L", "R", && StringAt(original, (current + 2), 1, "L", "R",
"N", "M", "B", "H", "F", "V", "W", "N", "M", "B", "H", "F", "V", "W",
" ", ""))) " ", "")))
...@@ -696,8 +702,7 @@ DoubleMetaphone(char *str, char **codes) ...@@ -696,8 +702,7 @@ DoubleMetaphone(char *str, char **codes)
/* name sent in 'mac caffrey', 'mac gregor */ /* name sent in 'mac caffrey', 'mac gregor */
if (StringAt(original, (current + 1), 2, " C", " Q", " G", "")) if (StringAt(original, (current + 1), 2, " C", " Q", " G", ""))
current += 3; current += 3;
else else if (StringAt(original, (current + 1), 1, "C", "K", "Q", "")
if (StringAt(original, (current + 1), 1, "C", "K", "Q", "")
&& !StringAt(original, (current + 1), 2, && !StringAt(original, (current + 1), 2,
"CE", "CI", "")) "CE", "CI", ""))
current += 2; current += 2;
...@@ -780,8 +785,11 @@ DoubleMetaphone(char *str, char **codes) ...@@ -780,8 +785,11 @@ DoubleMetaphone(char *str, char **codes)
break; break;
} }
} }
/* Parker's rule (with some further refinements) -
e.g., 'hugh' */ /*
* Parker's rule (with some further refinements) -
* e.g., 'hugh'
*/
if ( if (
((current > 1) ((current > 1)
&& StringAt(original, (current - 2), 1, && StringAt(original, (current - 2), 1,
...@@ -800,8 +808,10 @@ DoubleMetaphone(char *str, char **codes) ...@@ -800,8 +808,10 @@ DoubleMetaphone(char *str, char **codes)
} }
else else
{ {
/* e.g., 'laugh', 'McLaughlin', 'cough', /*
'gough', 'rough', 'tough' */ * e.g., 'laugh', 'McLaughlin', 'cough', 'gough',
* 'rough', 'tough'
*/
if ((current > 2) if ((current > 2)
&& (GetAt(original, current - 1) == 'U') && (GetAt(original, current - 1) == 'U')
&& StringAt(original, (current - 3), 1, "C", && StringAt(original, (current - 3), 1, "C",
...@@ -939,7 +949,8 @@ DoubleMetaphone(char *str, char **codes) ...@@ -939,7 +949,8 @@ DoubleMetaphone(char *str, char **codes)
MetaphAdd(secondary, "H"); MetaphAdd(secondary, "H");
current += 2; current += 2;
} }
else /* also takes care of 'HH' */ else
/* also takes care of 'HH' */
current += 1; current += 1;
break; break;
...@@ -1174,10 +1185,11 @@ DoubleMetaphone(char *str, char **codes) ...@@ -1174,10 +1185,11 @@ DoubleMetaphone(char *str, char **codes)
break; break;
} }
/* german & anglicisations, e.g. 'smith' match 'schmidt', /*
'snider' match 'schneider' * german & anglicisations, e.g. 'smith' match 'schmidt',
also, -sz- in slavic language altho in hungarian it is * 'snider' match 'schneider' also, -sz- in slavic
pronounced 's' */ * language altho in hungarian it is pronounced 's'
*/
if (((current == 0) if (((current == 0)
&& StringAt(original, (current + 1), 1, && StringAt(original, (current + 1), 1,
"M", "N", "L", "W", "")) "M", "N", "L", "W", ""))
...@@ -1428,8 +1440,11 @@ DoubleMetaphone(char *str, char **codes) ...@@ -1428,8 +1440,11 @@ DoubleMetaphone(char *str, char **codes)
default: default:
current += 1; current += 1;
} }
/* printf("PRIMARY: %s\n", primary->str);
printf("SECONDARY: %s\n", secondary->str); */ /*
* printf("PRIMARY: %s\n", primary->str); printf("SECONDARY:
* %s\n", secondary->str);
*/
} }
...@@ -1451,13 +1466,14 @@ DoubleMetaphone(char *str, char **codes) ...@@ -1451,13 +1466,14 @@ DoubleMetaphone(char *str, char **codes)
/* just for testing - not part of the perl code */ /* just for testing - not part of the perl code */
main(int argc, char ** argv) main(int argc, char **argv)
{ {
char * codes[2]; char *codes[2];
if (argc > 1) if (argc > 1)
{ {
DoubleMetaphone(argv[1],codes); DoubleMetaphone(argv[1], codes);
printf("%s|%s\n",codes[0],codes[1]); printf("%s|%s\n", codes[0], codes[1]);
} }
} }
......
...@@ -359,10 +359,10 @@ g_int_picksplit(PG_FUNCTION_ARGS) ...@@ -359,10 +359,10 @@ g_int_picksplit(PG_FUNCTION_ARGS)
waste = 0.0; waste = 0.0;
for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i)) for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
{ {
datum_alpha = GETENTRY(entryvec,i); datum_alpha = GETENTRY(entryvec, i);
for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j)) for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
{ {
datum_beta = GETENTRY(entryvec,j); datum_beta = GETENTRY(entryvec, j);
/* compute the wasted space by unioning these guys */ /* compute the wasted space by unioning these guys */
/* size_waste = size_union - size_inter; */ /* size_waste = size_union - size_inter; */
...@@ -402,10 +402,10 @@ g_int_picksplit(PG_FUNCTION_ARGS) ...@@ -402,10 +402,10 @@ g_int_picksplit(PG_FUNCTION_ARGS)
seed_2 = 2; seed_2 = 2;
} }
datum_alpha = GETENTRY(entryvec,seed_1); datum_alpha = GETENTRY(entryvec, seed_1);
datum_l = copy_intArrayType(datum_alpha); datum_l = copy_intArrayType(datum_alpha);
rt__int_size(datum_l, &size_l); rt__int_size(datum_l, &size_l);
datum_beta = GETENTRY(entryvec,seed_2); datum_beta = GETENTRY(entryvec, seed_2);
datum_r = copy_intArrayType(datum_beta); datum_r = copy_intArrayType(datum_beta);
rt__int_size(datum_r, &size_r); rt__int_size(datum_r, &size_r);
...@@ -418,7 +418,7 @@ g_int_picksplit(PG_FUNCTION_ARGS) ...@@ -418,7 +418,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{ {
costvector[i - 1].pos = i; costvector[i - 1].pos = i;
datum_alpha = GETENTRY(entryvec,i); datum_alpha = GETENTRY(entryvec, i);
union_d = inner_int_union(datum_l, datum_alpha); union_d = inner_int_union(datum_l, datum_alpha);
rt__int_size(union_d, &size_alpha); rt__int_size(union_d, &size_alpha);
pfree(union_d); pfree(union_d);
...@@ -466,7 +466,7 @@ g_int_picksplit(PG_FUNCTION_ARGS) ...@@ -466,7 +466,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
} }
/* okay, which page needs least enlargement? */ /* okay, which page needs least enlargement? */
datum_alpha = GETENTRY(entryvec,i); datum_alpha = GETENTRY(entryvec, i);
union_dl = inner_int_union(datum_l, datum_alpha); union_dl = inner_int_union(datum_l, datum_alpha);
union_dr = inner_int_union(datum_r, datum_alpha); union_dr = inner_int_union(datum_r, datum_alpha);
rt__int_size(union_dl, &size_alpha); rt__int_size(union_dl, &size_alpha);
......
This diff is collapsed.
...@@ -98,7 +98,7 @@ _ltree_compress(PG_FUNCTION_ARGS) ...@@ -98,7 +98,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
entry->rel, entry->page, entry->rel, entry->page,
entry->offset, key->len, FALSE); entry->offset, key->len, FALSE);
} }
else if ( !LTG_ISALLTRUE(entry->key) ) else if (!LTG_ISALLTRUE(entry->key))
{ {
int4 i, int4 i,
len; len;
...@@ -107,7 +107,7 @@ _ltree_compress(PG_FUNCTION_ARGS) ...@@ -107,7 +107,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
BITVECP sign = LTG_SIGN(DatumGetPointer(entry->key)); BITVECP sign = LTG_SIGN(DatumGetPointer(entry->key));
ALOOPBYTE( ALOOPBYTE(
if ((sign[i]&0xff) != 0xff) if ((sign[i] & 0xff) != 0xff)
PG_RETURN_POINTER(retval); PG_RETURN_POINTER(retval);
); );
len = LTG_HDRSIZE; len = LTG_HDRSIZE;
...@@ -175,7 +175,8 @@ _ltree_union(PG_FUNCTION_ARGS) ...@@ -175,7 +175,8 @@ _ltree_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1); int *size = (int *) PG_GETARG_POINTER(1);
ABITVEC base; ABITVEC base;
int4 i,len; int4 i,
len;
int4 flag = 0; int4 flag = 0;
ltree_gist *result; ltree_gist *result;
...@@ -213,27 +214,32 @@ sizebitvec(BITVECP sign) ...@@ -213,27 +214,32 @@ sizebitvec(BITVECP sign)
} }
static int static int
hemdistsign(BITVECP a, BITVECP b) { hemdistsign(BITVECP a, BITVECP b)
int i,dist=0; {
int i,
dist = 0;
ALOOPBIT( ALOOPBIT(
if ( GETBIT(a,i) != GETBIT(b,i) ) if (GETBIT(a, i) != GETBIT(b, i))
dist++; dist++;
); );
return dist; return dist;
} }
static int static int
hemdist(ltree_gist *a, ltree_gist *b) { hemdist(ltree_gist * a, ltree_gist * b)
if ( LTG_ISALLTRUE(a) ) { {
if (LTG_ISALLTRUE(a))
{
if (LTG_ISALLTRUE(b)) if (LTG_ISALLTRUE(b))
return 0; return 0;
else else
return ASIGLENBIT-sizebitvec(LTG_SIGN(b)); return ASIGLENBIT - sizebitvec(LTG_SIGN(b));
} else if (LTG_ISALLTRUE(b)) }
return ASIGLENBIT-sizebitvec(LTG_SIGN(a)); else if (LTG_ISALLTRUE(b))
return ASIGLENBIT - sizebitvec(LTG_SIGN(a));
return hemdistsign( LTG_SIGN(a), LTG_SIGN(b) ); return hemdistsign(LTG_SIGN(a), LTG_SIGN(b));
} }
...@@ -244,7 +250,7 @@ _ltree_penalty(PG_FUNCTION_ARGS) ...@@ -244,7 +250,7 @@ _ltree_penalty(PG_FUNCTION_ARGS)
ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *penalty = (float *) PG_GETARG_POINTER(2); float *penalty = (float *) PG_GETARG_POINTER(2);
*penalty=hemdist(origval,newval); *penalty = hemdist(origval, newval);
PG_RETURN_POINTER(penalty); PG_RETURN_POINTER(penalty);
} }
...@@ -271,7 +277,8 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -271,7 +277,8 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
*datum_r; *datum_r;
BITVECP union_l, BITVECP union_l,
union_r; union_r;
int4 size_alpha, size_beta; int4 size_alpha,
size_beta;
int4 size_waste, int4 size_waste,
waste = -1; waste = -1;
int4 nbytes; int4 nbytes;
...@@ -291,11 +298,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -291,11 +298,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes);
for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) { for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
{
_k = GETENTRY(entryvec, k); _k = GETENTRY(entryvec, k);
for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) { for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
size_waste=hemdist(_k, GETENTRY(entryvec, j)); {
if (size_waste > waste ) { size_waste = hemdist(_k, GETENTRY(entryvec, j));
if (size_waste > waste)
{
waste = size_waste; waste = size_waste;
seed_1 = k; seed_1 = k;
seed_2 = j; seed_2 = j;
...@@ -349,14 +359,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -349,14 +359,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
{ {
costvector[j - 1].pos = j; costvector[j - 1].pos = j;
_j = GETENTRY(entryvec, j); _j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l,_j); size_alpha = hemdist(datum_l, _j);
size_beta = hemdist(datum_r,_j); size_beta = hemdist(datum_r, _j);
costvector[j - 1].cost = abs(size_alpha - size_beta); costvector[j - 1].cost = abs(size_alpha - size_beta);
} }
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
union_l=LTG_SIGN(datum_l); union_l = LTG_SIGN(datum_l);
union_r=LTG_SIGN(datum_r); union_r = LTG_SIGN(datum_r);
for (k = 0; k < maxoff; k++) for (k = 0; k < maxoff; k++)
{ {
...@@ -374,16 +384,19 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -374,16 +384,19 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
continue; continue;
} }
_j = GETENTRY(entryvec, j); _j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l,_j); size_alpha = hemdist(datum_l, _j);
size_beta = hemdist(datum_r,_j); size_beta = hemdist(datum_r, _j);
if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.00001)) if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.00001))
{ {
if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j) ) { if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j))
{
if (!LTG_ISALLTRUE(datum_l)) if (!LTG_ISALLTRUE(datum_l))
MemSet((void *) union_l, 0xff, sizeof(ABITVEC)); MemSet((void *) union_l, 0xff, sizeof(ABITVEC));
} else { }
ptr=LTG_SIGN(_j); else
{
ptr = LTG_SIGN(_j);
ALOOPBYTE( ALOOPBYTE(
union_l[i] |= ptr[i]; union_l[i] |= ptr[i];
); );
...@@ -393,11 +406,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -393,11 +406,14 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
} }
else else
{ {
if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j) ) { if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j))
{
if (!LTG_ISALLTRUE(datum_r)) if (!LTG_ISALLTRUE(datum_r))
MemSet((void *) union_r, 0xff, sizeof(ABITVEC)); MemSet((void *) union_r, 0xff, sizeof(ABITVEC));
} else { }
ptr=LTG_SIGN(_j); else
{
ptr = LTG_SIGN(_j);
ALOOPBYTE( ALOOPBYTE(
union_r[i] |= ptr[i]; union_r[i] |= ptr[i];
); );
...@@ -498,7 +514,8 @@ gist_qe(ltree_gist * key, lquery * query) ...@@ -498,7 +514,8 @@ gist_qe(ltree_gist * key, lquery * query)
} }
static bool static bool
_arrq_cons(ltree_gist *key, ArrayType *_query) { _arrq_cons(ltree_gist * key, ArrayType *_query)
{
lquery *query = (lquery *) ARR_DATA_PTR(_query); lquery *query = (lquery *) ARR_DATA_PTR(_query);
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query)); int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
...@@ -507,11 +524,12 @@ _arrq_cons(ltree_gist *key, ArrayType *_query) { ...@@ -507,11 +524,12 @@ _arrq_cons(ltree_gist *key, ArrayType *_query) {
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("array must be one-dimensional"))); errmsg("array must be one-dimensional")));
while (num > 0) { while (num > 0)
if ( gist_qe(key, query) ) {
if (gist_qe(key, query))
return true; return true;
num--; num--;
query = (lquery*)NEXTVAL(query); query = (lquery *) NEXTVAL(query);
} }
return false; return false;
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* /*
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.31 2004/06/14 11:00:12 ishii Exp $ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.32 2004/08/29 05:06:36 momjian Exp $
* *
* pgbench: a simple TPC-B like benchmark program for PostgreSQL * pgbench: a simple TPC-B like benchmark program for PostgreSQL
* written by Tatsuo Ishii * written by Tatsuo Ishii
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment