Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / contrib / btree_gist / btree_utils_num.h
blobe84d5f975dffc4b6e7c277adf933710d973c61cd
1 /*
2 * $PostgreSQL$
3 */
4 #ifndef __BTREE_UTILS_NUM_H__
5 #define __BTREE_UTILS_NUM_H__
7 #include "btree_gist.h"
8 #include "utils/rel.h"
10 #include <math.h>
11 #include <float.h>
13 typedef char GBT_NUMKEY;
15 /* Better readable key */
16 typedef struct
18 const GBT_NUMKEY *lower,
19 *upper;
20 } GBT_NUMKEY_R;
23 /* for sorting */
24 typedef struct
26 int i;
27 GBT_NUMKEY *t;
28 } Nsrt;
31 /* type description */
33 typedef struct
36 /* Attribs */
38 enum gbtree_type t; /* data type */
39 int32 size; /* size of type , 0 means variable */
41 /* Methods */
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 */
49 } gbtree_ninfo;
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 { \
62 double tmp = 0.0F; \
63 (*(result)) = 0.0F; \
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 ); \
68 if (tmp > 0.0F) \
69 { \
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)); \
73 } \
74 } while (0);
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))
87 #else
88 #define INTERVAL_TO_SEC(ivp) \
89 ((ivp)->time + \
90 (ivp)->day * (24.0 * SECS_PER_HOUR) + \
91 (ivp)->month * (30.0 * SECS_PER_DAY))
92 #endif
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);
115 #endif