Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/workdir/UnpackedTarball/graphite/src/Sparse.cpp
Line
Count
Source
1
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later
2
// Copyright 2011, SIL International, All rights reserved.
3
4
#include <cassert>
5
#include "inc/Sparse.h"
6
#include "inc/bits.h"
7
8
using namespace graphite2;
9
10
const sparse::chunk sparse::empty_chunk = {0,0};
11
12
sparse::~sparse() throw()
13
0
{
14
0
    if (m_array.map == &empty_chunk) return;
15
0
    free(m_array.values);
16
0
}
17
18
19
sparse::mapped_type sparse::operator [] (const key_type k) const throw()
20
0
{
21
0
    mapped_type         g = key_type(k/SIZEOF_CHUNK - m_nchunks) >> (sizeof k*8 - 1);
22
0
    const chunk &       c = m_array.map[g*k/SIZEOF_CHUNK];
23
0
    const mask_t        m = c.mask >> (SIZEOF_CHUNK - 1 - (k%SIZEOF_CHUNK));
24
0
    g *= m & 1;
25
26
0
    return g*m_array.values[g*(c.offset + bit_set_count(m >> 1))];
27
0
}
28
29
30
size_t sparse::capacity() const throw()
31
0
{
32
0
    size_t n = m_nchunks,
33
0
           s = 0;
34
35
0
    for (const chunk *ci=m_array.map; n; --n, ++ci)
36
0
        s += bit_set_count(ci->mask);
37
38
0
    return s;
39
0
}