2 * contrib/btree_gist/btree_int8.c
6 #include "btree_gist.h"
7 #include "btree_utils_num.h"
9 typedef struct int64key
18 PG_FUNCTION_INFO_V1(gbt_int8_compress);
19 PG_FUNCTION_INFO_V1(gbt_int8_fetch);
20 PG_FUNCTION_INFO_V1(gbt_int8_union);
21 PG_FUNCTION_INFO_V1(gbt_int8_picksplit);
22 PG_FUNCTION_INFO_V1(gbt_int8_consistent);
23 PG_FUNCTION_INFO_V1(gbt_int8_distance);
24 PG_FUNCTION_INFO_V1(gbt_int8_penalty);
25 PG_FUNCTION_INFO_V1(gbt_int8_same);
29 gbt_int8gt(const void *a, const void *b)
31 return (*((const int64 *) a) > *((const int64 *) b));
34 gbt_int8ge(const void *a, const void *b)
36 return (*((const int64 *) a) >= *((const int64 *) b));
39 gbt_int8eq(const void *a, const void *b)
41 return (*((const int64 *) a) == *((const int64 *) b));
44 gbt_int8le(const void *a, const void *b)
46 return (*((const int64 *) a) <= *((const int64 *) b));
49 gbt_int8lt(const void *a, const void *b)
51 return (*((const int64 *) a) < *((const int64 *) b));
55 gbt_int8key_cmp(const void *a, const void *b)
57 int64KEY *ia = (int64KEY *) (((const Nsrt *) a)->t);
58 int64KEY *ib = (int64KEY *) (((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_int8_dist(const void *a, const void *b)
74 return GET_FLOAT_DISTANCE(int64, a, b);
78 static const gbtree_ninfo tinfo =
82 16, /* sizeof(gbtreekey16) */
93 PG_FUNCTION_INFO_V1(int8_dist);
95 int8_dist(PG_FUNCTION_ARGS)
97 int64 a = PG_GETARG_INT64(0);
98 int64 b = PG_GETARG_INT64(1);
105 /* Overflow check. */
106 if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
108 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
109 errmsg("bigint out of range")));
115 /**************************************************
117 **************************************************/
121 gbt_int8_compress(PG_FUNCTION_ARGS)
123 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
125 PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
129 gbt_int8_fetch(PG_FUNCTION_ARGS)
131 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
133 PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
137 gbt_int8_consistent(PG_FUNCTION_ARGS)
139 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
140 int64 query = PG_GETARG_INT64(1);
141 StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
143 /* Oid subtype = PG_GETARG_OID(3); */
144 bool *recheck = (bool *) PG_GETARG_POINTER(4);
145 int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
148 /* All cases served by this function are exact */
151 key.lower = (GBT_NUMKEY *) &kkk->lower;
152 key.upper = (GBT_NUMKEY *) &kkk->upper;
155 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
161 gbt_int8_distance(PG_FUNCTION_ARGS)
163 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
164 int64 query = PG_GETARG_INT64(1);
166 /* Oid subtype = PG_GETARG_OID(3); */
167 int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
170 key.lower = (GBT_NUMKEY *) &kkk->lower;
171 key.upper = (GBT_NUMKEY *) &kkk->upper;
174 gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
180 gbt_int8_union(PG_FUNCTION_ARGS)
182 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
183 void *out = palloc(sizeof(int64KEY));
185 *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
186 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
191 gbt_int8_penalty(PG_FUNCTION_ARGS)
193 int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
194 int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
195 float *result = (float *) PG_GETARG_POINTER(2);
197 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
199 PG_RETURN_POINTER(result);
203 gbt_int8_picksplit(PG_FUNCTION_ARGS)
205 PG_RETURN_POINTER(gbt_num_picksplit(
206 (GistEntryVector *) PG_GETARG_POINTER(0),
207 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
213 gbt_int8_same(PG_FUNCTION_ARGS)
215 int64KEY *b1 = (int64KEY *) PG_GETARG_POINTER(0);
216 int64KEY *b2 = (int64KEY *) PG_GETARG_POINTER(1);
217 bool *result = (bool *) PG_GETARG_POINTER(2);
219 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
220 PG_RETURN_POINTER(result);