2 * contrib/btree_gist/btree_oid.c
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
16 PG_FUNCTION_INFO_V1(gbt_oid_compress);
17 PG_FUNCTION_INFO_V1(gbt_oid_union);
18 PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
19 PG_FUNCTION_INFO_V1(gbt_oid_consistent);
20 PG_FUNCTION_INFO_V1(gbt_oid_distance);
21 PG_FUNCTION_INFO_V1(gbt_oid_penalty);
22 PG_FUNCTION_INFO_V1(gbt_oid_same);
24 Datum gbt_oid_compress(PG_FUNCTION_ARGS);
25 Datum gbt_oid_union(PG_FUNCTION_ARGS);
26 Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
27 Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
28 Datum gbt_oid_distance(PG_FUNCTION_ARGS);
29 Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
30 Datum gbt_oid_same(PG_FUNCTION_ARGS);
34 gbt_oidgt(const void *a, const void *b)
36 return (*((Oid *) a) > *((Oid *) b));
39 gbt_oidge(const void *a, const void *b)
41 return (*((Oid *) a) >= *((Oid *) b));
44 gbt_oideq(const void *a, const void *b)
46 return (*((Oid *) a) == *((Oid *) b));
49 gbt_oidle(const void *a, const void *b)
51 return (*((Oid *) a) <= *((Oid *) b));
54 gbt_oidlt(const void *a, const void *b)
56 return (*((Oid *) a) < *((Oid *) b));
60 gbt_oidkey_cmp(const void *a, const void *b)
62 oidKEY *ia = (oidKEY *) (((Nsrt *) a)->t);
63 oidKEY *ib = (oidKEY *) (((Nsrt *) b)->t);
65 if (ia->lower == ib->lower)
67 if (ia->upper == ib->upper)
70 return (ia->upper > ib->upper) ? 1 : -1;
73 return (ia->lower > ib->lower) ? 1 : -1;
77 gbt_oid_dist(const void *a, const void *b)
79 Oid aa = *(const Oid *) a;
80 Oid bb = *(const Oid *) b;
83 return (float8) (bb - aa);
85 return (float8) (aa - bb);
89 static const gbtree_ninfo tinfo =
103 PG_FUNCTION_INFO_V1(oid_dist);
104 Datum oid_dist(PG_FUNCTION_ARGS);
106 oid_dist(PG_FUNCTION_ARGS)
108 Oid a = PG_GETARG_OID(0);
109 Oid b = PG_GETARG_OID(1);
120 /**************************************************
122 **************************************************/
126 gbt_oid_compress(PG_FUNCTION_ARGS)
128 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
129 GISTENTRY *retval = NULL;
131 PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
136 gbt_oid_consistent(PG_FUNCTION_ARGS)
138 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139 Oid query = PG_GETARG_OID(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 oidKEY *kkk = (oidKEY *) 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)
160 gbt_oid_distance(PG_FUNCTION_ARGS)
162 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
163 Oid query = PG_GETARG_OID(1);
165 /* Oid subtype = PG_GETARG_OID(3); */
166 oidKEY *kkk = (oidKEY *) 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)
179 gbt_oid_union(PG_FUNCTION_ARGS)
181 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
182 void *out = palloc(sizeof(oidKEY));
184 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
185 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
190 gbt_oid_penalty(PG_FUNCTION_ARGS)
192 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
193 oidKEY *newentry = (oidKEY *) 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);
202 gbt_oid_picksplit(PG_FUNCTION_ARGS)
204 PG_RETURN_POINTER(gbt_num_picksplit(
205 (GistEntryVector *) PG_GETARG_POINTER(0),
206 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
212 gbt_oid_same(PG_FUNCTION_ARGS)
214 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
215 oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
216 bool *result = (bool *) PG_GETARG_POINTER(2);
218 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
219 PG_RETURN_POINTER(result);