LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_float8.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 94.0 % 83 78 5 2 76 2
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 25 25 2 23
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (180,240] days: 100.0 % 2 2 2
Legend: Lines: hit not hit (240..) days: 93.8 % 81 76 5 76
Function coverage date bins:
(240..) days: 100.0 % 25 25 2 23

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * contrib/btree_gist/btree_float8.c
                                  3                 :  */
                                  4                 : #include "postgres.h"
                                  5                 : 
                                  6                 : #include "btree_gist.h"
                                  7                 : #include "btree_utils_num.h"
                                  8                 : #include "utils/float.h"
                                  9                 : 
                                 10                 : typedef struct float8key
                                 11                 : {
                                 12                 :     float8      lower;
                                 13                 :     float8      upper;
                                 14                 : } float8KEY;
                                 15                 : 
                                 16                 : /*
                                 17                 : ** float8 ops
                                 18                 : */
 6890 teodor                     19 CBC           2 : PG_FUNCTION_INFO_V1(gbt_float8_compress);
 2935 heikki.linnakangas         20               2 : PG_FUNCTION_INFO_V1(gbt_float8_fetch);
 6890 teodor                     21               2 : PG_FUNCTION_INFO_V1(gbt_float8_union);
                                 22               2 : PG_FUNCTION_INFO_V1(gbt_float8_picksplit);
                                 23               2 : PG_FUNCTION_INFO_V1(gbt_float8_consistent);
 4421 tgl                        24               2 : PG_FUNCTION_INFO_V1(gbt_float8_distance);
 6890 teodor                     25               2 : PG_FUNCTION_INFO_V1(gbt_float8_penalty);
                                 26               2 : PG_FUNCTION_INFO_V1(gbt_float8_same);
                                 27                 : 
                                 28                 : 
                                 29                 : static bool
 2210 andrew                     30            1597 : gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
                                 31                 : {
 4228 peter_e                    32            1597 :     return (*((const float8 *) a) > *((const float8 *) b));
                                 33                 : }
                                 34                 : static bool
 2210 andrew                     35             382 : gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
                                 36                 : {
 4228 peter_e                    37             382 :     return (*((const float8 *) a) >= *((const float8 *) b));
                                 38                 : }
                                 39                 : static bool
 2210 andrew                     40             734 : gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
                                 41                 : {
 4228 peter_e                    42             734 :     return (*((const float8 *) a) == *((const float8 *) b));
                                 43                 : }
                                 44                 : static bool
 2210 andrew                     45             558 : gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
                                 46                 : {
 4228 peter_e                    47             558 :     return (*((const float8 *) a) <= *((const float8 *) b));
                                 48                 : }
                                 49                 : static bool
 2210 andrew                     50            1728 : gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
                                 51                 : {
 4228 peter_e                    52            1728 :     return (*((const float8 *) a) < *((const float8 *) b));
                                 53                 : }
                                 54                 : 
                                 55                 : static int
 2210 andrew                     56            6805 : gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 57                 : {
 4228 peter_e                    58            6805 :     float8KEY  *ia = (float8KEY *) (((const Nsrt *) a)->t);
                                 59            6805 :     float8KEY  *ib = (float8KEY *) (((const Nsrt *) b)->t);
                                 60                 : 
 4876 teodor                     61            6805 :     if (ia->lower == ib->lower)
                                 62                 :     {
 4876 teodor                     63 UBC           0 :         if (ia->upper == ib->upper)
                                 64               0 :             return 0;
                                 65                 : 
                                 66               0 :         return (ia->upper > ib->upper) ? 1 : -1;
                                 67                 :     }
                                 68                 : 
 4876 teodor                     69 CBC        6805 :     return (ia->lower > ib->lower) ? 1 : -1;
                                 70                 : }
                                 71                 : 
                                 72                 : static float8
 2210 andrew                     73             138 : gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 74                 : {
 4382 bruce                      75             138 :     float8      arg1 = *(const float8 *) a;
                                 76             138 :     float8      arg2 = *(const float8 *) b;
                                 77                 :     float8      r;
                                 78                 : 
 4421 tgl                        79             138 :     r = arg1 - arg2;
  598 michael                    80             138 :     if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
  598 michael                    81 UBC           0 :         float_overflow_error();
  184 peter                      82 GNC         138 :     return fabs(r);
                                 83                 : }
                                 84                 : 
                                 85                 : 
                                 86                 : static const gbtree_ninfo tinfo =
                                 87                 : {
                                 88                 :     gbt_t_float8,
                                 89                 :     sizeof(float8),
                                 90                 :     16,                         /* sizeof(gbtreekey16) */
                                 91                 :     gbt_float8gt,
                                 92                 :     gbt_float8ge,
                                 93                 :     gbt_float8eq,
                                 94                 :     gbt_float8le,
                                 95                 :     gbt_float8lt,
                                 96                 :     gbt_float8key_cmp,
                                 97                 :     gbt_float8_dist
                                 98                 : };
                                 99                 : 
                                100                 : 
 4421 tgl                       101 CBC           2 : PG_FUNCTION_INFO_V1(float8_dist);
                                102                 : Datum
                                103             547 : float8_dist(PG_FUNCTION_ARGS)
                                104                 : {
                                105             547 :     float8      a = PG_GETARG_FLOAT8(0);
                                106             547 :     float8      b = PG_GETARG_FLOAT8(1);
                                107                 :     float8      r;
                                108                 : 
                                109             547 :     r = a - b;
  598 michael                   110             547 :     if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
  598 michael                   111 UBC           0 :         float_overflow_error();
                                112                 : 
  184 peter                     113 GNC         547 :     PG_RETURN_FLOAT8(fabs(r));
                                114                 : }
                                115                 : 
                                116                 : /**************************************************
                                117                 :  * float8 ops
                                118                 :  **************************************************/
                                119                 : 
                                120                 : 
                                121                 : Datum
 6890 teodor                    122 CBC         552 : gbt_float8_compress(PG_FUNCTION_ARGS)
                                123                 : {
 6797 bruce                     124             552 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                125                 : 
 2936 heikki.linnakangas        126             552 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                127                 : }
                                128                 : 
                                129                 : Datum
 2935                           130             135 : gbt_float8_fetch(PG_FUNCTION_ARGS)
                                131                 : {
                                132             135 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                133                 : 
                                134             135 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                135                 : }
                                136                 : 
                                137                 : Datum
 6890 teodor                    138            1513 : gbt_float8_consistent(PG_FUNCTION_ARGS)
                                139                 : {
 6797 bruce                     140            1513 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                141            1513 :     float8      query = PG_GETARG_FLOAT8(1);
 5473 tgl                       142            1513 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                143                 : 
                                144                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                145            1513 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 6797 bruce                     146            1513 :     float8KEY  *kkk = (float8KEY *) DatumGetPointer(entry->key);
                                147                 :     GBT_NUMKEY_R key;
                                148                 : 
                                149                 :     /* All cases served by this function are exact */
 5473 tgl                       150            1513 :     *recheck = false;
                                151                 : 
 5050 bruce                     152            1513 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                153            1513 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                154                 : 
 1165 alvherre                  155            1513 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
                                156                 :                                       GIST_LEAF(entry), &tinfo,
                                157                 :                                       fcinfo->flinfo));
                                158                 : }
                                159                 : 
                                160                 : 
                                161                 : Datum
 4421 tgl                       162             139 : gbt_float8_distance(PG_FUNCTION_ARGS)
                                163                 : {
                                164             139 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                165             139 :     float8      query = PG_GETARG_FLOAT8(1);
                                166                 : 
                                167                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                168             139 :     float8KEY  *kkk = (float8KEY *) DatumGetPointer(entry->key);
                                169                 :     GBT_NUMKEY_R key;
                                170                 : 
                                171             139 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                172             139 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                173                 : 
 1165 alvherre                  174             139 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
                                175                 :                                       &tinfo, fcinfo->flinfo));
                                176                 : }
                                177                 : 
                                178                 : 
                                179                 : Datum
 6890 teodor                    180             301 : gbt_float8_union(PG_FUNCTION_ARGS)
                                181                 : {
 6797 bruce                     182             301 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                183             301 :     void       *out = palloc(sizeof(float8KEY));
                                184                 : 
                                185             301 :     *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
 2210 andrew                    186             301 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
                                187                 : }
                                188                 : 
                                189                 : 
                                190                 : Datum
 6890 teodor                    191             541 : gbt_float8_penalty(PG_FUNCTION_ARGS)
                                192                 : {
 6797 bruce                     193             541 :     float8KEY  *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                194             541 :     float8KEY  *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                195             541 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                196                 : 
 6385                           197             541 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                198                 : 
 6797                           199             541 :     PG_RETURN_POINTER(result);
                                200                 : }
                                201                 : 
                                202                 : Datum
 6890 teodor                    203               3 : gbt_float8_picksplit(PG_FUNCTION_ARGS)
                                204                 : {
 1165 alvherre                  205               3 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                206                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                207                 :                                         &tinfo, fcinfo->flinfo));
                                208                 : }
                                209                 : 
                                210                 : Datum
 6890 teodor                    211             300 : gbt_float8_same(PG_FUNCTION_ARGS)
                                212                 : {
 6797 bruce                     213             300 :     float8KEY  *b1 = (float8KEY *) PG_GETARG_POINTER(0);
                                214             300 :     float8KEY  *b2 = (float8KEY *) PG_GETARG_POINTER(1);
                                215             300 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                216                 : 
 2210 andrew                    217             300 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 6797 bruce                     218             300 :     PG_RETURN_POINTER(result);
                                219                 : }
        

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