PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_macaddr.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/builtins.h"
#include "utils/inet.h"
Include dependency graph for btree_macaddr.c:

Go to the source code of this file.

Data Structures

struct  macKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_macad_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_union)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_macad_same)
 
static bool gbt_macadgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_macadge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_macadeq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_macadle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_macadlt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_macadkey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static uint64 mac_2_uint64 (macaddr *m)
 
Datum gbt_macad_compress (PG_FUNCTION_ARGS)
 
Datum gbt_macad_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_macad_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_macad_union (PG_FUNCTION_ARGS)
 
Datum gbt_macad_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_macad_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_macad_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

Datum gbt_macad_compress ( PG_FUNCTION_ARGS  )

Definition at line 111 of file btree_macaddr.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

112 {
113  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
114 
116 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
Datum gbt_macad_consistent ( PG_FUNCTION_ARGS  )

Definition at line 127 of file btree_macaddr.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, macKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, macKEY::upper, and GBT_NUMKEY_R::upper.

128 {
129  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
130  macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
132 
133  /* Oid subtype = PG_GETARG_OID(3); */
134  bool *recheck = (bool *) PG_GETARG_POINTER(4);
135  macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
136  GBT_NUMKEY_R key;
137 
138  /* All cases served by this function are exact */
139  *recheck = false;
140 
141  key.lower = (GBT_NUMKEY *) &kkk->lower;
142  key.upper = (GBT_NUMKEY *) &kkk->upper;
143 
145  gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
146  );
147 }
#define GIST_LEAF(entry)
Definition: gist.h:133
macaddr lower
Definition: btree_macaddr.c:13
const GBT_NUMKEY * lower
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
macaddr upper
Definition: btree_macaddr.c:14
Definition: inet.h:94
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
Datum gbt_macad_fetch ( PG_FUNCTION_ARGS  )

Definition at line 119 of file btree_macaddr.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

120 {
121  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
122 
124 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
Datum gbt_macad_penalty ( PG_FUNCTION_ARGS  )

Definition at line 162 of file btree_macaddr.c.

References DatumGetPointer, macKEY::lower, mac_2_uint64(), penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and macKEY::upper.

163 {
164  macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
165  macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
166  float *result = (float *) PG_GETARG_POINTER(2);
167  uint64 iorg[2],
168  inew[2];
169 
170  iorg[0] = mac_2_uint64(&origentry->lower);
171  iorg[1] = mac_2_uint64(&origentry->upper);
172  inew[0] = mac_2_uint64(&newentry->lower);
173  inew[1] = mac_2_uint64(&newentry->upper);
174 
175  penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
176 
177  PG_RETURN_POINTER(result);
178 
179 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
macaddr lower
Definition: btree_macaddr.c:13
static uint64 mac_2_uint64(macaddr *m)
Definition: btree_macaddr.c:97
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define penalty_num(result, olower, oupper, nlower, nupper)
macaddr upper
Definition: btree_macaddr.c:14
#define DatumGetPointer(X)
Definition: postgres.h:555
Datum gbt_macad_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 182 of file btree_macaddr.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

183 {
187  &tinfo, fcinfo->flinfo
188  ));
189 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum gbt_macad_same ( PG_FUNCTION_ARGS  )

Definition at line 192 of file btree_macaddr.c.

References gbt_num_same(), PG_GETARG_POINTER, PG_RETURN_POINTER, and result.

193 {
194  macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
195  macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
196  bool *result = (bool *) PG_GETARG_POINTER(2);
197 
198  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
199  PG_RETURN_POINTER(result);
200 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
Datum gbt_macad_union ( PG_FUNCTION_ARGS  )

Definition at line 151 of file btree_macaddr.c.

References gbt_num_union(), palloc0(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

152 {
154  void *out = palloc0(sizeof(macKEY));
155 
156  *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
157  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
158 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
void * palloc0(Size size)
Definition: mcxt.c:878
static const gbtree_ninfo tinfo
Definition: btree_macaddr.c:75
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static bool gbt_macadeq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 42 of file btree_macaddr.c.

References DatumGetBool, DirectFunctionCall2, macaddr_eq(), and PointerGetDatum.

43 {
45 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetBool(X)
Definition: postgres.h:399
Datum macaddr_eq(PG_FUNCTION_ARGS)
Definition: mac.c:228
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
static bool gbt_macadge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 36 of file btree_macaddr.c.

References DatumGetBool, DirectFunctionCall2, macaddr_ge(), and PointerGetDatum.

37 {
39 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum macaddr_ge(PG_FUNCTION_ARGS)
Definition: mac.c:237
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
static bool gbt_macadgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 31 of file btree_macaddr.c.

References DatumGetBool, DirectFunctionCall2, macaddr_gt(), and PointerGetDatum.

32 {
34 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum macaddr_gt(PG_FUNCTION_ARGS)
Definition: mac.c:246
static int gbt_macadkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 61 of file btree_macaddr.c.

References DatumGetInt32, DirectFunctionCall2, macKEY::lower, macaddr_cmp(), MacaddrPGetDatum, and macKEY::upper.

62 {
63  macKEY *ia = (macKEY *) (((const Nsrt *) a)->t);
64  macKEY *ib = (macKEY *) (((const Nsrt *) b)->t);
65  int res;
66 
68  if (res == 0)
70 
71  return res;
72 }
macaddr lower
Definition: btree_macaddr.c:13
#define DatumGetInt32(X)
Definition: postgres.h:478
#define MacaddrPGetDatum(X)
Definition: inet.h:132
macaddr upper
Definition: btree_macaddr.c:14
Datum macaddr_cmp(PG_FUNCTION_ARGS)
Definition: mac.c:197
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
static bool gbt_macadle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 48 of file btree_macaddr.c.

References DatumGetBool, DirectFunctionCall2, macaddr_le(), and PointerGetDatum.

49 {
51 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum macaddr_le(PG_FUNCTION_ARGS)
Definition: mac.c:219
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
static bool gbt_macadlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 54 of file btree_macaddr.c.

References DatumGetBool, DirectFunctionCall2, macaddr_lt(), and PointerGetDatum.

55 {
57 }
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum macaddr_lt(PG_FUNCTION_ARGS)
Definition: mac.c:210
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
static uint64 mac_2_uint64 ( macaddr m)
static

Definition at line 97 of file btree_macaddr.c.

References i.

Referenced by gbt_macad_penalty().

98 {
99  unsigned char *mi = (unsigned char *) m;
100  uint64 res = 0;
101  int i;
102 
103  for (i = 0; i < 6; i++)
104  res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
105  return res;
106 }
int i
PG_FUNCTION_INFO_V1 ( gbt_macad_compress  )
PG_FUNCTION_INFO_V1 ( gbt_macad_fetch  )
PG_FUNCTION_INFO_V1 ( gbt_macad_union  )
PG_FUNCTION_INFO_V1 ( gbt_macad_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_macad_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_macad_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_macad_same  )

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(macaddr),
16,
}
static int gbt_macadkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:61
static bool gbt_macadle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:48
static bool gbt_macadeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:42
struct macaddr macaddr
static bool gbt_macadgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:31
#define NULL
Definition: c.h:229
static bool gbt_macadlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:54
static bool gbt_macadge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_macaddr.c:36

Definition at line 75 of file btree_macaddr.c.