CMS 3D CMS Logo

BitSet.cc
Go to the documentation of this file.
3 
4 namespace PhysicsTools {
5 
7 {
8  static constexpr unsigned char byteBits[256] = {
9  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3,
10  4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,
11  4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3,
12  4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5,
13  4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,
14  4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4,
15  4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3,
16  4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
17  4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3,
18  4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4,
19  4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3,
20  4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5,
21  4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3,
22  4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4,
23  4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3,
24  4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
25  4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7,
26  8
27  };
28  const unsigned char *begin = reinterpret_cast<const unsigned char*>(store);
29  const unsigned char *end = reinterpret_cast<const unsigned char*>(store + bitsToWords(bits_));
30 
31  size_t bits = 0;
32  for(const unsigned char *p = begin; p < end; p++)
33  bits += byteBits[*p];
34 
35  return bits;
36 }
37 
39 {
40  PhysicsTools::BitSet::size_t size = bitSet.store.size();
41  size = (size - 1) * 8 + (bitSet.bitsInLast + 7) % 8 + 1;
42 
44  for(PhysicsTools::BitSet::size_t i = 0; i < size; i++)
45  result[i] = bitSet.store[i / 8] & (1 << (i % 8));
46 
47  return result;
48 }
49 
51 {
53  PhysicsTools::BitSet::size_t bytes = (size + 7) / 8;
54 
56  result.store.resize(bytes);
57  result.bitsInLast = (size + 7) % 8 + 1;
58 
59  for(PhysicsTools::BitSet::size_t i = 0; i < size; i++)
60  result.store[i / 8] |= bitSet[i] ? (1 << (i % 8)) : 0;
61 
62  return result;
63 }
64 
65 } // namespace PhysicsTools
int i
Definition: DBlmapReader.cc:9
std::vector< unsigned char > store
Definition: MVAComputer.h:35
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:183
#define constexpr
A compact container for storing single bits.
Definition: BitSet.h:29
#define end
Definition: vmac.h:37
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
size_t size() const
returns the number of all bits in the container
Definition: BitSet.h:173
std::size_t size_t
Definition: BitSet.h:31
#define begin
Definition: vmac.h:30
PhysicsTools::BitSet convert(const BitSet &bitSet)
constructs BitSet container from persistent representation
Definition: BitSet.cc:38
Word_t * store
Definition: BitSet.h:188