Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / contrib / btree_gist / btree_float4.c
bloba817ff6064c45756ea790a496be01af5251e9b43
1 /*
2 * $PostgreSQL$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct float4key
9 float4 lower;
10 float4 upper;
11 } float4KEY;
14 ** float4 ops
16 PG_FUNCTION_INFO_V1(gbt_float4_compress);
17 PG_FUNCTION_INFO_V1(gbt_float4_union);
18 PG_FUNCTION_INFO_V1(gbt_float4_picksplit);
19 PG_FUNCTION_INFO_V1(gbt_float4_consistent);
20 PG_FUNCTION_INFO_V1(gbt_float4_penalty);
21 PG_FUNCTION_INFO_V1(gbt_float4_same);
23 Datum gbt_float4_compress(PG_FUNCTION_ARGS);
24 Datum gbt_float4_union(PG_FUNCTION_ARGS);
25 Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
26 Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
27 Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
28 Datum gbt_float4_same(PG_FUNCTION_ARGS);
30 static bool
31 gbt_float4gt(const void *a, const void *b)
33 return (*((float4 *) a) > *((float4 *) b));
35 static bool
36 gbt_float4ge(const void *a, const void *b)
38 return (*((float4 *) a) >= *((float4 *) b));
40 static bool
41 gbt_float4eq(const void *a, const void *b)
43 return (*((float4 *) a) == *((float4 *) b));
45 static bool
46 gbt_float4le(const void *a, const void *b)
48 return (*((float4 *) a) <= *((float4 *) b));
50 static bool
51 gbt_float4lt(const void *a, const void *b)
53 return (*((float4 *) a) < *((float4 *) b));
56 static int
57 gbt_float4key_cmp(const void *a, const void *b)
60 if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
61 return 1;
62 else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
63 return -1;
64 return 0;
69 static const gbtree_ninfo tinfo =
71 gbt_t_float4,
72 sizeof(float4),
73 gbt_float4gt,
74 gbt_float4ge,
75 gbt_float4eq,
76 gbt_float4le,
77 gbt_float4lt,
78 gbt_float4key_cmp
82 /**************************************************
83 * float4 ops
84 **************************************************/
87 Datum
88 gbt_float4_compress(PG_FUNCTION_ARGS)
90 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
91 GISTENTRY *retval = NULL;
93 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
97 Datum
98 gbt_float4_consistent(PG_FUNCTION_ARGS)
100 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
101 float4 query = PG_GETARG_FLOAT4(1);
102 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
104 /* Oid subtype = PG_GETARG_OID(3); */
105 bool *recheck = (bool *) PG_GETARG_POINTER(4);
106 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
107 GBT_NUMKEY_R key;
109 /* All cases served by this function are exact */
110 *recheck = false;
112 key.lower = (GBT_NUMKEY *) &kkk->lower;
113 key.upper = (GBT_NUMKEY *) &kkk->upper;
115 PG_RETURN_BOOL(
116 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
121 Datum
122 gbt_float4_union(PG_FUNCTION_ARGS)
124 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
125 void *out = palloc(sizeof(float4KEY));
127 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
128 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
132 Datum
133 gbt_float4_penalty(PG_FUNCTION_ARGS)
135 float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
136 float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
137 float *result = (float *) PG_GETARG_POINTER(2);
139 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
141 PG_RETURN_POINTER(result);
145 Datum
146 gbt_float4_picksplit(PG_FUNCTION_ARGS)
148 PG_RETURN_POINTER(gbt_num_picksplit(
149 (GistEntryVector *) PG_GETARG_POINTER(0),
150 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
151 &tinfo
155 Datum
156 gbt_float4_same(PG_FUNCTION_ARGS)
158 float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
159 float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
160 bool *result = (bool *) PG_GETARG_POINTER(2);
162 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
163 PG_RETURN_POINTER(result);