aboutsummaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_int2.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/btree_gist/btree_int2.c')
-rw-r--r--contrib/btree_gist/btree_int2.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index 2859fa830b3..33eccdedd70 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -6,6 +6,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "common/int.h"
+#include "utils/sortsupport.h"
typedef struct int16key
{
@@ -22,6 +23,7 @@ PG_FUNCTION_INFO_V1(gbt_int2_consistent);
PG_FUNCTION_INFO_V1(gbt_int2_distance);
PG_FUNCTION_INFO_V1(gbt_int2_penalty);
PG_FUNCTION_INFO_V1(gbt_int2_same);
+PG_FUNCTION_INFO_V1(gbt_int2_sortsupport);
static bool
@@ -209,3 +211,27 @@ gbt_int2_same(PG_FUNCTION_ARGS)
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
PG_RETURN_POINTER(result);
}
+
+static int
+gbt_int2_ssup_cmp(Datum x, Datum y, SortSupport ssup)
+{
+ int16KEY *arg1 = (int16KEY *) DatumGetPointer(x);
+ int16KEY *arg2 = (int16KEY *) DatumGetPointer(y);
+
+ /* for leaf items we expect lower == upper, so only compare lower */
+ if (arg1->lower < arg2->lower)
+ return -1;
+ else if (arg1->lower > arg2->lower)
+ return 1;
+ else
+ return 0;
+}
+
+Datum
+gbt_int2_sortsupport(PG_FUNCTION_ARGS)
+{
+ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
+
+ ssup->comparator = gbt_int2_ssup_cmp;
+ PG_RETURN_VOID();
+}