2 * contrib/btree_gist/btree_oid.c
6 #include "btree_gist.h"
7 #include "btree_utils_num.h"
18 PG_FUNCTION_INFO_V1(gbt_oid_compress);
19 PG_FUNCTION_INFO_V1(gbt_oid_fetch);
20 PG_FUNCTION_INFO_V1(gbt_oid_union);
21 PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
22 PG_FUNCTION_INFO_V1(gbt_oid_consistent);
23 PG_FUNCTION_INFO_V1(gbt_oid_distance);
24 PG_FUNCTION_INFO_V1(gbt_oid_penalty);
25 PG_FUNCTION_INFO_V1(gbt_oid_same);
29 gbt_oidgt(const void *a, const void *b, FmgrInfo *flinfo)
31 return (*((const Oid *) a) > *((const Oid *) b));
34 gbt_oidge(const void *a, const void *b, FmgrInfo *flinfo)
36 return (*((const Oid *) a) >= *((const Oid *) b));
39 gbt_oideq(const void *a, const void *b, FmgrInfo *flinfo)
41 return (*((const Oid *) a) == *((const Oid *) b));
44 gbt_oidle(const void *a, const void *b, FmgrInfo *flinfo)
46 return (*((const Oid *) a) <= *((const Oid *) b));
49 gbt_oidlt(const void *a, const void *b, FmgrInfo *flinfo)
51 return (*((const Oid *) a) < *((const Oid *) b));
55 gbt_oidkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
57 oidKEY *ia = (oidKEY *) (((const Nsrt *) a)->t);
58 oidKEY *ib = (oidKEY *) (((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_oid_dist(const void *a, const void *b, FmgrInfo *flinfo)
74 Oid aa = *(const Oid *) a;
75 Oid bb = *(const Oid *) b;
78 return (float8) (bb - aa);
80 return (float8) (aa - bb);
84 static const gbtree_ninfo tinfo =
88 8, /* sizeof(gbtreekey8) */
99 PG_FUNCTION_INFO_V1(oid_dist);
101 oid_dist(PG_FUNCTION_ARGS)
103 Oid a = PG_GETARG_OID(0);
104 Oid b = PG_GETARG_OID(1);
115 /**************************************************
117 **************************************************/
121 gbt_oid_compress(PG_FUNCTION_ARGS)
123 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
125 PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
129 gbt_oid_fetch(PG_FUNCTION_ARGS)
131 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
133 PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
137 gbt_oid_consistent(PG_FUNCTION_ARGS)
139 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
140 Oid query = PG_GETARG_OID(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 oidKEY *kkk = (oidKEY *) 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, fcinfo->flinfo)
161 gbt_oid_distance(PG_FUNCTION_ARGS)
163 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
164 Oid query = PG_GETARG_OID(1);
166 /* Oid subtype = PG_GETARG_OID(3); */
167 oidKEY *kkk = (oidKEY *) 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, fcinfo->flinfo)
180 gbt_oid_union(PG_FUNCTION_ARGS)
182 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
183 void *out = palloc(sizeof(oidKEY));
185 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
186 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
191 gbt_oid_penalty(PG_FUNCTION_ARGS)
193 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
194 oidKEY *newentry = (oidKEY *) 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_oid_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_oid_same(PG_FUNCTION_ARGS)
215 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
216 oidKEY *b2 = (oidKEY *) 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);