LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_macaddr.c (source / functions) Coverage Total Hit CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 100.0 % 69 69 69
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 21 21 21
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 100.0 % 69 69 69
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 21 21 21

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * contrib/btree_gist/btree_macaddr.c
                                  3                 :  */
                                  4                 : #include "postgres.h"
                                  5                 : 
                                  6                 : #include "btree_gist.h"
                                  7                 : #include "btree_utils_num.h"
                                  8                 : #include "utils/builtins.h"
                                  9                 : #include "utils/inet.h"
                                 10                 : 
                                 11                 : typedef struct
                                 12                 : {
                                 13                 :     macaddr     lower;
                                 14                 :     macaddr     upper;
                                 15                 :     char        pad[4];         /* make struct size = sizeof(gbtreekey16) */
                                 16                 : } macKEY;
                                 17                 : 
                                 18                 : /*
                                 19                 : ** OID ops
                                 20                 : */
 6890 teodor                     21 CBC           2 : PG_FUNCTION_INFO_V1(gbt_macad_compress);
 2935 heikki.linnakangas         22               2 : PG_FUNCTION_INFO_V1(gbt_macad_fetch);
 6890 teodor                     23               2 : PG_FUNCTION_INFO_V1(gbt_macad_union);
                                 24               2 : PG_FUNCTION_INFO_V1(gbt_macad_picksplit);
                                 25               2 : PG_FUNCTION_INFO_V1(gbt_macad_consistent);
                                 26               2 : PG_FUNCTION_INFO_V1(gbt_macad_penalty);
                                 27               2 : PG_FUNCTION_INFO_V1(gbt_macad_same);
                                 28                 : 
                                 29                 : 
                                 30                 : static bool
 2210 andrew                     31            1681 : gbt_macadgt(const void *a, const void *b, FmgrInfo *flinfo)
                                 32                 : {
 6797 bruce                      33            1681 :     return DatumGetBool(DirectFunctionCall2(macaddr_gt, PointerGetDatum(a), PointerGetDatum(b)));
                                 34                 : }
                                 35                 : static bool
 2210 andrew                     36             163 : gbt_macadge(const void *a, const void *b, FmgrInfo *flinfo)
                                 37                 : {
 6797 bruce                      38             163 :     return DatumGetBool(DirectFunctionCall2(macaddr_ge, PointerGetDatum(a), PointerGetDatum(b)));
                                 39                 : }
                                 40                 : 
                                 41                 : static bool
 2210 andrew                     42             853 : gbt_macadeq(const void *a, const void *b, FmgrInfo *flinfo)
                                 43                 : {
 6797 bruce                      44             853 :     return DatumGetBool(DirectFunctionCall2(macaddr_eq, PointerGetDatum(a), PointerGetDatum(b)));
                                 45                 : }
                                 46                 : 
                                 47                 : static bool
 2210 andrew                     48             613 : gbt_macadle(const void *a, const void *b, FmgrInfo *flinfo)
                                 49                 : {
 6797 bruce                      50             613 :     return DatumGetBool(DirectFunctionCall2(macaddr_le, PointerGetDatum(a), PointerGetDatum(b)));
                                 51                 : }
                                 52                 : 
                                 53                 : static bool
 2210 andrew                     54            1979 : gbt_macadlt(const void *a, const void *b, FmgrInfo *flinfo)
                                 55                 : {
 6797 bruce                      56            1979 :     return DatumGetBool(DirectFunctionCall2(macaddr_lt, PointerGetDatum(a), PointerGetDatum(b)));
                                 57                 : }
                                 58                 : 
                                 59                 : 
                                 60                 : static int
 2210 andrew                     61            5865 : gbt_macadkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 62                 : {
 4228 peter_e                    63            5865 :     macKEY     *ia = (macKEY *) (((const Nsrt *) a)->t);
                                 64            5865 :     macKEY     *ib = (macKEY *) (((const Nsrt *) b)->t);
                                 65                 :     int         res;
                                 66                 : 
 4876 teodor                     67            5865 :     res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
                                 68            5865 :     if (res == 0)
                                 69             731 :         return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));
                                 70                 : 
                                 71            5134 :     return res;
                                 72                 : }
                                 73                 : 
                                 74                 : 
                                 75                 : static const gbtree_ninfo tinfo =
                                 76                 : {
                                 77                 :     gbt_t_macad,
                                 78                 :     sizeof(macaddr),
                                 79                 :     16,                         /* sizeof(gbtreekey16) */
                                 80                 :     gbt_macadgt,
                                 81                 :     gbt_macadge,
                                 82                 :     gbt_macadeq,
                                 83                 :     gbt_macadle,
                                 84                 :     gbt_macadlt,
                                 85                 :     gbt_macadkey_cmp,
                                 86                 :     NULL
                                 87                 : };
                                 88                 : 
                                 89                 : 
                                 90                 : /**************************************************
                                 91                 :  * macaddr ops
                                 92                 :  **************************************************/
                                 93                 : 
                                 94                 : 
                                 95                 : 
                                 96                 : static uint64
 6797 bruce                      97            2880 : mac_2_uint64(macaddr *m)
                                 98                 : {
                                 99            2880 :     unsigned char *mi = (unsigned char *) m;
                                100            2880 :     uint64      res = 0;
                                101                 :     int         i;
                                102                 : 
                                103           20160 :     for (i = 0; i < 6; i++)
                                104           17280 :         res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
                                105            2880 :     return res;
                                106                 : }
                                107                 : 
                                108                 : 
                                109                 : 
                                110                 : Datum
 6890 teodor                    111             607 : gbt_macad_compress(PG_FUNCTION_ARGS)
                                112                 : {
 6797 bruce                     113             607 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                114                 : 
 2936 heikki.linnakangas        115             607 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                116                 : }
                                117                 : 
                                118                 : Datum
 2935                           119               8 : gbt_macad_fetch(PG_FUNCTION_ARGS)
                                120                 : {
                                121               8 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                122                 : 
                                123               8 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                124                 : }
                                125                 : 
                                126                 : Datum
 6890 teodor                    127            1828 : gbt_macad_consistent(PG_FUNCTION_ARGS)
                                128                 : {
 6797 bruce                     129            1828 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                130            1828 :     macaddr    *query = (macaddr *) PG_GETARG_POINTER(1);
 5473 tgl                       131            1828 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                132                 : 
                                133                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                134            1828 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 6797 bruce                     135            1828 :     macKEY     *kkk = (macKEY *) DatumGetPointer(entry->key);
                                136                 :     GBT_NUMKEY_R key;
                                137                 : 
                                138                 :     /* All cases served by this function are exact */
 5473 tgl                       139            1828 :     *recheck = false;
                                140                 : 
 5050 bruce                     141            1828 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                142            1828 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                143                 : 
 1165 alvherre                  144            1828 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) query, &strategy,
                                145                 :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                146                 : }
                                147                 : 
                                148                 : 
                                149                 : Datum
 6890 teodor                    150             352 : gbt_macad_union(PG_FUNCTION_ARGS)
                                151                 : {
 6797 bruce                     152             352 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 3250 tgl                       153             352 :     void       *out = palloc0(sizeof(macKEY));
                                154                 : 
 6797 bruce                     155             352 :     *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
 2210 andrew                    156             352 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
                                157                 : }
                                158                 : 
                                159                 : 
                                160                 : Datum
 6890 teodor                    161             720 : gbt_macad_penalty(PG_FUNCTION_ARGS)
                                162                 : {
 6797 bruce                     163             720 :     macKEY     *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                164             720 :     macKEY     *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                165             720 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                166                 :     uint64      iorg[2],
                                167                 :                 inew[2];
                                168                 : 
                                169             720 :     iorg[0] = mac_2_uint64(&origentry->lower);
                                170             720 :     iorg[1] = mac_2_uint64(&origentry->upper);
                                171             720 :     inew[0] = mac_2_uint64(&newentry->lower);
                                172             720 :     inew[1] = mac_2_uint64(&newentry->upper);
                                173                 : 
 6385                           174             720 :     penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
                                175                 : 
 6797                           176             720 :     PG_RETURN_POINTER(result);
                                177                 : }
                                178                 : 
                                179                 : Datum
 6890 teodor                    180               3 : gbt_macad_picksplit(PG_FUNCTION_ARGS)
                                181                 : {
 1165 alvherre                  182               3 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                183                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                184                 :                                         &tinfo, fcinfo->flinfo));
                                185                 : }
                                186                 : 
                                187                 : Datum
 6890 teodor                    188             351 : gbt_macad_same(PG_FUNCTION_ARGS)
                                189                 : {
 6797 bruce                     190             351 :     macKEY     *b1 = (macKEY *) PG_GETARG_POINTER(0);
                                191             351 :     macKEY     *b2 = (macKEY *) PG_GETARG_POINTER(1);
                                192             351 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                193                 : 
 2210 andrew                    194             351 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 6797 bruce                     195             351 :     PG_RETURN_POINTER(result);
                                196                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a