4
#include "btree_gist.h"
5
#include "btree_utils_num.h"
6
#include "utils/builtins.h"
7
#include "utils/inet.h"
18
PG_FUNCTION_INFO_V1(gbt_macad_compress);
19
PG_FUNCTION_INFO_V1(gbt_macad_union);
20
PG_FUNCTION_INFO_V1(gbt_macad_picksplit);
21
PG_FUNCTION_INFO_V1(gbt_macad_consistent);
22
PG_FUNCTION_INFO_V1(gbt_macad_penalty);
23
PG_FUNCTION_INFO_V1(gbt_macad_same);
25
Datum gbt_macad_compress(PG_FUNCTION_ARGS);
26
Datum gbt_macad_union(PG_FUNCTION_ARGS);
27
Datum gbt_macad_picksplit(PG_FUNCTION_ARGS);
28
Datum gbt_macad_consistent(PG_FUNCTION_ARGS);
29
Datum gbt_macad_penalty(PG_FUNCTION_ARGS);
30
Datum gbt_macad_same(PG_FUNCTION_ARGS);
34
gbt_macadgt(const void *a, const void *b)
36
return DatumGetBool(DirectFunctionCall2(macaddr_gt, PointerGetDatum(a), PointerGetDatum(b)));
39
gbt_macadge(const void *a, const void *b)
41
return DatumGetBool(DirectFunctionCall2(macaddr_ge, PointerGetDatum(a), PointerGetDatum(b)));
45
gbt_macadeq(const void *a, const void *b)
47
return DatumGetBool(DirectFunctionCall2(macaddr_eq, PointerGetDatum(a), PointerGetDatum(b)));
51
gbt_macadle(const void *a, const void *b)
53
return DatumGetBool(DirectFunctionCall2(macaddr_le, PointerGetDatum(a), PointerGetDatum(b)));
57
gbt_macadlt(const void *a, const void *b)
59
return DatumGetBool(DirectFunctionCall2(macaddr_lt, PointerGetDatum(a), PointerGetDatum(b)));
64
gbt_macadkey_cmp(const void *a, const void *b)
69
PointerGetDatum(&((Nsrt *) a)->t[0]),
70
PointerGetDatum(&((Nsrt *) b)->t[0])
76
static const gbtree_ninfo tinfo =
89
/**************************************************
91
**************************************************/
96
mac_2_uint64(macaddr *m)
98
unsigned char *mi = (unsigned char *) m;
102
for (i = 0; i < 6; i++)
103
res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
110
gbt_macad_compress(PG_FUNCTION_ARGS)
112
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
113
GISTENTRY *retval = NULL;
115
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
120
gbt_macad_consistent(PG_FUNCTION_ARGS)
122
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
123
macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
124
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
125
/* Oid subtype = PG_GETARG_OID(3); */
126
bool *recheck = (bool *) PG_GETARG_POINTER(4);
127
macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
130
/* All cases served by this function are exact */
133
key.lower = (GBT_NUMKEY *) & kkk->lower;
134
key.upper = (GBT_NUMKEY *) & kkk->upper;
137
gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
143
gbt_macad_union(PG_FUNCTION_ARGS)
145
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
146
void *out = palloc(sizeof(macKEY));
148
*(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
149
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
154
gbt_macad_penalty(PG_FUNCTION_ARGS)
156
macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
157
macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
158
float *result = (float *) PG_GETARG_POINTER(2);
162
iorg[0] = mac_2_uint64(&origentry->lower);
163
iorg[1] = mac_2_uint64(&origentry->upper);
164
inew[0] = mac_2_uint64(&newentry->lower);
165
inew[1] = mac_2_uint64(&newentry->upper);
167
penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
169
PG_RETURN_POINTER(result);
174
gbt_macad_picksplit(PG_FUNCTION_ARGS)
176
PG_RETURN_POINTER(gbt_num_picksplit(
177
(GistEntryVector *) PG_GETARG_POINTER(0),
178
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
184
gbt_macad_same(PG_FUNCTION_ARGS)
186
macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
187
macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
188
bool *result = (bool *) PG_GETARG_POINTER(2);
190
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
191
PG_RETURN_POINTER(result);