LCOV - differential code coverage report
Current view: top level - src/include/lib - qunique.h (source / functions) Coverage Total Hit CBC
Current: a2387c32f2f8a1643c7d71b951587e6bcb2d4744 vs 371a302eecdc82274b0ae2967d18fd726a0aa6a1 Lines: 100.0 % 16 16 16
Current Date: 2025-10-26 12:31:50 -0700 Functions: 100.0 % 2 2 2
Baseline: lcov-20251027-010456-baseline Branches: 100.0 % 16 16 16
Baseline Date: 2025-10-26 11:01:32 +1300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 100.0 % 16 16 16
Function coverage date bins:
(360..) days: 100.0 % 2 2 2
Branch coverage date bins:
(360..) days: 100.0 % 16 16 16

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * qunique.h
                                  4                 :                :  *      inline array unique functions
                                  5                 :                :  * Portions Copyright (c) 2019-2025, 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
 2181 tmunro@postgresql.or       21                 :CBC      151904 : qunique(void *array, size_t elements, size_t width,
                                 22                 :                :         int (*compare) (const void *, const void *))
                                 23                 :                : {
                                 24                 :         151904 :     char       *bytes = (char *) array;
                                 25                 :                :     size_t      i,
                                 26                 :                :                 j;
                                 27                 :                : 
                                 28         [ +  + ]:         151904 :     if (elements <= 1)
                                 29                 :           1294 :         return elements;
                                 30                 :                : 
                                 31         [ +  + ]:        5115422 :     for (i = 1, j = 0; i < elements; ++i)
                                 32                 :                :     {
 2123 noah@leadboat.com          33   [ +  +  +  + ]:        4964812 :         if (compare(bytes + i * width, bytes + j * width) != 0 &&
                                 34                 :                :             ++j != i)
                                 35                 :        2623212 :             memcpy(bytes + j * width, bytes + i * width, width);
                                 36                 :                :     }
                                 37                 :                : 
 2181 tmunro@postgresql.or       38                 :         150610 :     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                 :        2589528 : qunique_arg(void *array, size_t elements, size_t width,
                                 47                 :                :             int (*compare) (const void *, const void *, void *),
                                 48                 :                :             void *arg)
                                 49                 :                : {
                                 50                 :        2589528 :     char       *bytes = (char *) array;
                                 51                 :                :     size_t      i,
                                 52                 :                :                 j;
                                 53                 :                : 
                                 54         [ +  + ]:        2589528 :     if (elements <= 1)
                                 55                 :            234 :         return elements;
                                 56                 :                : 
                                 57         [ +  + ]:      107911519 :     for (i = 1, j = 0; i < elements; ++i)
                                 58                 :                :     {
 2123 noah@leadboat.com          59   [ +  +  +  + ]:      105322225 :         if (compare(bytes + i * width, bytes + j * width, arg) != 0 &&
                                 60                 :                :             ++j != i)
                                 61                 :       15303275 :             memcpy(bytes + j * width, bytes + i * width, width);
                                 62                 :                :     }
                                 63                 :                : 
 2181 tmunro@postgresql.or       64                 :        2589294 :     return j + 1;
                                 65                 :                : }
                                 66                 :                : 
                                 67                 :                : #endif                          /* QUNIQUE_H */
        

Generated by: LCOV version 2.4-beta