w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Sparse.cpp
Go to the documentation of this file.
1 /* GRAPHITE2 LICENSING
2 
3  Copyright 2011, SIL International
4  All rights reserved.
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation; either version 2.1 of License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should also have received a copy of the GNU Lesser General Public
17  License along with this library in the file named "LICENSE".
18  If not, write to the Free Software Foundation, 51 Franklin Street,
19  Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20  internet at http://www.fsf.org/licenses/lgpl.html.
21 
22 Alternatively, the contents of this file may be used under the terms of the
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 License, as published by the Free Software Foundation, either version 2
25 of the License or (at your option) any later version.
26 */
27 #include <cassert>
28 #include "inc/Sparse.h"
29 #include "inc/bits.h"
30 
31 using namespace graphite2;
32 
33 const sparse::chunk sparse::empty_chunk = {0,0};
34 
35 sparse::~sparse() throw()
36 {
37  if (m_array.map == &empty_chunk) return;
38  free(m_array.values);
39 }
40 
41 
42 sparse::mapped_type sparse::operator [] (const key_type k) const throw()
43 {
44  mapped_type g = key_type(k/SIZEOF_CHUNK - m_nchunks) >> (sizeof k*8 - 1);
45  const chunk & c = m_array.map[g*k/SIZEOF_CHUNK];
46  const mask_t m = c.mask >> (SIZEOF_CHUNK - 1 - (k%SIZEOF_CHUNK));
47  g *= m & 1;
48 
49  return g*m_array.values[g*(c.offset + bit_set_count(m >> 1))];
50 }
51 
52 
53 size_t sparse::capacity() const throw()
54 {
55  size_t n = m_nchunks,
56  s = 0;
57 
58  for (const chunk *ci=m_array.map; n; --n, ++ci)
59  s += bit_set_count(ci->mask);
60 
61  return s;
62 }
union graphite2::sparse::@989 m_array
static const chunk empty_chunk
Definition: Sparse.h:59
key_type m_nchunks
Definition: Sparse.h:84
mapped_type operator[](const key_type k) const
Definition: Sparse.cpp:42
size_t capacity() const
Definition: Sparse.cpp:53
uint16 mapped_type
Definition: Sparse.h:45
#define n
Definition: t4ht.c:1290
#define free(a)
Definition: decNumber.cpp:310
#define s
Definition: afcover.h:80
#define c(n)
Definition: gpos-common.c:150
Definition: bits.h:30
unsigned int bit_set_count(T v)
Definition: bits.h:80
int k
Definition: otp-parser.c:70
int g
Definition: ppmqvga.c:68
m
Definition: tex4ht.c:3990