2 * $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct float4key
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);
31 gbt_float4gt(const void *a, const void *b)
33 return (*((float4 *) a) > *((float4 *) b));
36 gbt_float4ge(const void *a, const void *b)
38 return (*((float4 *) a) >= *((float4 *) b));
41 gbt_float4eq(const void *a, const void *b)
43 return (*((float4 *) a) == *((float4 *) b));
46 gbt_float4le(const void *a, const void *b)
48 return (*((float4 *) a) <= *((float4 *) b));
51 gbt_float4lt(const void *a, const void *b)
53 return (*((float4 *) a) < *((float4 *) b));
57 gbt_float4key_cmp(const void *a, const void *b)
59 float4KEY *ia = (float4KEY *) (((Nsrt *) a)->t);
60 float4KEY *ib = (float4KEY *) (((Nsrt *) b)->t);
62 if (ia->lower == ib->lower)
64 if (ia->upper == ib->upper)
67 return (ia->upper > ib->upper) ? 1 : -1;
70 return (ia->lower > ib->lower) ? 1 : -1;
74 static const gbtree_ninfo tinfo =
87 /**************************************************
89 **************************************************/
93 gbt_float4_compress(PG_FUNCTION_ARGS)
95 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
96 GISTENTRY *retval = NULL;
98 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
103 gbt_float4_consistent(PG_FUNCTION_ARGS)
105 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
106 float4 query = PG_GETARG_FLOAT4(1);
107 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
109 /* Oid subtype = PG_GETARG_OID(3); */
110 bool *recheck = (bool *) PG_GETARG_POINTER(4);
111 float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
114 /* All cases served by this function are exact */
117 key.lower = (GBT_NUMKEY *) &kkk->lower;
118 key.upper = (GBT_NUMKEY *) &kkk->upper;
121 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
127 gbt_float4_union(PG_FUNCTION_ARGS)
129 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
130 void *out = palloc(sizeof(float4KEY));
132 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
133 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
138 gbt_float4_penalty(PG_FUNCTION_ARGS)
140 float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
141 float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
142 float *result = (float *) PG_GETARG_POINTER(2);
144 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
146 PG_RETURN_POINTER(result);
151 gbt_float4_picksplit(PG_FUNCTION_ARGS)
153 PG_RETURN_POINTER(gbt_num_picksplit(
154 (GistEntryVector *) PG_GETARG_POINTER(0),
155 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
161 gbt_float4_same(PG_FUNCTION_ARGS)
163 float4KEY *b1 = (float4KEY *) PG_GETARG_POINTER(0);
164 float4KEY *b2 = (float4KEY *) PG_GETARG_POINTER(1);
165 bool *result = (bool *) PG_GETARG_POINTER(2);
167 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
168 PG_RETURN_POINTER(result);