4 #ifndef __BTREE_UTILS_NUM_H__
5 #define __BTREE_UTILS_NUM_H__
7 #include "btree_gist.h"
13 typedef char GBT_NUMKEY
;
15 /* Better readable key */
18 const GBT_NUMKEY
*lower
,
31 /* type description */
38 enum gbtree_type t
; /* data type */
39 int32 size
; /* size of type , 0 means variable */
43 bool (*f_gt
) (const void *, const void *); /* greater then */
44 bool (*f_ge
) (const void *, const void *); /* greater equal */
45 bool (*f_eq
) (const void *, const void *); /* equal */
46 bool (*f_le
) (const void *, const void *); /* less equal */
47 bool (*f_lt
) (const void *, const void *); /* less then */
48 int (*f_cmp
) (const void *, const void *); /* key compare function */
53 * Numeric btree functions
59 * Note: The factor 0.49 in following macro avoids floating point overflows
61 #define penalty_num(result,olower,oupper,nlower,nupper) do { \
64 if ( (nupper) > (oupper) ) \
65 tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
66 if ( (olower) > (nlower) ) \
67 tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
70 (*(result)) += FLT_MIN; \
71 (*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
72 (*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
78 * Convert an Interval to an approximate equivalent number of seconds
79 * (as a double). Here because we need it for time/timetz as well as
80 * interval. See interval_cmp_internal for comparison.
82 #ifdef HAVE_INT64_TIMESTAMP
83 #define INTERVAL_TO_SEC(ivp) \
84 (((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
85 (ivp)->day * (24.0 * SECS_PER_HOUR) + \
86 (ivp)->month * (30.0 * SECS_PER_DAY))
88 #define INTERVAL_TO_SEC(ivp) \
90 (ivp)->day * (24.0 * SECS_PER_HOUR) + \
91 (ivp)->month * (30.0 * SECS_PER_DAY))
95 extern bool gbt_num_consistent(const GBT_NUMKEY_R
*key
, const void *query
,
96 const StrategyNumber
*strategy
, bool is_leaf
,
97 const gbtree_ninfo
*tinfo
);
99 extern GIST_SPLITVEC
*gbt_num_picksplit(const GistEntryVector
*entryvec
, GIST_SPLITVEC
*v
,
100 const gbtree_ninfo
*tinfo
);
102 extern GISTENTRY
*gbt_num_compress(GISTENTRY
*retval
, GISTENTRY
*entry
,
103 const gbtree_ninfo
*tinfo
);
106 extern void *gbt_num_union(GBT_NUMKEY
*out
, const GistEntryVector
*entryvec
,
107 const gbtree_ninfo
*tinfo
);
109 extern bool gbt_num_same(const GBT_NUMKEY
*a
, const GBT_NUMKEY
*b
,
110 const gbtree_ninfo
*tinfo
);
112 extern void gbt_num_bin_union(Datum
*u
, GBT_NUMKEY
*e
,
113 const gbtree_ninfo
*tinfo
);