1 #include "btree_gist.h"
2 #include "btree_utils_num.h"
4 typedef struct float4key
13 PG_FUNCTION_INFO_V1(gbt_float4_compress);
14 PG_FUNCTION_INFO_V1(gbt_float4_union);
15 PG_FUNCTION_INFO_V1(gbt_float4_picksplit);
16 PG_FUNCTION_INFO_V1(gbt_float4_consistent);
17 PG_FUNCTION_INFO_V1(gbt_float4_penalty);
18 PG_FUNCTION_INFO_V1(gbt_float4_same);
20 Datum gbt_float4_compress(PG_FUNCTION_ARGS);
21 Datum gbt_float4_union(PG_FUNCTION_ARGS);
22 Datum gbt_float4_picksplit(PG_FUNCTION_ARGS);
23 Datum gbt_float4_consistent(PG_FUNCTION_ARGS);
24 Datum gbt_float4_penalty(PG_FUNCTION_ARGS);
25 Datum gbt_float4_same(PG_FUNCTION_ARGS);
28 gbt_float4gt(const void *a, const void *b)
30 return (*((float4 *) a) > *((float4 *) b));
33 gbt_float4ge(const void *a, const void *b)
35 return (*((float4 *) a) >= *((float4 *) b));
38 gbt_float4eq(const void *a, const void *b)
40 return (*((float4 *) a) == *((float4 *) b));
43 gbt_float4le(const void *a, const void *b)
45 return (*((float4 *) a) <= *((float4 *) b));
48 gbt_float4lt(const void *a, const void *b)
50 return (*((float4 *) a) < *((float4 *) b));
54 gbt_float4key_cmp(const void *a, const void *b)
57 if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
59 else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
66 static const gbtree_ninfo tinfo =
79 /**************************************************
81 **************************************************/
85 gbt_float4_compress(PG_FUNCTION_ARGS)
87 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
88 GISTENTRY *retval = NULL;
90 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
95 gbt_float4_consistent(PG_FUNCTION_ARGS)
97 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
98 float4 query = PG_GETARG_FLOAT4(1);
99 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
101 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
103 key.lower = (GBT_NUMKEY *) & kkk->lower;
104 key.upper = (GBT_NUMKEY *) & kkk->upper;
107 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
113 gbt_float4_union(PG_FUNCTION_ARGS)
115 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
116 void *out = palloc(sizeof(float4KEY));
118 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
119 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
124 gbt_float4_penalty(PG_FUNCTION_ARGS)
126 float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
127 float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
128 float *result = (float *) PG_GETARG_POINTER(2);
130 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
132 PG_RETURN_POINTER(result);
137 gbt_float4_picksplit(PG_FUNCTION_ARGS)
139 PG_RETURN_POINTER(gbt_num_picksplit(
140 (GistEntryVector *) PG_GETARG_POINTER(0),
141 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
147 gbt_float4_same(PG_FUNCTION_ARGS)
149 float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
150 float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
151 bool *result = (bool *) PG_GETARG_POINTER(2);
153 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
154 PG_RETURN_POINTER(result);