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);
126 /* Oid subtype = PG_GETARG_OID(3); */
127 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
128 macKEY
*kkk
= (macKEY
*) DatumGetPointer(entry
->key
);
131 /* All cases served by this function are exact */
134 key
.lower
= (GBT_NUMKEY
*) &kkk
->lower
;
135 key
.upper
= (GBT_NUMKEY
*) &kkk
->upper
;
138 gbt_num_consistent(&key
, (void *) query
, &strategy
, GIST_LEAF(entry
), &tinfo
)
144 gbt_macad_union(PG_FUNCTION_ARGS
)
146 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
147 void *out
= palloc(sizeof(macKEY
));
149 *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY
);
150 PG_RETURN_POINTER(gbt_num_union((void *) out
, entryvec
, &tinfo
));
155 gbt_macad_penalty(PG_FUNCTION_ARGS
)
157 macKEY
*origentry
= (macKEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(0))->key
);
158 macKEY
*newentry
= (macKEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(1))->key
);
159 float *result
= (float *) PG_GETARG_POINTER(2);
163 iorg
[0] = mac_2_uint64(&origentry
->lower
);
164 iorg
[1] = mac_2_uint64(&origentry
->upper
);
165 inew
[0] = mac_2_uint64(&newentry
->lower
);
166 inew
[1] = mac_2_uint64(&newentry
->upper
);
168 penalty_num(result
, iorg
[0], iorg
[1], inew
[0], inew
[1]);
170 PG_RETURN_POINTER(result
);
175 gbt_macad_picksplit(PG_FUNCTION_ARGS
)
177 PG_RETURN_POINTER(gbt_num_picksplit(
178 (GistEntryVector
*) PG_GETARG_POINTER(0),
179 (GIST_SPLITVEC
*) PG_GETARG_POINTER(1),
185 gbt_macad_same(PG_FUNCTION_ARGS
)
187 macKEY
*b1
= (macKEY
*) PG_GETARG_POINTER(0);
188 macKEY
*b2
= (macKEY
*) PG_GETARG_POINTER(1);
189 bool *result
= (bool *) PG_GETARG_POINTER(2);
191 *result
= gbt_num_same((void *) b1
, (void *) b2
, &tinfo
);
192 PG_RETURN_POINTER(result
);