LCOV - code coverage report
Current view: top level - src/support - bitvector.c (source / functions) Hit Total Coverage
Test: [build process] commit ef510b1f346f4c9f9d86eaceace5ca54961a1dbc Lines: 17 19 89.5 %
Date: 2022-07-17 01:01:28 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : // This file is a part of Julia. License is MIT: https://julialang.org/license
       2                 :            : 
       3                 :            : /*
       4                 :            :   bit vector primitives
       5                 :            : */
       6                 :            : 
       7                 :            : #include <stdlib.h>
       8                 :            : #include <assert.h>
       9                 :            : #include <string.h>
      10                 :            : 
      11                 :            : #include "dtypes.h"
      12                 :            : #include "bitvector.h"
      13                 :            : 
      14                 :            : #ifdef _OS_WINDOWS_
      15                 :            : #include <malloc.h>
      16                 :            : #endif
      17                 :            : 
      18                 :            : #ifdef __cplusplus
      19                 :            : extern "C" {
      20                 :            : #endif
      21                 :            : 
      22                 :         30 : uint32_t *bitvector_resize(uint32_t *b, uint64_t oldsz, uint64_t newsz,
      23                 :            :                             int initzero)
      24                 :            : {
      25                 :            :     uint32_t *p;
      26                 :         30 :     size_t sz = ((newsz+31)>>5) * sizeof(uint32_t);
      27                 :         30 :     p = (uint32_t*)LLT_REALLOC(b, sz);
      28         [ -  + ]:         30 :     if (p == NULL) return NULL;
      29   [ +  -  +  - ]:         30 :     if (initzero && newsz>oldsz) {
      30                 :         30 :         size_t osz = ((oldsz+31)>>5) * sizeof(uint32_t);
      31                 :         30 :         memset(&p[osz/sizeof(uint32_t)], 0, sz-osz);
      32                 :            :     }
      33                 :         30 :     return p;
      34                 :            : }
      35                 :            : 
      36                 :         30 : uint32_t *bitvector_new(uint64_t n, int initzero)
      37                 :            : {
      38                 :         30 :     return bitvector_resize(NULL, 0, n, initzero);
      39                 :            : }
      40                 :            : 
      41                 :          0 : size_t bitvector_nwords(uint64_t nbits)
      42                 :            : {
      43                 :          0 :     return ((nbits+31)>>5);
      44                 :            : }
      45                 :            : 
      46                 :    4488640 : void bitvector_set(uint32_t *b, uint64_t n, uint32_t c)
      47                 :            : {
      48         [ +  + ]:    4488640 :     if (c)
      49                 :    2237800 :         b[n>>5] |= (1<<(n&31));
      50                 :            :     else
      51                 :    2250860 :         b[n>>5] &= ~(1<<(n&31));
      52                 :    4488640 : }
      53                 :            : 
      54                 :    2250680 : uint32_t bitvector_get(uint32_t *b, uint64_t n)
      55                 :            : {
      56                 :    2250680 :     return b[n>>5] & (1<<(n&31));
      57                 :            : }
      58                 :            : 
      59                 :            : #ifdef __cplusplus
      60                 :            : }
      61                 :            : #endif

Generated by: LCOV version 1.14