LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_macaddr.c (source / functions) Coverage Total Hit UBC GNC CBC
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 72.2 % 79 57 22 57
Current Date: 2026-03-14 14:10:32 -0400 Functions: 87.5 % 24 21 3 1 20
Baseline: lcov-20260315-024220-baseline Branches: 20.0 % 10 2 8 2
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 10 10 10
(360..) days: 68.1 % 69 47 22 47
Function coverage date bins:
(30,360] days: 100.0 % 3 3 3
(360..) days: 85.7 % 21 18 3 1 17
Branch coverage date bins:
(360..) days: 20.0 % 10 2 8 2

 Age         Owner                    Branch data    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/fmgrprotos.h"
                                  9                 :                : #include "utils/inet.h"
                                 10                 :                : #include "utils/rel.h"
                                 11                 :                : #include "utils/sortsupport.h"
                                 12                 :                : 
                                 13                 :                : typedef struct
                                 14                 :                : {
                                 15                 :                :     macaddr     lower;
                                 16                 :                :     macaddr     upper;
                                 17                 :                :     char        pad[4];         /* make struct size = sizeof(gbtreekey16) */
                                 18                 :                : } macKEY;
                                 19                 :                : 
                                 20                 :                : /* GiST support functions */
 7961 teodor@sigaev.ru           21                 :CBC           4 : PG_FUNCTION_INFO_V1(gbt_macad_compress);
 4006 heikki.linnakangas@i       22                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_fetch);
 7961 teodor@sigaev.ru           23                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_union);
                                 24                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_picksplit);
                                 25                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_consistent);
                                 26                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_penalty);
                                 27                 :              4 : PG_FUNCTION_INFO_V1(gbt_macad_same);
  346 heikki.linnakangas@i       28                 :              4 : PG_FUNCTION_INFO_V1(gbt_macaddr_sortsupport);
                                 29                 :                : 
                                 30                 :                : 
                                 31                 :                : static bool
 3281 andrew@dunslane.net        32                 :           2093 : gbt_macadgt(const void *a, const void *b, FmgrInfo *flinfo)
                                 33                 :                : {
 7868 bruce@momjian.us           34                 :           2093 :     return DatumGetBool(DirectFunctionCall2(macaddr_gt, PointerGetDatum(a), PointerGetDatum(b)));
                                 35                 :                : }
                                 36                 :                : static bool
 3281 andrew@dunslane.net        37                 :            162 : gbt_macadge(const void *a, const void *b, FmgrInfo *flinfo)
                                 38                 :                : {
 7868 bruce@momjian.us           39                 :            162 :     return DatumGetBool(DirectFunctionCall2(macaddr_ge, PointerGetDatum(a), PointerGetDatum(b)));
                                 40                 :                : }
                                 41                 :                : 
                                 42                 :                : static bool
 3281 andrew@dunslane.net        43                 :            150 : gbt_macadeq(const void *a, const void *b, FmgrInfo *flinfo)
                                 44                 :                : {
 7868 bruce@momjian.us           45                 :            150 :     return DatumGetBool(DirectFunctionCall2(macaddr_eq, PointerGetDatum(a), PointerGetDatum(b)));
                                 46                 :                : }
                                 47                 :                : 
                                 48                 :                : static bool
 3281 andrew@dunslane.net        49                 :            613 : gbt_macadle(const void *a, const void *b, FmgrInfo *flinfo)
                                 50                 :                : {
 7868 bruce@momjian.us           51                 :            613 :     return DatumGetBool(DirectFunctionCall2(macaddr_le, PointerGetDatum(a), PointerGetDatum(b)));
                                 52                 :                : }
                                 53                 :                : 
                                 54                 :                : static bool
 3281 andrew@dunslane.net        55                 :           2393 : gbt_macadlt(const void *a, const void *b, FmgrInfo *flinfo)
                                 56                 :                : {
 7868 bruce@momjian.us           57                 :           2393 :     return DatumGetBool(DirectFunctionCall2(macaddr_lt, PointerGetDatum(a), PointerGetDatum(b)));
                                 58                 :                : }
                                 59                 :                : 
                                 60                 :                : 
                                 61                 :                : static int
 3281 andrew@dunslane.net        62                 :           1197 : gbt_macadkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 63                 :                : {
 5299 peter_e@gmx.net            64                 :           1197 :     macKEY     *ia = (macKEY *) (((const Nsrt *) a)->t);
                                 65                 :           1197 :     macKEY     *ib = (macKEY *) (((const Nsrt *) b)->t);
                                 66                 :                :     int         res;
                                 67                 :                : 
 5947 teodor@sigaev.ru           68                 :           1197 :     res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
                                 69         [ +  + ]:           1197 :     if (res == 0)
                                 70                 :            900 :         return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));
                                 71                 :                : 
                                 72                 :            297 :     return res;
                                 73                 :                : }
                                 74                 :                : 
                                 75                 :                : 
                                 76                 :                : static const gbtree_ninfo tinfo =
                                 77                 :                : {
                                 78                 :                :     gbt_t_macad,
                                 79                 :                :     sizeof(macaddr),
                                 80                 :                :     16,                         /* sizeof(gbtreekey16) */
                                 81                 :                :     gbt_macadgt,
                                 82                 :                :     gbt_macadge,
                                 83                 :                :     gbt_macadeq,
                                 84                 :                :     gbt_macadle,
                                 85                 :                :     gbt_macadlt,
                                 86                 :                :     gbt_macadkey_cmp,
                                 87                 :                :     NULL
                                 88                 :                : };
                                 89                 :                : 
                                 90                 :                : 
                                 91                 :                : /**************************************************
                                 92                 :                :  * GiST support functions
                                 93                 :                :  **************************************************/
                                 94                 :                : 
                                 95                 :                : static uint64
 7868 bruce@momjian.us           96                 :UBC           0 : mac_2_uint64(macaddr *m)
                                 97                 :                : {
                                 98                 :              0 :     unsigned char *mi = (unsigned char *) m;
                                 99                 :              0 :     uint64      res = 0;
                                100                 :                :     int         i;
                                101                 :                : 
                                102         [ #  # ]:              0 :     for (i = 0; i < 6; i++)
                                103                 :              0 :         res += (((uint64) mi[i]) << ((uint64) ((5 - i) * 8)));
                                104                 :              0 :     return res;
                                105                 :                : }
                                106                 :                : 
                                107                 :                : Datum
 7961 teodor@sigaev.ru          108                 :CBC         604 : gbt_macad_compress(PG_FUNCTION_ARGS)
                                109                 :                : {
 7868 bruce@momjian.us          110                 :            604 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                111                 :                : 
 4007 heikki.linnakangas@i      112                 :            604 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                113                 :                : }
                                114                 :                : 
                                115                 :                : Datum
 4006                           116                 :              8 : gbt_macad_fetch(PG_FUNCTION_ARGS)
                                117                 :                : {
                                118                 :              8 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                119                 :                : 
                                120                 :              8 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                121                 :                : }
                                122                 :                : 
                                123                 :                : Datum
 7961 teodor@sigaev.ru          124                 :           1824 : gbt_macad_consistent(PG_FUNCTION_ARGS)
                                125                 :                : {
 7868 bruce@momjian.us          126                 :           1824 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                127                 :           1824 :     macaddr    *query = (macaddr *) PG_GETARG_POINTER(1);
 6544 tgl@sss.pgh.pa.us         128                 :           1824 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                129                 :                : #ifdef NOT_USED
                                130                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                131                 :                : #endif
                                132                 :           1824 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 7868 bruce@momjian.us          133                 :           1824 :     macKEY     *kkk = (macKEY *) DatumGetPointer(entry->key);
                                134                 :                :     GBT_NUMKEY_R key;
                                135                 :                : 
                                136                 :                :     /* All cases served by this function are exact */
 6544 tgl@sss.pgh.pa.us         137                 :           1824 :     *recheck = false;
                                138                 :                : 
 6121 bruce@momjian.us          139                 :           1824 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                140                 :           1824 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                141                 :                : 
  472 peter@eisentraut.org      142                 :           1824 :     PG_RETURN_BOOL(gbt_num_consistent(&key, query, &strategy,
                                143                 :                :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                144                 :                : }
                                145                 :                : 
                                146                 :                : 
                                147                 :                : Datum
 7961 teodor@sigaev.ru          148                 :              1 : gbt_macad_union(PG_FUNCTION_ARGS)
                                149                 :                : {
 7868 bruce@momjian.us          150                 :              1 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 4321 tgl@sss.pgh.pa.us         151                 :              1 :     void       *out = palloc0(sizeof(macKEY));
                                152                 :                : 
 7868 bruce@momjian.us          153                 :              1 :     *(int *) PG_GETARG_POINTER(1) = sizeof(macKEY);
  472 peter@eisentraut.org      154                 :              1 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                155                 :                : }
                                156                 :                : 
                                157                 :                : 
                                158                 :                : Datum
 7961 teodor@sigaev.ru          159                 :UBC           0 : gbt_macad_penalty(PG_FUNCTION_ARGS)
                                160                 :                : {
 7868 bruce@momjian.us          161                 :              0 :     macKEY     *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                162                 :              0 :     macKEY     *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                163                 :              0 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                164                 :                :     uint64      iorg[2],
                                165                 :                :                 inew[2];
                                166                 :                : 
                                167                 :              0 :     iorg[0] = mac_2_uint64(&origentry->lower);
                                168                 :              0 :     iorg[1] = mac_2_uint64(&origentry->upper);
                                169                 :              0 :     inew[0] = mac_2_uint64(&newentry->lower);
                                170                 :              0 :     inew[1] = mac_2_uint64(&newentry->upper);
                                171                 :                : 
 7456                           172   [ #  #  #  #  :              0 :     penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
                                              #  # ]
                                173                 :                : 
 7868                           174                 :              0 :     PG_RETURN_POINTER(result);
                                175                 :                : }
                                176                 :                : 
                                177                 :                : Datum
 7961 teodor@sigaev.ru          178                 :CBC           3 : gbt_macad_picksplit(PG_FUNCTION_ARGS)
                                179                 :                : {
 2236 alvherre@alvh.no-ip.      180                 :              3 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                181                 :                :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                182                 :                :                                         &tinfo, fcinfo->flinfo));
                                183                 :                : }
                                184                 :                : 
                                185                 :                : Datum
 7961 teodor@sigaev.ru          186                 :UBC           0 : gbt_macad_same(PG_FUNCTION_ARGS)
                                187                 :                : {
 7868 bruce@momjian.us          188                 :              0 :     macKEY     *b1 = (macKEY *) PG_GETARG_POINTER(0);
                                189                 :              0 :     macKEY     *b2 = (macKEY *) PG_GETARG_POINTER(1);
                                190                 :              0 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                191                 :                : 
 3281 andrew@dunslane.net       192                 :              0 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 7868 bruce@momjian.us          193                 :              0 :     PG_RETURN_POINTER(result);
                                194                 :                : }
                                195                 :                : 
                                196                 :                : static int
  346 heikki.linnakangas@i      197                 :CBC        5789 : gbt_macaddr_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                198                 :                : {
                                199                 :           5789 :     macKEY     *arg1 = (macKEY *) DatumGetPointer(x);
                                200                 :           5789 :     macKEY     *arg2 = (macKEY *) DatumGetPointer(y);
                                201                 :                : 
                                202                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                203                 :           5789 :     return DatumGetInt32(DirectFunctionCall2(macaddr_cmp,
                                204                 :                :                                              MacaddrPGetDatum(&arg1->lower),
                                205                 :                :                                              MacaddrPGetDatum(&arg2->lower)));
                                206                 :                : }
                                207                 :                : 
                                208                 :                : Datum
                                209                 :              1 : gbt_macaddr_sortsupport(PG_FUNCTION_ARGS)
                                210                 :                : {
                                211                 :              1 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                212                 :                : 
                                213                 :              1 :     ssup->comparator = gbt_macaddr_ssup_cmp;
                                214                 :              1 :     ssup->ssup_extra = NULL;
                                215                 :                : 
                                216                 :              1 :     PG_RETURN_VOID();
                                217                 :                : }
        

Generated by: LCOV version 2.4-beta