aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_oid.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist/btree_oid.c')
-rw-r--r--contrib/btree_gist/btree_oid.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c
index 4927448258f..c81dd31799e 100644
--- a/contrib/btree_gist/btree_oid.c
+++ b/contrib/btree_gist/btree_oid.c
@@ -17,6 +17,7 @@ PG_FUNCTION_INFO_V1(gbt_oid_compress);
PG_FUNCTION_INFO_V1(gbt_oid_union);
PG_FUNCTION_INFO_V1(gbt_oid_picksplit);
PG_FUNCTION_INFO_V1(gbt_oid_consistent);
+PG_FUNCTION_INFO_V1(gbt_oid_distance);
PG_FUNCTION_INFO_V1(gbt_oid_penalty);
PG_FUNCTION_INFO_V1(gbt_oid_same);
@@ -24,6 +25,7 @@ Datum gbt_oid_compress(PG_FUNCTION_ARGS);
Datum gbt_oid_union(PG_FUNCTION_ARGS);
Datum gbt_oid_picksplit(PG_FUNCTION_ARGS);
Datum gbt_oid_consistent(PG_FUNCTION_ARGS);
+Datum gbt_oid_distance(PG_FUNCTION_ARGS);
Datum gbt_oid_penalty(PG_FUNCTION_ARGS);
Datum gbt_oid_same(PG_FUNCTION_ARGS);
@@ -71,6 +73,18 @@ gbt_oidkey_cmp(const void *a, const void *b)
return (ia->lower > ib->lower) ? 1 : -1;
}
+static float8
+gbt_oid_dist(const void *a, const void *b)
+{
+ Oid aa = *(const Oid *) a;
+ Oid bb = *(const Oid *) b;
+
+ if (aa < bb)
+ return (float8) (bb - aa);
+ else
+ return (float8) (aa - bb);
+}
+
static const gbtree_ninfo tinfo =
{
@@ -81,10 +95,28 @@ static const gbtree_ninfo tinfo =
gbt_oideq,
gbt_oidle,
gbt_oidlt,
- gbt_oidkey_cmp
+ gbt_oidkey_cmp,
+ gbt_oid_dist
};
+PG_FUNCTION_INFO_V1(oid_dist);
+Datum oid_dist(PG_FUNCTION_ARGS);
+Datum
+oid_dist(PG_FUNCTION_ARGS)
+{
+ Oid a = PG_GETARG_OID(0);
+ Oid b = PG_GETARG_OID(1);
+ Oid res;
+
+ if (a < b)
+ res = b - a;
+ else
+ res = a - b;
+ PG_RETURN_OID(res);
+}
+
+
/**************************************************
* Oid ops
**************************************************/
@@ -125,6 +157,25 @@ gbt_oid_consistent(PG_FUNCTION_ARGS)
Datum
+gbt_oid_distance(PG_FUNCTION_ARGS)
+{
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ Oid query = PG_GETARG_OID(1);
+
+ /* Oid subtype = PG_GETARG_OID(3); */
+ oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
+ GBT_NUMKEY_R key;
+
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
+
+ PG_RETURN_FLOAT8(
+ gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
+ );
+}
+
+
+Datum
gbt_oid_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);