CMS 3D CMS Logo

BitSet.cc
Go to the documentation of this file.
3 
4 namespace PhysicsTools {
5 
7  static constexpr unsigned char byteBits[256] = {
8  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2,
9  3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
10  3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
11  6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4,
12  3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4,
13  5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6,
14  6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
15  const unsigned char *begin = reinterpret_cast<const unsigned char *>(store);
16  const unsigned char *end = reinterpret_cast<const unsigned char *>(store + bitsToWords(bits_));
17 
18  size_t bits = 0;
19  for (const unsigned char *p = begin; p < end; p++)
20  bits += byteBits[*p];
21 
22  return bits;
23  }
24 
26  PhysicsTools::BitSet::size_t size = bitSet.store.size();
27  size = (size - 1) * 8 + (bitSet.bitsInLast + 7) % 8 + 1;
28 
30  for (PhysicsTools::BitSet::size_t i = 0; i < size; i++)
31  result[i] = bitSet.store[i / 8] & (1 << (i % 8));
32 
33  return result;
34  }
35 
38  PhysicsTools::BitSet::size_t bytes = (size + 7) / 8;
39 
41  result.store.resize(bytes);
42  result.bitsInLast = (size + 7) % 8 + 1;
43 
44  for (PhysicsTools::BitSet::size_t i = 0; i < size; i++)
45  result.store[i / 8] |= bitSet[i] ? (1 << (i % 8)) : 0;
46 
47  return result;
48  }
49 
50 } // namespace PhysicsTools
std::vector< unsigned char > store
Definition: MVAComputer.h:38
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:182
A compact container for storing single bits.
Definition: BitSet.h:29
#define end
Definition: vmac.h:39
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:32
PhysicsTools::BitSet convert(const BitSet &bitSet)
constructs BitSet container from persistent representation
Definition: BitSet.cc:25
Word_t * store
Definition: BitSet.h:186
#define constexpr