Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / contrib / btree_gist / btree_int2.c
blob3971b80f402b572957c58028da6858e4e3e44cfe
1 /*
2 * $PostgreSQL$
3 */
4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct int16key
9 int16 lower;
10 int16 upper;
11 } int16KEY;
14 ** int16 ops
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);
30 static bool
31 gbt_int2gt(const void *a, const void *b)
33 return (*((int16 *) a) > *((int16 *) b));
35 static bool
36 gbt_int2ge(const void *a, const void *b)
38 return (*((int16 *) a) >= *((int16 *) b));
40 static bool
41 gbt_int2eq(const void *a, const void *b)
43 return (*((int16 *) a) == *((int16 *) b));
45 static bool
46 gbt_int2le(const void *a, const void *b)
48 return (*((int16 *) a) <= *((int16 *) b));
50 static bool
51 gbt_int2lt(const void *a, const void *b)
53 return (*((int16 *) a) < *((int16 *) b));
56 static int
57 gbt_int2key_cmp(const void *a, const void *b)
60 if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
61 return 1;
62 else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
63 return -1;
64 return 0;
69 static const gbtree_ninfo tinfo =
71 gbt_t_int2,
72 sizeof(int16),
73 gbt_int2gt,
74 gbt_int2ge,
75 gbt_int2eq,
76 gbt_int2le,
77 gbt_int2lt,
78 gbt_int2key_cmp
86 /**************************************************
87 * int16 ops
88 **************************************************/
91 Datum
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));
101 Datum
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);
108 /* Oid subtype = PG_GETARG_OID(3); */
109 bool *recheck = (bool *) PG_GETARG_POINTER(4);
110 int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
111 GBT_NUMKEY_R key;
113 /* All cases served by this function are exact */
114 *recheck = false;
116 key.lower = (GBT_NUMKEY *) &kkk->lower;
117 key.upper = (GBT_NUMKEY *) &kkk->upper;
119 PG_RETURN_BOOL(
120 gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
125 Datum
126 gbt_int2_union(PG_FUNCTION_ARGS)
128 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
129 void *out = palloc(sizeof(int16KEY));
131 *(int *) PG_GETARG_POINTER(1) = sizeof(int16KEY);
132 PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
136 Datum
137 gbt_int2_penalty(PG_FUNCTION_ARGS)
139 int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
140 int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
141 float *result = (float *) PG_GETARG_POINTER(2);
143 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
145 PG_RETURN_POINTER(result);
148 Datum
149 gbt_int2_picksplit(PG_FUNCTION_ARGS)
151 PG_RETURN_POINTER(gbt_num_picksplit(
152 (GistEntryVector *) PG_GETARG_POINTER(0),
153 (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
154 &tinfo
158 Datum
159 gbt_int2_same(PG_FUNCTION_ARGS)
161 int16KEY *b1 = (int16KEY *) PG_GETARG_POINTER(0);
162 int16KEY *b2 = (int16KEY *) PG_GETARG_POINTER(1);
163 bool *result = (bool *) PG_GETARG_POINTER(2);
165 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
166 PG_RETURN_POINTER(result);