PostgreSQL Source Code  git master
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

◆ gbt_macad_compress()

Datum gbt_macad_compress ( PG_FUNCTION_ARGS  )

Definition at line 111 of file btree_macaddr.c.

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

References gbt_num_compress(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_macad_consistent()

Datum gbt_macad_consistent ( PG_FUNCTION_ARGS  )

Definition at line 127 of file btree_macaddr.c.

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);
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 
144  PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) query, &strategy,
145  GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
146 }
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:170
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:160
macaddr upper
Definition: btree_macaddr.c:14
macaddr lower
Definition: btree_macaddr.c:13
Definition: inet.h:95

References DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, macKEY::lower, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, tinfo, and macKEY::upper.

◆ gbt_macad_fetch()

Datum gbt_macad_fetch ( PG_FUNCTION_ARGS  )

Definition at line 119 of file btree_macaddr.c.

120 {
121  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
122 
124 }
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

References gbt_num_fetch(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_macad_penalty()

Datum gbt_macad_penalty ( PG_FUNCTION_ARGS  )

Definition at line 161 of file btree_macaddr.c.

162 {
163  macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
164  macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
165  float *result = (float *) PG_GETARG_POINTER(2);
166  uint64 iorg[2],
167  inew[2];
168 
169  iorg[0] = mac_2_uint64(&origentry->lower);
170  iorg[1] = mac_2_uint64(&origentry->upper);
171  inew[0] = mac_2_uint64(&newentry->lower);
172  inew[1] = mac_2_uint64(&newentry->upper);
173 
174  penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
175 
176  PG_RETURN_POINTER(result);
177 }
static uint64 mac_2_uint64(macaddr *m)
Definition: btree_macaddr.c:97
#define penalty_num(result, olower, oupper, nlower, nupper)

References DatumGetPointer(), sort-test::key, macKEY::lower, mac_2_uint64(), penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and macKEY::upper.

◆ gbt_macad_picksplit()

Datum gbt_macad_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 180 of file btree_macaddr.c.

181 {
184  &tinfo, fcinfo->flinfo));
185 }
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

References gbt_num_picksplit(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_macad_same()

Datum gbt_macad_same ( PG_FUNCTION_ARGS  )

Definition at line 188 of file btree_macaddr.c.

189 {
190  macKEY *b1 = (macKEY *) PG_GETARG_POINTER(0);
191  macKEY *b2 = (macKEY *) PG_GETARG_POINTER(1);
192  bool *result = (bool *) PG_GETARG_POINTER(2);
193 
194  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
195  PG_RETURN_POINTER(result);
196 }
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_macad_union()

Datum gbt_macad_union ( PG_FUNCTION_ARGS  )

Definition at line 150 of file btree_macaddr.c.

151 {
153  void *out = palloc0(sizeof(macKEY));
154 
155  *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
156  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
157 }
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * palloc0(Size size)
Definition: mcxt.c:1346

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

◆ gbt_macadeq()

static bool gbt_macadeq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 42 of file btree_macaddr.c.

43 {
45 }
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:644
int b
Definition: isn.c:70
int a
Definition: isn.c:69
Datum macaddr_eq(PG_FUNCTION_ARGS)
Definition: mac.c:228
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322

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

◆ gbt_macadge()

static bool gbt_macadge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 36 of file btree_macaddr.c.

37 {
39 }
Datum macaddr_ge(PG_FUNCTION_ARGS)
Definition: mac.c:237

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

◆ gbt_macadgt()

static bool gbt_macadgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 31 of file btree_macaddr.c.

32 {
34 }
Datum macaddr_gt(PG_FUNCTION_ARGS)
Definition: mac.c:246

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

◆ gbt_macadkey_cmp()

static int gbt_macadkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 61 of file btree_macaddr.c.

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 }
Datum macaddr_cmp(PG_FUNCTION_ARGS)
Definition: mac.c:197
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
static Datum MacaddrPGetDatum(const macaddr *X)
Definition: inet.h:153

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

◆ gbt_macadle()

static bool gbt_macadle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 48 of file btree_macaddr.c.

49 {
51 }
Datum macaddr_le(PG_FUNCTION_ARGS)
Definition: mac.c:219

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

◆ gbt_macadlt()

static bool gbt_macadlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 54 of file btree_macaddr.c.

55 {
57 }
Datum macaddr_lt(PG_FUNCTION_ARGS)
Definition: mac.c:210

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

◆ mac_2_uint64()

static uint64 mac_2_uint64 ( macaddr m)
static

Definition at line 97 of file btree_macaddr.c.

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
Definition: isn.c:73

References i, and res.

Referenced by gbt_macad_penalty().

◆ PG_FUNCTION_INFO_V1() [1/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_compress  )

◆ PG_FUNCTION_INFO_V1() [2/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_fetch  )

◆ PG_FUNCTION_INFO_V1() [4/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_penalty  )

◆ PG_FUNCTION_INFO_V1() [5/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_picksplit  )

◆ PG_FUNCTION_INFO_V1() [6/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_same  )

◆ PG_FUNCTION_INFO_V1() [7/7]

PG_FUNCTION_INFO_V1 ( gbt_macad_union  )

Variable Documentation

◆ tinfo

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

Definition at line 75 of file btree_macaddr.c.

Referenced by gbt_macad_compress(), gbt_macad_consistent(), gbt_macad_fetch(), gbt_macad_picksplit(), gbt_macad_same(), and gbt_macad_union().