CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Types | Static Private Member Functions | Private Attributes | Static Private Attributes
PhysicsTools::BitSet Class Reference

A compact container for storing single bits. More...

#include <BitSet.h>

Classes

class  Iterator
 Iterates over all set bits of a BitSet. More...
 
class  Manipulator
 Opaque structure for transparent write access to individual bits. More...
 

Public Types

typedef std::size_t size_t
 

Public Member Functions

size_t bits () const
 returns the number of set bits in the container More...
 
 BitSet ()
 
 BitSet (const BitSet &orig)
 
 BitSet (size_t bits)
 construct BitSet with a fixed size of bits bits More...
 
Iterator iter () const
 create iterator over all set bits More...
 
BitSetoperator= (const BitSet &orig)
 
Manipulator operator[] (size_t bit)
 provide read/write access to bit with index bit via reference More...
 
const Manipulator operator[] (size_t bit) const
 provide read access to bit with index bit via reference More...
 
size_t size () const
 returns the number of all bits in the container More...
 
 ~BitSet ()
 

Protected Types

typedef unsigned int Word_t
 

Static Private Member Functions

static size_t bitsToWords (std::size_t bits)
 

Private Attributes

size_t bits_
 
Word_tstore
 

Static Private Attributes

static const unsigned int wordSize = sizeof(Word_t) * 8
 

Detailed Description

A compact container for storing single bits.

BitSet provides a container of boolean values, similar to a std::vector<bool> which only consumes one actual bit for each value. Also an iterator is provided that can iterate over all set bits.

Definition at line 30 of file BitSet.h.

Member Typedef Documentation

typedef std::size_t PhysicsTools::BitSet::size_t

Definition at line 32 of file BitSet.h.

typedef unsigned int PhysicsTools::BitSet::Word_t
protected

Definition at line 35 of file BitSet.h.

Constructor & Destructor Documentation

PhysicsTools::BitSet::BitSet ( )
inline

Definition at line 127 of file BitSet.h.

127 : store(0), bits_(0) {}
Word_t * store
Definition: BitSet.h:189
PhysicsTools::BitSet::BitSet ( const BitSet orig)
inline

Definition at line 129 of file BitSet.h.

References bits_, bitsToWords(), and store.

129  : bits_(orig.bits_)
130  {
131  std::size_t words = bitsToWords(bits_);
132  if (words) {
133  store = new Word_t[words];
134  std::memcpy(store, orig.store, words * sizeof(Word_t));
135  } else
136  store = 0;
137  }
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:184
unsigned int Word_t
Definition: BitSet.h:35
Word_t * store
Definition: BitSet.h:189
PhysicsTools::BitSet::BitSet ( size_t  bits)
inline

construct BitSet with a fixed size of bits bits

Definition at line 140 of file BitSet.h.

References bitsToWords(), and store.

140  : bits_(bits)
141  {
142  std::size_t words = bitsToWords(bits);
143  if (words) {
144  store = new Word_t[words];
145  std::memset(store, 0, sizeof(Word_t) * words);
146  } else
147  store = 0;
148  }
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:184
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
unsigned int Word_t
Definition: BitSet.h:35
Word_t * store
Definition: BitSet.h:189
PhysicsTools::BitSet::~BitSet ( )
inline

Definition at line 150 of file BitSet.h.

References store.

150 { delete[] store; }
Word_t * store
Definition: BitSet.h:189

Member Function Documentation

BitSet::size_t PhysicsTools::BitSet::bits ( ) const

returns the number of set bits in the container

Definition at line 6 of file BitSet.cc.

References begin, bits_, bitsToWords(), end, AlCaHLTBitMon_ParallelJobs::p, and store.

7 {
8  static 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  unsigned char *begin = (unsigned char*)store;
29  unsigned char *end = (unsigned char*)(store + bitsToWords(bits_));
30 
31  size_t bits = 0;
32  for(unsigned char *p = begin; p < end; p++)
33  bits += byteBits[*p];
34 
35  return bits;
36 }
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:184
#define end
Definition: vmac.h:38
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
#define begin
Definition: vmac.h:31
Word_t * store
Definition: BitSet.h:189
static size_t PhysicsTools::BitSet::bitsToWords ( std::size_t  bits)
inlinestaticprivate

Definition at line 184 of file BitSet.h.

References wordSize.

Referenced by bits(), BitSet(), iter(), and operator=().

185  { return (bits + wordSize - 1) / wordSize; }
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
static const unsigned int wordSize
Definition: BitSet.h:187
Iterator PhysicsTools::BitSet::iter ( ) const
inline

create iterator over all set bits

Definition at line 180 of file BitSet.h.

References bits_, bitsToWords(), and store.

Referenced by PhysicsTools::VarProcessor::configure(), PhysicsTools::VarProcessor::deriv(), and PhysicsTools::VarProcessor::eval().

181  { return Iterator(store, store + bitsToWords(bits_)); }
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:184
Word_t * store
Definition: BitSet.h:189
BitSet& PhysicsTools::BitSet::operator= ( const BitSet orig)
inline

Definition at line 152 of file BitSet.h.

References bits_, bitsToWords(), and store.

153  {
154  delete[] store;
155  bits_ = orig.bits_;
156  std::size_t words = bitsToWords(bits_);
157  if (words) {
158  store = new Word_t[words];
159  std::memcpy(store, orig.store, words * sizeof(Word_t));
160  } else
161  store = 0;
162  return *this;
163  }
static size_t bitsToWords(std::size_t bits)
Definition: BitSet.h:184
unsigned int Word_t
Definition: BitSet.h:35
Word_t * store
Definition: BitSet.h:189
Manipulator PhysicsTools::BitSet::operator[] ( size_t  bit)
inline

provide read/write access to bit with index bit via reference

Definition at line 166 of file BitSet.h.

References store, and wordSize.

167  { return Manipulator(&store[bit / wordSize], bit % wordSize); }
Word_t * store
Definition: BitSet.h:189
static const unsigned int wordSize
Definition: BitSet.h:187
const Manipulator PhysicsTools::BitSet::operator[] ( size_t  bit) const
inline

provide read access to bit with index bit via reference

Definition at line 170 of file BitSet.h.

References store, and wordSize.

171  { return Manipulator(&store[bit / wordSize], bit % wordSize); }
Word_t * store
Definition: BitSet.h:189
static const unsigned int wordSize
Definition: BitSet.h:187
size_t PhysicsTools::BitSet::size ( void  ) const
inline

returns the number of all bits in the container

Definition at line 174 of file BitSet.h.

References bits_.

Referenced by PhysicsTools::VarProcessor::configure(), and PhysicsTools::Calibration::convert().

174 { return bits_; }

Member Data Documentation

size_t PhysicsTools::BitSet::bits_
private

Definition at line 190 of file BitSet.h.

Referenced by bits(), BitSet(), iter(), operator=(), and size().

Word_t* PhysicsTools::BitSet::store
private

Definition at line 189 of file BitSet.h.

Referenced by bits(), BitSet(), iter(), operator=(), operator[](), and ~BitSet().

const unsigned int PhysicsTools::BitSet::wordSize = sizeof(Word_t) * 8
staticprivate