Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions | Variables

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_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)
Datum gbt_macad_compress (PG_FUNCTION_ARGS)
Datum gbt_macad_union (PG_FUNCTION_ARGS)
Datum gbt_macad_picksplit (PG_FUNCTION_ARGS)
Datum gbt_macad_consistent (PG_FUNCTION_ARGS)
Datum gbt_macad_penalty (PG_FUNCTION_ARGS)
Datum gbt_macad_same (PG_FUNCTION_ARGS)
static bool gbt_macadgt (const void *a, const void *b)
static bool gbt_macadge (const void *a, const void *b)
static bool gbt_macadeq (const void *a, const void *b)
static bool gbt_macadle (const void *a, const void *b)
static bool gbt_macadlt (const void *a, const void *b)
static int gbt_macadkey_cmp (const void *a, const void *b)
static uint64 mac_2_uint64 (macaddr *m)

Variables

static const gbtree_ninfo tinfo

Function Documentation

Datum gbt_macad_compress ( PG_FUNCTION_ARGS   ) 

Definition at line 115 of file btree_macaddr.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

{
    GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
    GISTENTRY  *retval = NULL;

    PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
}

Datum gbt_macad_consistent ( PG_FUNCTION_ARGS   ) 

Definition at line 125 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.

{
    GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
    macaddr    *query = (macaddr *) PG_GETARG_POINTER(1);
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);

    /* Oid      subtype = PG_GETARG_OID(3); */
    bool       *recheck = (bool *) PG_GETARG_POINTER(4);
    macKEY     *kkk = (macKEY *) DatumGetPointer(entry->key);
    GBT_NUMKEY_R key;

    /* All cases served by this function are exact */
    *recheck = false;

    key.lower = (GBT_NUMKEY *) &kkk->lower;
    key.upper = (GBT_NUMKEY *) &kkk->upper;

    PG_RETURN_BOOL(
                   gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
        );
}

Datum gbt_macad_penalty ( PG_FUNCTION_ARGS   ) 

Definition at line 160 of file btree_macaddr.c.

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

{
    macKEY     *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
    macKEY     *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
    float      *result = (float *) PG_GETARG_POINTER(2);
    uint64      iorg[2],
                inew[2];

    iorg[0] = mac_2_uint64(&origentry->lower);
    iorg[1] = mac_2_uint64(&origentry->upper);
    inew[0] = mac_2_uint64(&newentry->lower);
    inew[1] = mac_2_uint64(&newentry->upper);

    penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);

    PG_RETURN_POINTER(result);

}

Datum gbt_macad_picksplit ( PG_FUNCTION_ARGS   ) 
Datum gbt_macad_same ( PG_FUNCTION_ARGS   ) 

Definition at line 190 of file btree_macaddr.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

{
    macKEY     *b1 = (macKEY *) PG_GETARG_POINTER(0);
    macKEY     *b2 = (macKEY *) PG_GETARG_POINTER(1);
    bool       *result = (bool *) PG_GETARG_POINTER(2);

    *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
    PG_RETURN_POINTER(result);
}

Datum gbt_macad_union ( PG_FUNCTION_ARGS   ) 

Definition at line 149 of file btree_macaddr.c.

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

{
    GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
    void       *out = palloc(sizeof(macKEY));

    *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
    PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
}

static bool gbt_macadeq ( const void *  a,
const void *  b 
) [static]
static bool gbt_macadge ( const void *  a,
const void *  b 
) [static]
static bool gbt_macadgt ( const void *  a,
const void *  b 
) [static]
static int gbt_macadkey_cmp ( const void *  a,
const void *  b 
) [static]

Definition at line 66 of file btree_macaddr.c.

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

{
    macKEY     *ia = (macKEY *) (((const Nsrt *) a)->t);
    macKEY     *ib = (macKEY *) (((const Nsrt *) b)->t);
    int         res;

    res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
    if (res == 0)
        return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));

    return res;
}

static bool gbt_macadle ( const void *  a,
const void *  b 
) [static]
static bool gbt_macadlt ( const void *  a,
const void *  b 
) [static]
static uint64 mac_2_uint64 ( macaddr m  )  [static]

Definition at line 101 of file btree_macaddr.c.

References i.

Referenced by gbt_macad_penalty().

{
    unsigned char *mi = (unsigned char *) m;
    uint64      res = 0;
    int         i;

    for (i = 0; i < 6; i++)
        res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
    return res;
}

PG_FUNCTION_INFO_V1 ( gbt_macad_picksplit   ) 
PG_FUNCTION_INFO_V1 ( gbt_macad_compress   ) 
PG_FUNCTION_INFO_V1 ( gbt_macad_union   ) 
PG_FUNCTION_INFO_V1 ( gbt_macad_penalty   ) 
PG_FUNCTION_INFO_V1 ( gbt_macad_same   ) 
PG_FUNCTION_INFO_V1 ( gbt_macad_consistent   ) 

Variable Documentation

const gbtree_ninfo tinfo [static]
Initial value:

Definition at line 80 of file btree_macaddr.c.