LCOV - code coverage report
Current view: top level - src/support - rle.c (source / functions) Hit Total Coverage
Test: [build process] commit ef510b1f346f4c9f9d86eaceace5ca54961a1dbc Lines: 33 52 63.5 %
Date: 2022-07-17 01:01:28 Functions: 2 4 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 28 57.1 %

           Branch data     Line data    Source code
       1                 :            : // This file is a part of Julia. License is MIT: https://julialang.org/license
       2                 :            : 
       3                 :            : #include "rle.h"
       4                 :            : 
       5                 :            : #ifdef __cplusplus
       6                 :            : extern "C" {
       7                 :            : #endif
       8                 :            : 
       9                 :            : /* iteration */
      10                 :            : 
      11                 :          0 : rle_iter_state rle_iter_init(uint64_t key0)
      12                 :            : {
      13                 :          0 :     rle_iter_state state = {-1, 0, key0};
      14                 :          0 :     return state;
      15                 :            : }
      16                 :            : 
      17                 :          0 : int rle_iter_increment(rle_iter_state *state, size_t len, uint64_t *rletable, size_t npairs)
      18                 :            : {
      19                 :          0 :     state->i += 1;
      20                 :          0 :     size_t i = state->i, j = state->j;
      21         [ #  # ]:          0 :     if (i >= len)
      22                 :          0 :         return 0;
      23         [ #  # ]:          0 :     if (rletable) {
      24   [ #  #  #  # ]:          0 :         while (j < npairs && i >= rletable[j+1]) {
      25                 :          0 :             state->key = rletable[j];
      26                 :          0 :             j += 2;
      27                 :            :         }
      28                 :          0 :         state->j = j;
      29                 :            :     }
      30                 :          0 :     return 1;
      31                 :            : }
      32                 :            : 
      33                 :            : /* indexing */
      34                 :            : 
      35                 :      16292 : void rle_index_to_reference(rle_reference *rr, size_t i, uint64_t *rletable, size_t npairs, uint64_t key0)
      36                 :            : {
      37         [ -  + ]:      16292 :     if (!rletable) {
      38                 :          0 :         rr->key = key0;
      39                 :          0 :         rr->index = i;
      40                 :          0 :         return;
      41                 :            :     }
      42                 :            :     // Determine the active key
      43                 :      16292 :     uint64_t key = key0;
      44                 :      16292 :     size_t jj = 0;
      45   [ +  +  +  + ]:      25008 :     while (jj < npairs && i >= rletable[jj+1]) {
      46                 :       8716 :         key = rletable[jj];
      47                 :       8716 :         jj += 2;
      48                 :            :     }
      49                 :            :     // Subtract the number of preceding items with different keys
      50                 :      16292 :     uint64_t ckey = key0;
      51                 :      16292 :     size_t j, start = 0, index = i;
      52         [ +  + ]:      25008 :     for (j = 0; j < jj; j+=2) {
      53         [ +  + ]:       8716 :         if (key != ckey)
      54                 :       7940 :             index -= rletable[j+1] - start;
      55                 :       8716 :         ckey = rletable[j];
      56                 :       8716 :         start = rletable[j+1];
      57                 :            :     }
      58                 :            :     // Return the result
      59                 :      16292 :     rr->key = key;
      60                 :      16292 :     rr->index = index;
      61                 :      16292 :     return;
      62                 :            : }
      63                 :            : 
      64                 :      11368 : size_t rle_reference_to_index(rle_reference *rr, uint64_t *rletable, size_t npairs, uint64_t key0)
      65                 :            : {
      66                 :      11368 :     uint64_t key = rr->key;
      67                 :      11368 :     size_t index = rr->index, i = index;
      68         [ -  + ]:      11368 :     if (!rletable) {
      69         [ #  # ]:          0 :         assert(key == key0);
      70                 :          0 :         return i;
      71                 :            :     }
      72                 :      11368 :     uint64_t ckey = key0;
      73                 :      11368 :     size_t j, start = 0, n;
      74         [ +  + ]:      16432 :     for (j = 0; j < npairs; j+=2) {
      75                 :      12008 :         n = rletable[j+1] - start;
      76         [ +  + ]:      12008 :         if (key != ckey)
      77                 :       4424 :             i += n;
      78                 :            :         else {
      79         [ +  + ]:       7584 :             if (index < n)
      80                 :       6944 :                 break;
      81                 :        640 :             index -= n;
      82                 :            :         }
      83                 :       5064 :         ckey = rletable[j];
      84                 :       5064 :         start = rletable[j+1];
      85                 :            :     }
      86                 :      11368 :     return i;
      87                 :            : }
      88                 :            : 
      89                 :            : 
      90                 :            : #ifdef __cplusplus
      91                 :            : }
      92                 :            : #endif

Generated by: LCOV version 1.14