LCOV - differential code coverage report
Current view: top level - src/include/lib - qunique.h (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 93.8 % 16 15 1 15
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 2 2 2
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 93.8 % 16 15 1 15
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 2 2 2

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * qunique.h
                                  4                 :  *      inline array unique functions
                                  5                 :  * Portions Copyright (c) 2019-2023, PostgreSQL Global Development Group
                                  6                 :  *
                                  7                 :  * IDENTIFICATION
                                  8                 :  *      src/include/lib/qunique.h
                                  9                 :  *-------------------------------------------------------------------------
                                 10                 :  */
                                 11                 : 
                                 12                 : #ifndef QUNIQUE_H
                                 13                 : #define QUNIQUE_H
                                 14                 : 
                                 15                 : /*
                                 16                 :  * Remove duplicates from a pre-sorted array, according to a user-supplied
                                 17                 :  * comparator.  Usually the array should have been sorted with qsort() using
                                 18                 :  * the same arguments.  Return the new size.
                                 19                 :  */
                                 20                 : static inline size_t
 1249 tmunro                     21 CBC      180787 : qunique(void *array, size_t elements, size_t width,
                                 22                 :         int (*compare) (const void *, const void *))
                                 23                 : {
                                 24          180787 :     char       *bytes = (char *) array;
                                 25                 :     size_t      i,
                                 26                 :                 j;
                                 27                 : 
                                 28          180787 :     if (elements <= 1)
                                 29            5095 :         return elements;
                                 30                 : 
                                 31         4210521 :     for (i = 1, j = 0; i < elements; ++i)
                                 32                 :     {
 1191 noah                       33         4034829 :         if (compare(bytes + i * width, bytes + j * width) != 0 &&
                                 34                 :             ++j != i)
                                 35         1974596 :             memcpy(bytes + j * width, bytes + i * width, width);
                                 36                 :     }
                                 37                 : 
 1249 tmunro                     38          175692 :     return j + 1;
                                 39                 : }
                                 40                 : 
                                 41                 : /*
                                 42                 :  * Like qunique(), but takes a comparator with an extra user data argument
                                 43                 :  * which is passed through, for compatibility with qsort_arg().
                                 44                 :  */
                                 45                 : static inline size_t
                                 46         1628755 : qunique_arg(void *array, size_t elements, size_t width,
                                 47                 :             int (*compare) (const void *, const void *, void *),
                                 48                 :             void *arg)
                                 49                 : {
                                 50         1628755 :     char       *bytes = (char *) array;
                                 51                 :     size_t      i,
                                 52                 :                 j;
                                 53                 : 
                                 54         1628755 :     if (elements <= 1)
 1249 tmunro                     55 UBC           0 :         return elements;
                                 56                 : 
 1249 tmunro                     57 CBC    29828406 :     for (i = 1, j = 0; i < elements; ++i)
                                 58                 :     {
 1191 noah                       59        28199651 :         if (compare(bytes + i * width, bytes + j * width, arg) != 0 &&
                                 60                 :             ++j != i)
                                 61         1845107 :             memcpy(bytes + j * width, bytes + i * width, width);
                                 62                 :     }
                                 63                 : 
 1249 tmunro                     64         1628755 :     return j + 1;
                                 65                 : }
                                 66                 : 
                                 67                 : #endif                          /* QUNIQUE_H */
        

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