LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_float4.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 94.9 % 78 74 4 1 73 1
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 25 25 1 24
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (180,240] days: 100.0 % 1 1 1
Legend: Lines: hit not hit (240..) days: 94.8 % 77 73 4 73
Function coverage date bins:
(240..) days: 100.0 % 25 25 1 24

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * contrib/btree_gist/btree_float4.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 float4key
                                 11                 : {
                                 12                 :     float4      lower;
                                 13                 :     float4      upper;
                                 14                 : } float4KEY;
                                 15                 : 
                                 16                 : /*
                                 17                 : ** float4 ops
                                 18                 : */
 6890 teodor                     19 CBC           2 : PG_FUNCTION_INFO_V1(gbt_float4_compress);
 2935 heikki.linnakangas         20               2 : PG_FUNCTION_INFO_V1(gbt_float4_fetch);
 6890 teodor                     21               2 : PG_FUNCTION_INFO_V1(gbt_float4_union);
                                 22               2 : PG_FUNCTION_INFO_V1(gbt_float4_picksplit);
                                 23               2 : PG_FUNCTION_INFO_V1(gbt_float4_consistent);
 4421 tgl                        24               2 : PG_FUNCTION_INFO_V1(gbt_float4_distance);
 6890 teodor                     25               2 : PG_FUNCTION_INFO_V1(gbt_float4_penalty);
                                 26               2 : PG_FUNCTION_INFO_V1(gbt_float4_same);
                                 27                 : 
                                 28                 : static bool
 2210 andrew                     29            1176 : gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
                                 30                 : {
 4228 peter_e                    31            1176 :     return (*((const float4 *) a) > *((const float4 *) b));
                                 32                 : }
                                 33                 : static bool
 2210 andrew                     34             514 : gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
                                 35                 : {
 4228 peter_e                    36             514 :     return (*((const float4 *) a) >= *((const float4 *) b));
                                 37                 : }
                                 38                 : static bool
 2210 andrew                     39             688 : gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
                                 40                 : {
 4228 peter_e                    41             688 :     return (*((const float4 *) a) == *((const float4 *) b));
                                 42                 : }
                                 43                 : static bool
 2210 andrew                     44             821 : gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
                                 45                 : {
 4228 peter_e                    46             821 :     return (*((const float4 *) a) <= *((const float4 *) b));
                                 47                 : }
                                 48                 : static bool
 2210 andrew                     49            1458 : gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
                                 50                 : {
 4228 peter_e                    51            1458 :     return (*((const float4 *) a) < *((const float4 *) b));
                                 52                 : }
                                 53                 : 
                                 54                 : static int
 2210 andrew                     55            3247 : gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 56                 : {
 4228 peter_e                    57            3247 :     float4KEY  *ia = (float4KEY *) (((const Nsrt *) a)->t);
                                 58            3247 :     float4KEY  *ib = (float4KEY *) (((const Nsrt *) b)->t);
                                 59                 : 
 4876 teodor                     60            3247 :     if (ia->lower == ib->lower)
                                 61                 :     {
 4876 teodor                     62 UBC           0 :         if (ia->upper == ib->upper)
                                 63               0 :             return 0;
                                 64                 : 
                                 65               0 :         return (ia->upper > ib->upper) ? 1 : -1;
                                 66                 :     }
                                 67                 : 
 4876 teodor                     68 CBC        3247 :     return (ia->lower > ib->lower) ? 1 : -1;
                                 69                 : }
                                 70                 : 
                                 71                 : static float8
 2210 andrew                     72             266 : gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                 73                 : {
 4421 tgl                        74             266 :     return GET_FLOAT_DISTANCE(float4, a, b);
                                 75                 : }
                                 76                 : 
                                 77                 : 
                                 78                 : static const gbtree_ninfo tinfo =
                                 79                 : {
                                 80                 :     gbt_t_float4,
                                 81                 :     sizeof(float4),
                                 82                 :     8,                          /* sizeof(gbtreekey8) */
                                 83                 :     gbt_float4gt,
                                 84                 :     gbt_float4ge,
                                 85                 :     gbt_float4eq,
                                 86                 :     gbt_float4le,
                                 87                 :     gbt_float4lt,
                                 88                 :     gbt_float4key_cmp,
                                 89                 :     gbt_float4_dist
                                 90                 : };
                                 91                 : 
                                 92                 : 
                                 93               2 : PG_FUNCTION_INFO_V1(float4_dist);
                                 94                 : Datum
                                 95             550 : float4_dist(PG_FUNCTION_ARGS)
                                 96                 : {
 4382 bruce                      97             550 :     float4      a = PG_GETARG_FLOAT4(0);
 4421 tgl                        98             550 :     float4      b = PG_GETARG_FLOAT4(1);
                                 99                 :     float4      r;
                                100                 : 
                                101             550 :     r = a - b;
  598 michael                   102             550 :     if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
  598 michael                   103 UBC           0 :         float_overflow_error();
                                104                 : 
  183 peter                     105 GNC         550 :     PG_RETURN_FLOAT4(fabsf(r));
                                106                 : }
                                107                 : 
                                108                 : 
                                109                 : /**************************************************
                                110                 :  * float4 ops
                                111                 :  **************************************************/
                                112                 : 
                                113                 : 
                                114                 : Datum
 6890 teodor                    115 CBC         551 : gbt_float4_compress(PG_FUNCTION_ARGS)
                                116                 : {
 6797 bruce                     117             551 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                118                 : 
 2936 heikki.linnakangas        119             551 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                120                 : }
                                121                 : 
                                122                 : Datum
 2935                           123             265 : gbt_float4_fetch(PG_FUNCTION_ARGS)
                                124                 : {
                                125             265 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                126                 : 
                                127             265 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                128                 : }
                                129                 : 
                                130                 : Datum
 6890 teodor                    131            1899 : gbt_float4_consistent(PG_FUNCTION_ARGS)
                                132                 : {
 6797 bruce                     133            1899 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                134            1899 :     float4      query = PG_GETARG_FLOAT4(1);
 5473 tgl                       135            1899 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                136                 : 
                                137                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                138            1899 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 6797 bruce                     139            1899 :     float4KEY  *kkk = (float4KEY *) DatumGetPointer(entry->key);
                                140                 :     GBT_NUMKEY_R key;
                                141                 : 
                                142                 :     /* All cases served by this function are exact */
 5473 tgl                       143            1899 :     *recheck = false;
                                144                 : 
 5050 bruce                     145            1899 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                146            1899 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                147                 : 
 1165 alvherre                  148            1899 :     PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query, &strategy,
                                149                 :                                       GIST_LEAF(entry), &tinfo,
                                150                 :                                       fcinfo->flinfo));
                                151                 : }
                                152                 : 
                                153                 : 
                                154                 : Datum
 4421 tgl                       155             267 : gbt_float4_distance(PG_FUNCTION_ARGS)
                                156                 : {
                                157             267 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                158             267 :     float4      query = PG_GETARG_FLOAT4(1);
                                159                 : 
                                160                 :     /* Oid      subtype = PG_GETARG_OID(3); */
                                161             267 :     float4KEY  *kkk = (float4KEY *) DatumGetPointer(entry->key);
                                162                 :     GBT_NUMKEY_R key;
                                163                 : 
                                164             267 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                165             267 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                166                 : 
 1165 alvherre                  167             267 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry),
                                168                 :                                       &tinfo, fcinfo->flinfo));
                                169                 : }
                                170                 : 
                                171                 : 
                                172                 : Datum
 6890 teodor                    173             213 : gbt_float4_union(PG_FUNCTION_ARGS)
                                174                 : {
 6797 bruce                     175             213 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
                                176             213 :     void       *out = palloc(sizeof(float4KEY));
                                177                 : 
                                178             213 :     *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
 2210 andrew                    179             213 :     PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
                                180                 : }
                                181                 : 
                                182                 : 
                                183                 : Datum
 6890 teodor                    184             352 : gbt_float4_penalty(PG_FUNCTION_ARGS)
                                185                 : {
 6797 bruce                     186             352 :     float4KEY  *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                187             352 :     float4KEY  *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                188             352 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                189                 : 
 6385                           190             352 :     penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
                                191                 : 
 6797                           192             352 :     PG_RETURN_POINTER(result);
                                193                 : }
                                194                 : 
                                195                 : Datum
 6890 teodor                    196               1 : gbt_float4_picksplit(PG_FUNCTION_ARGS)
                                197                 : {
 1165 alvherre                  198               1 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                199                 :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                200                 :                                         &tinfo, fcinfo->flinfo));
                                201                 : }
                                202                 : 
                                203                 : Datum
 6890 teodor                    204             212 : gbt_float4_same(PG_FUNCTION_ARGS)
                                205                 : {
 6797 bruce                     206             212 :     float4KEY  *b1 = (float4KEY *) PG_GETARG_POINTER(0);
                                207             212 :     float4KEY  *b2 = (float4KEY *) PG_GETARG_POINTER(1);
                                208             212 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                209                 : 
 2210 andrew                    210             212 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 6797 bruce                     211             212 :     PG_RETURN_POINTER(result);
                                212                 : }
        

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