Commit b6b71b85 authored by Bruce Momjian's avatar Bruce Momjian

Pgindent run for 8.0.

parent 90cb9c30
...@@ -14,92 +14,99 @@ PG_FUNCTION_INFO_V1(gbt_bit_consistent); ...@@ -14,92 +14,99 @@ PG_FUNCTION_INFO_V1(gbt_bit_consistent);
PG_FUNCTION_INFO_V1(gbt_bit_penalty); PG_FUNCTION_INFO_V1(gbt_bit_penalty);
PG_FUNCTION_INFO_V1(gbt_bit_same); PG_FUNCTION_INFO_V1(gbt_bit_same);
Datum gbt_bit_compress(PG_FUNCTION_ARGS); Datum gbt_bit_compress(PG_FUNCTION_ARGS);
Datum gbt_bit_union(PG_FUNCTION_ARGS); Datum gbt_bit_union(PG_FUNCTION_ARGS);
Datum gbt_bit_picksplit(PG_FUNCTION_ARGS); Datum gbt_bit_picksplit(PG_FUNCTION_ARGS);
Datum gbt_bit_consistent(PG_FUNCTION_ARGS); Datum gbt_bit_consistent(PG_FUNCTION_ARGS);
Datum gbt_bit_penalty(PG_FUNCTION_ARGS); Datum gbt_bit_penalty(PG_FUNCTION_ARGS);
Datum gbt_bit_same(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_vinfo tinfo = static const gbtree_vinfo tinfo =
{ {
gbt_t_bit, gbt_t_bit,
FALSE, FALSE,
TRUE, TRUE,
gbt_bitgt, gbt_bitgt,
gbt_bitge, gbt_bitge,
gbt_biteq, gbt_biteq,
gbt_bitle, gbt_bitle,
gbt_bitlt, gbt_bitlt,
gbt_bitcmp, gbt_bitcmp,
gbt_bit_l2n gbt_bit_l2n
}; };
...@@ -108,40 +115,40 @@ static const gbtree_vinfo tinfo = ...@@ -108,40 +115,40 @@ 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);
retval = gbt_var_consistent( &r, query, &strategy, TRUE, &tinfo ); else
} else { {
bytea * q = gbt_bit_xfrm ( ( bytea * ) query ); bytea *q = gbt_bit_xfrm((bytea *) query);
retval = gbt_var_consistent( &r, (void*)q, &strategy, FALSE, &tinfo );
pfree(q); retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
} pfree(q);
}
if ( ktst != key ){
pfree ( key ); if (ktst != key)
} pfree(key);
if ( qtst != query ){ if (qtst != query)
pfree ( query ); pfree(query);
} PG_RETURN_BOOL(retval);
PG_RETURN_BOOL(retval);
} }
...@@ -149,37 +156,40 @@ gbt_bit_consistent(PG_FUNCTION_ARGS) ...@@ -149,37 +156,40 @@ 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));
} }
Datum Datum
gbt_bit_picksplit(PG_FUNCTION_ARGS) 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 );
PG_RETURN_POINTER(v); gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v);
} }
Datum Datum
gbt_bit_same(PG_FUNCTION_ARGS) 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));
} }
Datum 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));
}
...@@ -13,61 +13,67 @@ PG_FUNCTION_INFO_V1(gbt_bytea_consistent); ...@@ -13,61 +13,67 @@ PG_FUNCTION_INFO_V1(gbt_bytea_consistent);
PG_FUNCTION_INFO_V1(gbt_bytea_penalty); PG_FUNCTION_INFO_V1(gbt_bytea_penalty);
PG_FUNCTION_INFO_V1(gbt_bytea_same); PG_FUNCTION_INFO_V1(gbt_bytea_same);
Datum gbt_bytea_compress(PG_FUNCTION_ARGS); Datum gbt_bytea_compress(PG_FUNCTION_ARGS);
Datum gbt_bytea_union(PG_FUNCTION_ARGS); Datum gbt_bytea_union(PG_FUNCTION_ARGS);
Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS); Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS);
Datum gbt_bytea_consistent(PG_FUNCTION_ARGS); Datum gbt_bytea_consistent(PG_FUNCTION_ARGS);
Datum gbt_bytea_penalty(PG_FUNCTION_ARGS); Datum gbt_bytea_penalty(PG_FUNCTION_ARGS);
Datum gbt_bytea_same(PG_FUNCTION_ARGS); 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))));
} }
static const gbtree_vinfo tinfo = static const gbtree_vinfo tinfo =
{ {
gbt_t_bytea, gbt_t_bytea,
FALSE, FALSE,
TRUE, TRUE,
gbt_byteagt, gbt_byteagt,
gbt_byteage, gbt_byteage,
gbt_byteaeq, gbt_byteaeq,
gbt_byteale, gbt_byteale,
gbt_bytealt, gbt_bytealt,
gbt_byteacmp, gbt_byteacmp,
NULL NULL
}; };
...@@ -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));
} }
...@@ -88,24 +95,22 @@ gbt_bytea_compress (PG_FUNCTION_ARGS) ...@@ -88,24 +95,22 @@ gbt_bytea_compress (PG_FUNCTION_ARGS)
Datum 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,37 +118,40 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS) ...@@ -113,37 +118,40 @@ 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));
} }
Datum Datum
gbt_bytea_picksplit(PG_FUNCTION_ARGS) 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 );
PG_RETURN_POINTER(v); gbt_var_picksplit(entryvec, v, &tinfo);
PG_RETURN_POINTER(v);
} }
Datum Datum
gbt_bytea_same(PG_FUNCTION_ARGS) 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));
} }
Datum 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));
}
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
typedef struct typedef struct
{ {
Cash lower; Cash lower;
Cash upper; Cash upper;
} cashKEY; } cashKEY;
/* /*
** Cash ops ** Cash ops
...@@ -18,59 +18,62 @@ PG_FUNCTION_INFO_V1(gbt_cash_consistent); ...@@ -18,59 +18,62 @@ PG_FUNCTION_INFO_V1(gbt_cash_consistent);
PG_FUNCTION_INFO_V1(gbt_cash_penalty); PG_FUNCTION_INFO_V1(gbt_cash_penalty);
PG_FUNCTION_INFO_V1(gbt_cash_same); PG_FUNCTION_INFO_V1(gbt_cash_same);
Datum gbt_cash_compress(PG_FUNCTION_ARGS); Datum gbt_cash_compress(PG_FUNCTION_ARGS);
Datum gbt_cash_union(PG_FUNCTION_ARGS); Datum gbt_cash_union(PG_FUNCTION_ARGS);
Datum gbt_cash_picksplit(PG_FUNCTION_ARGS); Datum gbt_cash_picksplit(PG_FUNCTION_ARGS);
Datum gbt_cash_consistent(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_cash, gbt_t_cash,
sizeof(Cash), sizeof(Cash),
gbt_cashgt, gbt_cashgt,
gbt_cashge, gbt_cashge,
gbt_casheq, gbt_casheq,
gbt_cashle, gbt_cashle,
gbt_cashlt, gbt_cashlt,
gbt_cashkey_cmp gbt_cashkey_cmp
}; };
...@@ -82,81 +85,83 @@ static const gbtree_ninfo tinfo = ...@@ -82,81 +85,83 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_cash_compress(PG_FUNCTION_ARGS) 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));
} }
Datum Datum
gbt_cash_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_cash_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_cash_penalty(PG_FUNCTION_ARGS) gbt_cash_penalty(PG_FUNCTION_ARGS)
{ {
cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
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);
} }
Datum Datum
gbt_cash_picksplit(PG_FUNCTION_ARGS) gbt_cash_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_cash_same(PG_FUNCTION_ARGS) gbt_cash_same(PG_FUNCTION_ARGS)
{ {
cashKEY *b1 = (cashKEY *) PG_GETARG_POINTER(0); cashKEY *b1 = (cashKEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
typedef struct typedef struct
{ {
DateADT lower; DateADT lower;
DateADT upper; DateADT upper;
} dateKEY; } dateKEY;
/* /*
** date ops ** date ops
...@@ -18,46 +18,51 @@ PG_FUNCTION_INFO_V1(gbt_date_consistent); ...@@ -18,46 +18,51 @@ PG_FUNCTION_INFO_V1(gbt_date_consistent);
PG_FUNCTION_INFO_V1(gbt_date_penalty); PG_FUNCTION_INFO_V1(gbt_date_penalty);
PG_FUNCTION_INFO_V1(gbt_date_same); PG_FUNCTION_INFO_V1(gbt_date_same);
Datum gbt_date_compress(PG_FUNCTION_ARGS); Datum gbt_date_compress(PG_FUNCTION_ARGS);
Datum gbt_date_union(PG_FUNCTION_ARGS); Datum gbt_date_union(PG_FUNCTION_ARGS);
Datum gbt_date_picksplit(PG_FUNCTION_ARGS); Datum gbt_date_picksplit(PG_FUNCTION_ARGS);
Datum gbt_date_consistent(PG_FUNCTION_ARGS); 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,26 +70,24 @@ static bool gbt_datelt (const void *a, const void *b) ...@@ -65,26 +70,24 @@ 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_date, gbt_t_date,
sizeof(DateADT), sizeof(DateADT),
gbt_dategt, gbt_dategt,
gbt_datege, gbt_datege,
gbt_dateeq, gbt_dateeq,
gbt_datele, gbt_datele,
gbt_datelt, gbt_datelt,
gbt_datekey_cmp gbt_datekey_cmp
}; };
...@@ -97,9 +100,10 @@ static const gbtree_ninfo tinfo = ...@@ -97,9 +100,10 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_date_compress(PG_FUNCTION_ARGS) 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));
} }
...@@ -107,86 +111,89 @@ gbt_date_compress(PG_FUNCTION_ARGS) ...@@ -107,86 +111,89 @@ gbt_date_compress(PG_FUNCTION_ARGS)
Datum 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)
); );
} }
Datum Datum
gbt_date_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(dateKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_date_penalty(PG_FUNCTION_ARGS) 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(
date_mi, diff = DatumGetInt32(DirectFunctionCall2(
DateADTGetDatum(newentry->upper), date_mi,
DateADTGetDatum(origentry->upper))); DateADTGetDatum(newentry->upper),
DateADTGetDatum(origentry->upper)));
res = Max(diff, 0);
res = Max(diff, 0);
diff = DatumGetInt32(DirectFunctionCall2(
date_mi, diff = DatumGetInt32(DirectFunctionCall2(
DateADTGetDatum(origentry->lower), date_mi,
DateADTGetDatum(newentry->lower))); DateADTGetDatum(origentry->lower),
DateADTGetDatum(newentry->lower)));
res += Max(diff, 0);
res += Max(diff, 0);
*result = 0.0;
*result = 0.0;
if ( res > 0 ){
diff = DatumGetInt32(DirectFunctionCall2( if (res > 0)
date_mi, {
DateADTGetDatum(origentry->upper), diff = DatumGetInt32(DirectFunctionCall2(
DateADTGetDatum(origentry->lower))); date_mi,
*result += FLT_MIN ; DateADTGetDatum(origentry->upper),
*result += (float) ( res / ( (double) ( res + diff ) ) ); DateADTGetDatum(origentry->lower)));
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) ); *result += FLT_MIN;
} *result += (float) (res / ((double) (res + diff)));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
PG_RETURN_POINTER(result); }
PG_RETURN_POINTER(result);
} }
Datum Datum
gbt_date_picksplit(PG_FUNCTION_ARGS) gbt_date_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_date_same(PG_FUNCTION_ARGS) gbt_date_same(PG_FUNCTION_ARGS)
{ {
dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0); dateKEY *b1 = (dateKEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct float4key typedef struct float4key
{ {
float4 lower; float4 lower;
float4 upper; float4 upper;
} float4KEY; } float4KEY;
/* /*
** float4 ops ** float4 ops
...@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_float4_consistent); ...@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_float4_consistent);
PG_FUNCTION_INFO_V1(gbt_float4_penalty); PG_FUNCTION_INFO_V1(gbt_float4_penalty);
PG_FUNCTION_INFO_V1(gbt_float4_same); PG_FUNCTION_INFO_V1(gbt_float4_same);
Datum gbt_float4_compress(PG_FUNCTION_ARGS); Datum gbt_float4_compress(PG_FUNCTION_ARGS);
Datum gbt_float4_union(PG_FUNCTION_ARGS); Datum gbt_float4_union(PG_FUNCTION_ARGS);
Datum gbt_float4_picksplit(PG_FUNCTION_ARGS); Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
Datum gbt_float4_consistent(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_float4, gbt_t_float4,
sizeof(float4), sizeof(float4),
gbt_float4gt, gbt_float4gt,
gbt_float4ge, gbt_float4ge,
gbt_float4eq, gbt_float4eq,
gbt_float4le, gbt_float4le,
gbt_float4lt, gbt_float4lt,
gbt_float4key_cmp gbt_float4key_cmp
}; };
...@@ -81,80 +84,83 @@ static const gbtree_ninfo tinfo = ...@@ -81,80 +84,83 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_float4_compress(PG_FUNCTION_ARGS) 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));
} }
Datum Datum
gbt_float4_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_float4_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_float4_penalty(PG_FUNCTION_ARGS) gbt_float4_penalty(PG_FUNCTION_ARGS)
{ {
float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
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 );
if ( res > 0 ){ penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
*result += FLT_MIN ;
*result += (float) ( res / ( (double) ( res + origentry->upper - origentry->lower ) ) );
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
}
PG_RETURN_POINTER(result); if (res > 0)
{
*result += FLT_MIN;
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
}
PG_RETURN_POINTER(result);
} }
Datum Datum
gbt_float4_picksplit(PG_FUNCTION_ARGS) gbt_float4_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_float4_same(PG_FUNCTION_ARGS) gbt_float4_same(PG_FUNCTION_ARGS)
{ {
float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0); float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct float8key typedef struct float8key
{ {
float8 lower; float8 lower;
float8 upper; float8 upper;
} float8KEY; } float8KEY;
/* /*
** float8 ops ** float8 ops
...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_float8_consistent); ...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_float8_consistent);
PG_FUNCTION_INFO_V1(gbt_float8_penalty); PG_FUNCTION_INFO_V1(gbt_float8_penalty);
PG_FUNCTION_INFO_V1(gbt_float8_same); PG_FUNCTION_INFO_V1(gbt_float8_same);
Datum gbt_float8_compress(PG_FUNCTION_ARGS); Datum gbt_float8_compress(PG_FUNCTION_ARGS);
Datum gbt_float8_union(PG_FUNCTION_ARGS); Datum gbt_float8_union(PG_FUNCTION_ARGS);
Datum gbt_float8_picksplit(PG_FUNCTION_ARGS); Datum gbt_float8_picksplit(PG_FUNCTION_ARGS);
Datum gbt_float8_consistent(PG_FUNCTION_ARGS); Datum gbt_float8_consistent(PG_FUNCTION_ARGS);
Datum gbt_float8_penalty(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_float8, gbt_t_float8,
sizeof(float8), sizeof(float8),
gbt_float8gt, gbt_float8gt,
gbt_float8ge, gbt_float8ge,
gbt_float8eq, gbt_float8eq,
gbt_float8le, gbt_float8le,
gbt_float8lt, gbt_float8lt,
gbt_float8key_cmp gbt_float8key_cmp
}; };
...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo = ...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_float8_compress(PG_FUNCTION_ARGS) 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));
} }
...@@ -92,70 +96,73 @@ Datum ...@@ -92,70 +96,73 @@ Datum
gbt_float8_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_float8_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_float8_penalty(PG_FUNCTION_ARGS) gbt_float8_penalty(PG_FUNCTION_ARGS)
{ {
float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
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);
} }
Datum Datum
gbt_float8_picksplit(PG_FUNCTION_ARGS) gbt_float8_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_float8_same(PG_FUNCTION_ARGS) gbt_float8_same(PG_FUNCTION_ARGS)
{ {
float8KEY *b1 = (float8KEY *) PG_GETARG_POINTER(0); float8KEY *b1 = (float8KEY *) PG_GETARG_POINTER(0);
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);
} }
#include "btree_gist.h" #include "btree_gist.h"
PG_FUNCTION_INFO_V1(gbt_decompress); PG_FUNCTION_INFO_V1(gbt_decompress);
PG_FUNCTION_INFO_V1(gbtreekey_in); PG_FUNCTION_INFO_V1(gbtreekey_in);
PG_FUNCTION_INFO_V1(gbtreekey_out); PG_FUNCTION_INFO_V1(gbtreekey_out);
Datum gbt_decompress(PG_FUNCTION_ARGS); Datum gbt_decompress(PG_FUNCTION_ARGS);
/************************************************** /**************************************************
* In/Out for keys * In/Out for keys
**************************************************/ **************************************************/
Datum Datum
gbtreekey_in(PG_FUNCTION_ARGS) gbtreekey_in(PG_FUNCTION_ARGS)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("<datatype>key_in() not implemented"))); errmsg("<datatype>key_in() not implemented")));
PG_RETURN_POINTER(NULL); PG_RETURN_POINTER(NULL);
} }
#include "btree_utils_var.h" #include "btree_utils_var.h"
...@@ -26,10 +26,10 @@ gbtreekey_in(PG_FUNCTION_ARGS) ...@@ -26,10 +26,10 @@ gbtreekey_in(PG_FUNCTION_ARGS)
Datum Datum
gbtreekey_out(PG_FUNCTION_ARGS) gbtreekey_out(PG_FUNCTION_ARGS)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("<datatype>key_out() not implemented"))); errmsg("<datatype>key_out() not implemented")));
PG_RETURN_POINTER(NULL); PG_RETURN_POINTER(NULL);
} }
...@@ -40,6 +40,5 @@ gbtreekey_out(PG_FUNCTION_ARGS) ...@@ -40,6 +40,5 @@ gbtreekey_out(PG_FUNCTION_ARGS)
Datum Datum
gbt_decompress(PG_FUNCTION_ARGS) gbt_decompress(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(PG_GETARG_POINTER(0)); PG_RETURN_POINTER(PG_GETARG_POINTER(0));
} }
...@@ -7,25 +7,25 @@ ...@@ -7,25 +7,25 @@
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,
gbt_t_oid, gbt_t_oid,
gbt_t_time, gbt_t_time,
gbt_t_date, gbt_t_date,
gbt_t_intv, gbt_t_intv,
gbt_t_macad, gbt_t_macad,
gbt_t_text, gbt_t_text,
gbt_t_bpchar, gbt_t_bpchar,
gbt_t_bytea, gbt_t_bytea,
gbt_t_bit, gbt_t_bit,
gbt_t_inet gbt_t_inet
}; };
...@@ -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);
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
typedef struct inetkey typedef struct inetkey
{ {
double lower; double lower;
double upper; double upper;
} inetKEY; } inetKEY;
/* /*
** inet ops ** inet ops
...@@ -22,62 +22,65 @@ PG_FUNCTION_INFO_V1(gbt_cidr_consistent); ...@@ -22,62 +22,65 @@ PG_FUNCTION_INFO_V1(gbt_cidr_consistent);
PG_FUNCTION_INFO_V1(gbt_inet_penalty); PG_FUNCTION_INFO_V1(gbt_inet_penalty);
PG_FUNCTION_INFO_V1(gbt_inet_same); PG_FUNCTION_INFO_V1(gbt_inet_same);
Datum gbt_inet_compress(PG_FUNCTION_ARGS); Datum gbt_inet_compress(PG_FUNCTION_ARGS);
Datum gbt_cidr_compress(PG_FUNCTION_ARGS); Datum gbt_cidr_compress(PG_FUNCTION_ARGS);
Datum gbt_inet_union(PG_FUNCTION_ARGS); Datum gbt_inet_union(PG_FUNCTION_ARGS);
Datum gbt_inet_picksplit(PG_FUNCTION_ARGS); Datum gbt_inet_picksplit(PG_FUNCTION_ARGS);
Datum gbt_inet_consistent(PG_FUNCTION_ARGS); Datum gbt_inet_consistent(PG_FUNCTION_ARGS);
Datum gbt_cidr_consistent(PG_FUNCTION_ARGS); Datum gbt_cidr_consistent(PG_FUNCTION_ARGS);
Datum gbt_inet_penalty(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_inet, gbt_t_inet,
sizeof(double), sizeof(double),
gbt_inetgt, gbt_inetgt,
gbt_inetge, gbt_inetge,
gbt_ineteq, gbt_ineteq,
gbt_inetle, gbt_inetle,
gbt_inetlt, gbt_inetlt,
gbt_inetkey_cmp gbt_inetkey_cmp
}; };
...@@ -87,24 +90,25 @@ static const gbtree_ninfo tinfo = ...@@ -87,24 +90,25 @@ 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)
{
inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
retval = palloc(sizeof(GISTENTRY));
r->lower = convert_network_to_scalar(entry->key, typid );
r->upper = r->lower ;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, sizeof(inetKEY), FALSE);
}
else
retval = entry;
return ( retval ); if (entry->leafkey)
{
inetKEY *r = (inetKEY *) palloc(sizeof(inetKEY));
retval = palloc(sizeof(GISTENTRY));
r->lower = convert_network_to_scalar(entry->key, typid);
r->upper = r->lower;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, sizeof(inetKEY), FALSE);
}
else
retval = entry;
return (retval);
} }
...@@ -112,113 +116,118 @@ gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid) ...@@ -112,113 +116,118 @@ gbt_inet_compress_inetrnal(GISTENTRY *retval , GISTENTRY *entry , Oid typid)
Datum Datum
gbt_inet_compress(PG_FUNCTION_ARGS) 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
gbt_cidr_compress(PG_FUNCTION_ARGS) 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); {
GBT_NUMKEY_R key ; inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key;
key.lower = (GBT_NUMKEY *) & kkk->lower;
key.upper = (GBT_NUMKEY *) & kkk->upper;
key.lower = (GBT_NUMKEY*) &kkk->lower ; return (
key.upper = (GBT_NUMKEY*) &kkk->upper ; gbt_num_consistent(&key, (void *) query, strategy, GIST_LEAF(entry), &tinfo)
);
return (
gbt_num_consistent( &key, (void*)query,strategy,GIST_LEAF(entry),&tinfo)
);
} }
Datum 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)
); );
} }
Datum 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)
); );
} }
Datum Datum
gbt_inet_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(inetKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_inet_penalty(PG_FUNCTION_ARGS) gbt_inet_penalty(PG_FUNCTION_ARGS)
{ {
inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); inetKEY *origentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
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);
} }
Datum Datum
gbt_inet_picksplit(PG_FUNCTION_ARGS) gbt_inet_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_inet_same(PG_FUNCTION_ARGS) gbt_inet_same(PG_FUNCTION_ARGS)
{ {
inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0); inetKEY *b1 = (inetKEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct int16key typedef struct int16key
{ {
int16 lower; int16 lower;
int16 upper; int16 upper;
} int16KEY; } int16KEY;
/* /*
** int16 ops ** int16 ops
...@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_int2_consistent); ...@@ -17,59 +17,62 @@ PG_FUNCTION_INFO_V1(gbt_int2_consistent);
PG_FUNCTION_INFO_V1(gbt_int2_penalty); PG_FUNCTION_INFO_V1(gbt_int2_penalty);
PG_FUNCTION_INFO_V1(gbt_int2_same); PG_FUNCTION_INFO_V1(gbt_int2_same);
Datum gbt_int2_compress(PG_FUNCTION_ARGS); Datum gbt_int2_compress(PG_FUNCTION_ARGS);
Datum gbt_int2_union(PG_FUNCTION_ARGS); Datum gbt_int2_union(PG_FUNCTION_ARGS);
Datum gbt_int2_picksplit(PG_FUNCTION_ARGS); Datum gbt_int2_picksplit(PG_FUNCTION_ARGS);
Datum gbt_int2_consistent(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_int2, gbt_t_int2,
sizeof(int16), sizeof(int16),
gbt_int2gt, gbt_int2gt,
gbt_int2ge, gbt_int2ge,
gbt_int2eq, gbt_int2eq,
gbt_int2le, gbt_int2le,
gbt_int2lt, gbt_int2lt,
gbt_int2key_cmp gbt_int2key_cmp
}; };
...@@ -85,77 +88,81 @@ static const gbtree_ninfo tinfo = ...@@ -85,77 +88,81 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_int2_compress(PG_FUNCTION_ARGS) 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));
} }
Datum Datum
gbt_int2_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_int2_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_int2_penalty(PG_FUNCTION_ARGS) 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);
} }
Datum Datum
gbt_int2_picksplit(PG_FUNCTION_ARGS) gbt_int2_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_int2_same(PG_FUNCTION_ARGS) gbt_int2_same(PG_FUNCTION_ARGS)
{ {
int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0); int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct int32key typedef struct int32key
{ {
int32 lower; int32 lower;
int32 upper; int32 upper;
} int32KEY; } int32KEY;
/* /*
** int32 ops ** int32 ops
...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int4_consistent); ...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int4_consistent);
PG_FUNCTION_INFO_V1(gbt_int4_penalty); PG_FUNCTION_INFO_V1(gbt_int4_penalty);
PG_FUNCTION_INFO_V1(gbt_int4_same); PG_FUNCTION_INFO_V1(gbt_int4_same);
Datum gbt_int4_compress(PG_FUNCTION_ARGS); Datum gbt_int4_compress(PG_FUNCTION_ARGS);
Datum gbt_int4_union(PG_FUNCTION_ARGS); Datum gbt_int4_union(PG_FUNCTION_ARGS);
Datum gbt_int4_picksplit(PG_FUNCTION_ARGS); Datum gbt_int4_picksplit(PG_FUNCTION_ARGS);
Datum gbt_int4_consistent(PG_FUNCTION_ARGS); Datum gbt_int4_consistent(PG_FUNCTION_ARGS);
Datum gbt_int4_penalty(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_int4, gbt_t_int4,
sizeof(int32), sizeof(int32),
gbt_int4gt, gbt_int4gt,
gbt_int4ge, gbt_int4ge,
gbt_int4eq, gbt_int4eq,
gbt_int4le, gbt_int4le,
gbt_int4lt, gbt_int4lt,
gbt_int4key_cmp gbt_int4key_cmp
}; };
...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo = ...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_int4_compress(PG_FUNCTION_ARGS) 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));
} }
...@@ -92,68 +96,71 @@ Datum ...@@ -92,68 +96,71 @@ Datum
gbt_int4_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(int32KEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_int4_penalty(PG_FUNCTION_ARGS) 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);
} }
Datum Datum
gbt_int4_picksplit(PG_FUNCTION_ARGS) gbt_int4_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_int4_same(PG_FUNCTION_ARGS) gbt_int4_same(PG_FUNCTION_ARGS)
{ {
int32KEY *b1 = (int32KEY *) PG_GETARG_POINTER(0); int32KEY *b1 = (int32KEY *) PG_GETARG_POINTER(0);
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);
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct int64key typedef struct int64key
{ {
int64 lower; int64 lower;
int64 upper; int64 upper;
} int64KEY; } int64KEY;
/* /*
** int64 ops ** int64 ops
...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int8_consistent); ...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_int8_consistent);
PG_FUNCTION_INFO_V1(gbt_int8_penalty); PG_FUNCTION_INFO_V1(gbt_int8_penalty);
PG_FUNCTION_INFO_V1(gbt_int8_same); PG_FUNCTION_INFO_V1(gbt_int8_same);
Datum gbt_int8_compress(PG_FUNCTION_ARGS); Datum gbt_int8_compress(PG_FUNCTION_ARGS);
Datum gbt_int8_union(PG_FUNCTION_ARGS); Datum gbt_int8_union(PG_FUNCTION_ARGS);
Datum gbt_int8_picksplit(PG_FUNCTION_ARGS); Datum gbt_int8_picksplit(PG_FUNCTION_ARGS);
Datum gbt_int8_consistent(PG_FUNCTION_ARGS); Datum gbt_int8_consistent(PG_FUNCTION_ARGS);
Datum gbt_int8_penalty(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_int8, gbt_t_int8,
sizeof(int64), sizeof(int64),
gbt_int8gt, gbt_int8gt,
gbt_int8ge, gbt_int8ge,
gbt_int8eq, gbt_int8eq,
gbt_int8le, gbt_int8le,
gbt_int8lt, gbt_int8lt,
gbt_int8key_cmp gbt_int8key_cmp
}; };
...@@ -82,79 +85,82 @@ static const gbtree_ninfo tinfo = ...@@ -82,79 +85,82 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_int8_compress(PG_FUNCTION_ARGS) 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));
} }
Datum Datum
gbt_int8_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_int8_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_int8_penalty(PG_FUNCTION_ARGS) 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);
} }
Datum Datum
gbt_int8_picksplit(PG_FUNCTION_ARGS) gbt_int8_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_int8_same(PG_FUNCTION_ARGS) gbt_int8_same(PG_FUNCTION_ARGS)
{ {
int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0); int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
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);
} }
This diff is collapsed.
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
typedef struct typedef struct
{ {
macaddr lower; macaddr lower;
macaddr upper; macaddr upper;
} macKEY; } macKEY;
/* /*
** OID ops ** OID ops
...@@ -19,62 +19,67 @@ PG_FUNCTION_INFO_V1(gbt_macad_consistent); ...@@ -19,62 +19,67 @@ PG_FUNCTION_INFO_V1(gbt_macad_consistent);
PG_FUNCTION_INFO_V1(gbt_macad_penalty); PG_FUNCTION_INFO_V1(gbt_macad_penalty);
PG_FUNCTION_INFO_V1(gbt_macad_same); PG_FUNCTION_INFO_V1(gbt_macad_same);
Datum gbt_macad_compress(PG_FUNCTION_ARGS); Datum gbt_macad_compress(PG_FUNCTION_ARGS);
Datum gbt_macad_union(PG_FUNCTION_ARGS); Datum gbt_macad_union(PG_FUNCTION_ARGS);
Datum gbt_macad_picksplit(PG_FUNCTION_ARGS); Datum gbt_macad_picksplit(PG_FUNCTION_ARGS);
Datum gbt_macad_consistent(PG_FUNCTION_ARGS); Datum gbt_macad_consistent(PG_FUNCTION_ARGS);
Datum gbt_macad_penalty(PG_FUNCTION_ARGS); 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)));
} }
static int static int
gbt_macadkey_cmp(const void *a, const void *b) 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])
) )
); );
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_macad, gbt_t_macad,
sizeof(macaddr), sizeof(macaddr),
gbt_macadgt, gbt_macadgt,
gbt_macadge, gbt_macadge,
gbt_macadeq, gbt_macadeq,
gbt_macadle, gbt_macadle,
gbt_macadlt, gbt_macadlt,
gbt_macadkey_cmp gbt_macadkey_cmp
}; };
...@@ -84,14 +89,16 @@ static const gbtree_ninfo tinfo = ...@@ -84,14 +89,16 @@ 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)
uint64 res = 0; {
int i; unsigned char *mi = (unsigned char *) m;
for (i=0; i<6; i++ ){ uint64 res = 0;
res += ( ( (uint64) mi[i] ) << ( (uint64) ( (5-i)*8 ) ) ); int i;
}
return res; for (i = 0; i < 6; i++)
res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
return res;
} }
...@@ -99,9 +106,10 @@ static uint64 mac_2_uint64 ( macaddr * m ){ ...@@ -99,9 +106,10 @@ static uint64 mac_2_uint64 ( macaddr * m ){
Datum Datum
gbt_macad_compress(PG_FUNCTION_ARGS) 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));
} }
...@@ -109,76 +117,79 @@ Datum ...@@ -109,76 +117,79 @@ Datum
gbt_macad_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_macad_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_macad_penalty(PG_FUNCTION_ARGS) 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],
uint64 res; inew[2];
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);
} }
Datum Datum
gbt_macad_picksplit(PG_FUNCTION_ARGS) gbt_macad_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_macad_same(PG_FUNCTION_ARGS) gbt_macad_same(PG_FUNCTION_ARGS)
{ {
macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0); macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
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);
} }
This diff is collapsed.
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
typedef struct typedef struct
{ {
Oid lower; Oid lower;
Oid upper; Oid upper;
} oidKEY; } oidKEY;
/* /*
** OID ops ** OID ops
...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_oid_consistent); ...@@ -17,60 +17,63 @@ PG_FUNCTION_INFO_V1(gbt_oid_consistent);
PG_FUNCTION_INFO_V1(gbt_oid_penalty); PG_FUNCTION_INFO_V1(gbt_oid_penalty);
PG_FUNCTION_INFO_V1(gbt_oid_same); PG_FUNCTION_INFO_V1(gbt_oid_same);
Datum gbt_oid_compress(PG_FUNCTION_ARGS); Datum gbt_oid_compress(PG_FUNCTION_ARGS);
Datum gbt_oid_union(PG_FUNCTION_ARGS); Datum gbt_oid_union(PG_FUNCTION_ARGS);
Datum gbt_oid_picksplit(PG_FUNCTION_ARGS); Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
Datum gbt_oid_consistent(PG_FUNCTION_ARGS); Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
Datum gbt_oid_penalty(PG_FUNCTION_ARGS); 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;
} }
static const gbtree_ninfo tinfo = static const gbtree_ninfo tinfo =
{ {
gbt_t_oid, gbt_t_oid,
sizeof(Oid), sizeof(Oid),
gbt_oidgt, gbt_oidgt,
gbt_oidge, gbt_oidge,
gbt_oideq, gbt_oideq,
gbt_oidle, gbt_oidle,
gbt_oidlt, gbt_oidlt,
gbt_oidkey_cmp gbt_oidkey_cmp
}; };
...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo = ...@@ -82,9 +85,10 @@ static const gbtree_ninfo tinfo =
Datum Datum
gbt_oid_compress(PG_FUNCTION_ARGS) 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));
} }
...@@ -92,69 +96,72 @@ Datum ...@@ -92,69 +96,72 @@ Datum
gbt_oid_consistent(PG_FUNCTION_ARGS) 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(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo) PG_RETURN_BOOL(
); gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
);
} }
Datum Datum
gbt_oid_union(PG_FUNCTION_ARGS) 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);
PG_RETURN_POINTER( gbt_num_union ( (void*)out, entryvec, &tinfo ) ); *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
} }
Datum Datum
gbt_oid_penalty(PG_FUNCTION_ARGS) gbt_oid_penalty(PG_FUNCTION_ARGS)
{ {
oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
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);
} }
Datum Datum
gbt_oid_picksplit(PG_FUNCTION_ARGS) gbt_oid_picksplit(PG_FUNCTION_ARGS)
{ {
PG_RETURN_POINTER(gbt_num_picksplit( PG_RETURN_POINTER(gbt_num_picksplit(
(GistEntryVector *) PG_GETARG_POINTER(0), (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1), (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo &tinfo
)); ));
} }
Datum Datum
gbt_oid_same(PG_FUNCTION_ARGS) gbt_oid_same(PG_FUNCTION_ARGS)
{ {
oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0); oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
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);
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -4,16 +4,17 @@ typedef char GBT_NUMKEY; ...@@ -4,16 +4,17 @@ typedef char GBT_NUMKEY;
/* Better readable key */ /* Better readable key */
typedef struct typedef struct
{ {
const GBT_NUMKEY * lower, * upper; const GBT_NUMKEY *lower,
} GBT_NUMKEY_R; *upper;
} GBT_NUMKEY_R;
/* for sorting */ /* for sorting */
typedef struct typedef struct
{ {
int i; int i;
GBT_NUMKEY * t; GBT_NUMKEY *t;
} Nsrt; } Nsrt;
/* type description */ /* type description */
...@@ -21,53 +22,53 @@ typedef struct ...@@ -21,53 +22,53 @@ typedef struct
typedef struct 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;
/* /*
* Numeric btree functions * Numeric btree functions
*/ */
#define penalty_range_enlarge(olower,oupper,nlower,nupper) do { \ #define penalty_range_enlarge(olower,oupper,nlower,nupper) do { \
res = 0; \ res = 0; \
if ( (nupper) > (oupper) ) \ if ( (nupper) > (oupper) ) \
res += ( (nupper) - (oupper) ); \ res += ( (nupper) - (oupper) ); \
if ( (olower) > (nlower) ) \ if ( (olower) > (nlower) ) \
res += ( (olower) - (nlower) ); \ res += ( (olower) - (nlower) ); \
} while (0); } while (0);
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,
} GBT_VARKEY_R; *upper;
} 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
...@@ -23,45 +24,45 @@ typedef struct ...@@ -23,45 +24,45 @@ typedef struct
typedef struct 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);
...@@ -230,7 +230,7 @@ g_cube_union(GistEntryVector *entryvec, int *sizep) ...@@ -230,7 +230,7 @@ g_cube_union(GistEntryVector *entryvec, int *sizep)
for (i = 1; i < entryvec->n; i++) for (i = 1; i < entryvec->n; i++)
{ {
out = g_cube_binary_union(tmp, (NDBOX *) out = g_cube_binary_union(tmp, (NDBOX *)
DatumGetPointer(entryvec->vector[i].key), DatumGetPointer(entryvec->vector[i].key),
sizep); sizep);
if (i > 1) if (i > 1)
pfree(tmp); pfree(tmp);
......
...@@ -700,8 +700,8 @@ main(int argc, char **argv) ...@@ -700,8 +700,8 @@ main(int argc, char **argv)
if (verbose > 1) if (verbose > 1)
printf("Opening dbf-file\n"); printf("Opening dbf-file\n");
setlocale(LC_ALL, ""); /* fix for isprint() */ setlocale(LC_ALL, ""); /* fix for isprint() */
if ((dbh = dbf_open(argv[0], O_RDONLY)) == (dbhead *) - 1) if ((dbh = dbf_open(argv[0], O_RDONLY)) == (dbhead *) - 1)
{ {
fprintf(stderr, "Couldn't open xbase-file %s\n", argv[0]); fprintf(stderr, "Couldn't open xbase-file %s\n", argv[0]);
......
...@@ -571,8 +571,8 @@ dblink_fetch(PG_FUNCTION_ARGS) ...@@ -571,8 +571,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
rsinfo->expectedDesc == NULL) rsinfo->expectedDesc == NULL)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context " errmsg("function returning record called in context "
"that cannot accept type record"))); "that cannot accept type record")));
/* get the requested return tuple description */ /* get the requested return tuple description */
tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc); tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc);
...@@ -777,8 +777,8 @@ dblink_record(PG_FUNCTION_ARGS) ...@@ -777,8 +777,8 @@ dblink_record(PG_FUNCTION_ARGS)
rsinfo->expectedDesc == NULL) rsinfo->expectedDesc == NULL)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context " errmsg("function returning record called in context "
"that cannot accept type record"))); "that cannot accept type record")));
/* get the requested return tuple description */ /* get the requested return tuple description */
tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc); tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc);
......
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,10 +50,11 @@ database_size(PG_FUNCTION_ARGS) ...@@ -50,10 +50,11 @@ 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;
HeapTuple tuple; HeapTuple tuple;
#endif #endif
dbid = get_database_oid(NameStr(*dbname)); dbid = get_database_oid(NameStr(*dbname));
...@@ -62,17 +63,18 @@ database_size(PG_FUNCTION_ARGS) ...@@ -62,17 +63,18 @@ database_size(PG_FUNCTION_ARGS)
(errcode(ERRCODE_UNDEFINED_DATABASE), (errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", NameStr(*dbname)))); errmsg("database \"%s\" does not exist", NameStr(*dbname))));
#ifdef SYMLINK #ifdef SYMLINK
dbrel = heap_openr(TableSpaceRelationName, AccessShareLock); dbrel = heap_openr(TableSpaceRelationName, AccessShareLock);
scan = heap_beginscan(dbrel, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(dbrel, SnapshotNow, 0, (ScanKey) NULL);
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);
...@@ -94,8 +96,8 @@ database_size(PG_FUNCTION_ARGS) ...@@ -94,8 +96,8 @@ database_size(PG_FUNCTION_ARGS)
static int64 static int64
get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK) get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK)
{ {
char *dbpath; char *dbpath;
DIR *dirdesc; DIR *dirdesc;
struct dirent *direntry; struct dirent *direntry;
int64 totalsize; int64 totalsize;
...@@ -104,11 +106,11 @@ get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK) ...@@ -104,11 +106,11 @@ 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,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m", dbpath))); errmsg("could not open directory \"%s\": %m", dbpath)));
} }
totalsize = 0; totalsize = 0;
......
This diff is collapsed.
...@@ -87,7 +87,7 @@ g_int_consistent(PG_FUNCTION_ARGS) ...@@ -87,7 +87,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
Datum Datum
g_int_union(PG_FUNCTION_ARGS) g_int_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);
int4 i; int4 i;
ArrayType *res; ArrayType *res;
...@@ -317,7 +317,7 @@ comparecost(const void *a, const void *b) ...@@ -317,7 +317,7 @@ comparecost(const void *a, const void *b)
Datum Datum
g_int_picksplit(PG_FUNCTION_ARGS) g_int_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);
OffsetNumber i, OffsetNumber i,
j; j;
...@@ -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.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
* pg_dumplo * pg_dumplo
* *
* $PostgreSQL: pgsql/contrib/pg_dumplo/utils.c,v 1.8 2003/11/29 19:51:35 pgsql Exp $ * $PostgreSQL: pgsql/contrib/pg_dumplo/utils.c,v 1.9 2004/08/29 05:06:36 momjian Exp $
* *
* Karel Zak 1999-2000 * Karel Zak 1999-2000
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
...@@ -30,7 +30,7 @@ void ...@@ -30,7 +30,7 @@ void
index_file(LODumpMaster * pgLO) index_file(LODumpMaster * pgLO)
{ {
char path[BUFSIZ]; char path[BUFSIZ];
int sz; int sz;
if (pgLO->action == ACTION_SHOW) if (pgLO->action == ACTION_SHOW)
return; return;
...@@ -51,7 +51,7 @@ index_file(LODumpMaster * pgLO) ...@@ -51,7 +51,7 @@ index_file(LODumpMaster * pgLO)
} }
sz = strlen(path); sz = strlen(path);
strncat(path, "/lo_dump.index", BUFSIZ-sz); strncat(path, "/lo_dump.index", BUFSIZ - sz);
if ((pgLO->index = fopen(path, "w")) == NULL) if ((pgLO->index = fopen(path, "w")) == NULL)
{ {
...@@ -63,7 +63,7 @@ index_file(LODumpMaster * pgLO) ...@@ -63,7 +63,7 @@ index_file(LODumpMaster * pgLO)
else if (pgLO->action != ACTION_NONE) else if (pgLO->action != ACTION_NONE)
{ {
sz = strlen(path); sz = strlen(path);
strncat(path, "/lo_dump.index", BUFSIZ-sz); strncat(path, "/lo_dump.index", BUFSIZ - sz);
if ((pgLO->index = fopen(path, "r")) == NULL) if ((pgLO->index = fopen(path, "r")) == NULL)
{ {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -875,7 +875,7 @@ get_crosstab_tuplestore(char *sql, ...@@ -875,7 +875,7 @@ get_crosstab_tuplestore(char *sql,
/* no qualifying category tuples */ /* no qualifying category tuples */
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("provided \"categories\" SQL must " \ errmsg("provided \"categories\" SQL must " \
"return 1 column of at least one row"))); "return 1 column of at least one row")));
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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