New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
typedef char GBT_NUMKEY;
|
|
|
|
|
|
|
|
/* Better readable key */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
const GBT_NUMKEY *lower,
|
|
|
|
*upper;
|
|
|
|
} GBT_NUMKEY_R;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* for sorting */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-29 13:07:03 +08:00
|
|
|
int i;
|
|
|
|
GBT_NUMKEY *t;
|
|
|
|
} Nsrt;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* type description */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
/* Attribs */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
enum gbtree_type t; /* data type */
|
|
|
|
int32 size; /* size of type , 0 means variable */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
/* Methods */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
bool (*f_gt) (const void *, const void *); /* greater then */
|
|
|
|
bool (*f_ge) (const void *, const void *); /* greater equal */
|
|
|
|
bool (*f_eq) (const void *, const void *); /* equal */
|
|
|
|
bool (*f_le) (const void *, const void *); /* less equal */
|
|
|
|
bool (*f_lt) (const void *, const void *); /* less then */
|
|
|
|
int (*f_cmp) (const void *, const void *); /* key compare function */
|
|
|
|
} gbtree_ninfo;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-08-29 13:07:03 +08:00
|
|
|
* Numeric btree functions
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
*/
|
|
|
|
|
2004-06-03 20:26:10 +08:00
|
|
|
|
2005-07-01 21:44:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: The factor 0.49 in following macro avoids floating point overflows
|
|
|
|
*/
|
|
|
|
#define penalty_num(result,olower,oupper,nlower,nupper) do { \
|
2005-10-15 10:49:52 +08:00
|
|
|
double tmp = 0.0F; \
|
|
|
|
(*(result)) = 0.0F; \
|
2004-06-03 20:26:10 +08:00
|
|
|
if ( (nupper) > (oupper) ) \
|
2005-07-01 21:44:56 +08:00
|
|
|
tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
|
2004-08-29 13:07:03 +08:00
|
|
|
if ( (olower) > (nlower) ) \
|
2005-07-01 21:44:56 +08:00
|
|
|
tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
|
|
|
|
if (tmp > 0.0F) \
|
|
|
|
{ \
|
2005-10-15 10:49:52 +08:00
|
|
|
(*(result)) += FLT_MIN; \
|
|
|
|
(*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
|
|
|
|
(*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
|
2005-07-01 21:44:56 +08:00
|
|
|
} \
|
2004-06-03 20:26:10 +08:00
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
2005-07-21 12:15:04 +08:00
|
|
|
/*
|
|
|
|
* Convert an Interval to an approximate equivalent number of seconds
|
|
|
|
* (as a double). Here because we need it for time/timetz as well as
|
|
|
|
* interval. See interval_cmp_internal for comparison.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
|
|
|
#define INTERVAL_TO_SEC(ivp) \
|
|
|
|
(((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
|
|
|
|
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
|
|
|
|
(ivp)->month * (30.0 * SECS_PER_DAY))
|
|
|
|
#else
|
|
|
|
#define INTERVAL_TO_SEC(ivp) \
|
|
|
|
((ivp)->time + \
|
|
|
|
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
|
|
|
|
(ivp)->month * (30.0 * SECS_PER_DAY))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
|
|
|
|
const StrategyNumber *strategy, bool is_leaf,
|
|
|
|
const gbtree_ninfo * tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
|
|
|
|
const gbtree_ninfo * tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
|
|
|
|
const gbtree_ninfo * tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern void *gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec,
|
|
|
|
const gbtree_ninfo * tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern bool gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b,
|
|
|
|
const gbtree_ninfo * tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 18:43:32 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY * e,
|
|
|
|
const gbtree_ninfo * tinfo);
|