4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct int16key
16 PG_FUNCTION_INFO_V1(gbt_int2_compress
);
17 PG_FUNCTION_INFO_V1(gbt_int2_union
);
18 PG_FUNCTION_INFO_V1(gbt_int2_picksplit
);
19 PG_FUNCTION_INFO_V1(gbt_int2_consistent
);
20 PG_FUNCTION_INFO_V1(gbt_int2_penalty
);
21 PG_FUNCTION_INFO_V1(gbt_int2_same
);
23 Datum
gbt_int2_compress(PG_FUNCTION_ARGS
);
24 Datum
gbt_int2_union(PG_FUNCTION_ARGS
);
25 Datum
gbt_int2_picksplit(PG_FUNCTION_ARGS
);
26 Datum
gbt_int2_consistent(PG_FUNCTION_ARGS
);
27 Datum
gbt_int2_penalty(PG_FUNCTION_ARGS
);
28 Datum
gbt_int2_same(PG_FUNCTION_ARGS
);
31 gbt_int2gt(const void *a
, const void *b
)
33 return (*((int16
*) a
) > *((int16
*) b
));
36 gbt_int2ge(const void *a
, const void *b
)
38 return (*((int16
*) a
) >= *((int16
*) b
));
41 gbt_int2eq(const void *a
, const void *b
)
43 return (*((int16
*) a
) == *((int16
*) b
));
46 gbt_int2le(const void *a
, const void *b
)
48 return (*((int16
*) a
) <= *((int16
*) b
));
51 gbt_int2lt(const void *a
, const void *b
)
53 return (*((int16
*) a
) < *((int16
*) b
));
57 gbt_int2key_cmp(const void *a
, const void *b
)
60 if (*(int16
*) (&((Nsrt
*) a
)->t
[0]) > *(int16
*) &(((Nsrt
*) b
)->t
[0]))
62 else if (*(int16
*) &(((Nsrt
*) a
)->t
[0]) < *(int16
*) &(((Nsrt
*) b
)->t
[0]))
69 static const gbtree_ninfo tinfo
=
86 /**************************************************
88 **************************************************/
92 gbt_int2_compress(PG_FUNCTION_ARGS
)
94 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
95 GISTENTRY
*retval
= NULL
;
97 PG_RETURN_POINTER(gbt_num_compress(retval
, entry
, &tinfo
));
102 gbt_int2_consistent(PG_FUNCTION_ARGS
)
104 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
105 int16 query
= PG_GETARG_INT16(1);
106 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
107 /* Oid subtype = PG_GETARG_OID(3); */
108 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
109 int16KEY
*kkk
= (int16KEY
*) DatumGetPointer(entry
->key
);
112 /* All cases served by this function are exact */
115 key
.lower
= (GBT_NUMKEY
*) & kkk
->lower
;
116 key
.upper
= (GBT_NUMKEY
*) & kkk
->upper
;
119 gbt_num_consistent(&key
, (void *) &query
, &strategy
, GIST_LEAF(entry
), &tinfo
)
125 gbt_int2_union(PG_FUNCTION_ARGS
)
127 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
128 void *out
= palloc(sizeof(int16KEY
));
130 *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY
);
131 PG_RETURN_POINTER(gbt_num_union((void *) out
, entryvec
, &tinfo
));
136 gbt_int2_penalty(PG_FUNCTION_ARGS
)
138 int16KEY
*origentry
= (int16KEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(0))->key
);
139 int16KEY
*newentry
= (int16KEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(1))->key
);
140 float *result
= (float *) PG_GETARG_POINTER(2);
142 penalty_num(result
, origentry
->lower
, origentry
->upper
, newentry
->lower
, newentry
->upper
);
144 PG_RETURN_POINTER(result
);
148 gbt_int2_picksplit(PG_FUNCTION_ARGS
)
150 PG_RETURN_POINTER(gbt_num_picksplit(
151 (GistEntryVector
*) PG_GETARG_POINTER(0),
152 (GIST_SPLITVEC
*) PG_GETARG_POINTER(1),
158 gbt_int2_same(PG_FUNCTION_ARGS
)
160 int16KEY
*b1
= (int16KEY
*) PG_GETARG_POINTER(0);
161 int16KEY
*b2
= (int16KEY
*) PG_GETARG_POINTER(1);
162 bool *result
= (bool *) PG_GETARG_POINTER(2);
164 *result
= gbt_num_same((void *) b1
, (void *) b2
, &tinfo
);
165 PG_RETURN_POINTER(result
);