2 * contrib/btree_gist/btree_float8.c
6 #include "btree_gist.h"
7 #include "btree_utils_num.h"
9 typedef struct float8key
18 PG_FUNCTION_INFO_V1(gbt_float8_compress);
19 PG_FUNCTION_INFO_V1(gbt_float8_fetch);
20 PG_FUNCTION_INFO_V1(gbt_float8_union);
21 PG_FUNCTION_INFO_V1(gbt_float8_picksplit);
22 PG_FUNCTION_INFO_V1(gbt_float8_consistent);
23 PG_FUNCTION_INFO_V1(gbt_float8_distance);
24 PG_FUNCTION_INFO_V1(gbt_float8_penalty);
25 PG_FUNCTION_INFO_V1(gbt_float8_same);
29 gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
31 return (*((const float8 *) a) > *((const float8 *) b));
34 gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
36 return (*((const float8 *) a) >= *((const float8 *) b));
39 gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
41 return (*((const float8 *) a) == *((const float8 *) b));
44 gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
46 return (*((const float8 *) a) <= *((const float8 *) b));
49 gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
51 return (*((const float8 *) a) < *((const float8 *) b));
55 gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
57 float8KEY *ia = (float8KEY *) (((const Nsrt *) a)->t);
58 float8KEY *ib = (float8KEY *) (((const Nsrt *) b)->t);
60 if (ia->lower == ib->lower)
62 if (ia->upper == ib->upper)
65 return (ia->upper > ib->upper) ? 1 : -1;
68 return (ia->lower > ib->lower) ? 1 : -1;
72 gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
74 float8 arg1 = *(const float8 *) a;
75 float8 arg2 = *(const float8 *) b;
79 CHECKFLOATVAL(r, isinf(arg1) || isinf(arg2), true);
85 static const gbtree_ninfo tinfo =
89 16, /* sizeof(gbtreekey16) */
100 PG_FUNCTION_INFO_V1(float8_dist);
102 float8_dist(PG_FUNCTION_ARGS)
104 float8 a = PG_GETARG_FLOAT8(0);
105 float8 b = PG_GETARG_FLOAT8(1);
109 CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
111 PG_RETURN_FLOAT8(Abs(r));
114 /**************************************************
116 **************************************************/
120 gbt_float8_compress(PG_FUNCTION_ARGS)
122 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
124 PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
128 gbt_float8_fetch(PG_FUNCTION_ARGS)
130 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
132 PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
136 gbt_float8_consistent(PG_FUNCTION_ARGS)
138 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139 float8 query = PG_GETARG_FLOAT8(1);
140 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
142 /* Oid subtype = PG_GETARG_OID(3); */
143 bool *recheck = (bool *) PG_GETARG_POINTER(4);
144 float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
147 /* All cases served by this function are exact */
150 key.lower = (GBT_NUMKEY *) &kkk->lower;
151 key.upper = (GBT_NUMKEY *) &kkk->upper;
154 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
160 gbt_float8_distance(PG_FUNCTION_ARGS)
162 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
163 float8 query = PG_GETARG_FLOAT8(1);
165 /* Oid subtype = PG_GETARG_OID(3); */
166 float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
169 key.lower = (GBT_NUMKEY *) &kkk->lower;
170 key.upper = (GBT_NUMKEY *) &kkk->upper;
173 gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
179 gbt_float8_union(PG_FUNCTION_ARGS)
181 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
182 void *out = palloc(sizeof(float8KEY));
184 *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
185 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
190 gbt_float8_penalty(PG_FUNCTION_ARGS)
192 float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
193 float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
194 float *result = (float *) PG_GETARG_POINTER(2);
196 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
198 PG_RETURN_POINTER(result);
203 gbt_float8_picksplit(PG_FUNCTION_ARGS)
205 PG_RETURN_POINTER(gbt_num_picksplit(
206 (GistEntryVector *) PG_GETARG_POINTER(0),
207 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
208 &tinfo, fcinfo->flinfo
213 gbt_float8_same(PG_FUNCTION_ARGS)
215 float8KEY *b1 = (float8KEY *) PG_GETARG_POINTER(0);
216 float8KEY *b2 = (float8KEY *) PG_GETARG_POINTER(1);
217 bool *result = (bool *) PG_GETARG_POINTER(2);
219 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
220 PG_RETURN_POINTER(result);