CMS 3D CMS Logo

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>

List of all members.

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

: store(0), bits_(0) {}
PhysicsTools::BitSet::BitSet ( const BitSet orig) [inline]

Definition at line 129 of file BitSet.h.

References bits_, bitsToWords(), and store.

                                   : bits_(orig.bits_)
        {
                std::size_t words = bitsToWords(bits_);
                if (words) {
                        store = new Word_t[words];
                        std::memcpy(store, orig.store, words * sizeof(Word_t));
                } else
                        store = 0;
        }
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.

                            : bits_(bits)
        {
                std::size_t words = bitsToWords(bits);
                if (words) {
                        store = new Word_t[words];
                        std::memset(store, 0, sizeof(Word_t) * words);
                } else
                        store = 0;
        }
PhysicsTools::BitSet::~BitSet ( ) [inline]

Definition at line 150 of file BitSet.h.

References store.

{ delete[] store; }

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.

{
        static unsigned char byteBits[256] = {
                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,  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,  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,  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,  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,  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,  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
        };
        unsigned char *begin = (unsigned char*)store;
        unsigned char *end   = (unsigned char*)(store + bitsToWords(bits_));

        size_t bits = 0;
        for(unsigned char *p = begin; p < end; p++)
                bits += byteBits[*p];

        return bits;
}
static size_t PhysicsTools::BitSet::bitsToWords ( std::size_t  bits) [inline, static, private]

Definition at line 184 of file BitSet.h.

References wordSize.

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

        { return (bits + wordSize - 1) / wordSize; }
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().

        { return Iterator(store, store + bitsToWords(bits_)); }
BitSet& PhysicsTools::BitSet::operator= ( const BitSet orig) [inline]

Definition at line 152 of file BitSet.h.

References bits_, bitsToWords(), and store.

        {
                delete[] store;
                bits_ = orig.bits_;
                std::size_t words = bitsToWords(bits_);
                if (words) {
                        store = new Word_t[words];
                        std::memcpy(store, orig.store, words * sizeof(Word_t));
                } else
                        store = 0;
                return *this;
        }
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.

        { return Manipulator(&store[bit / wordSize], bit % wordSize); }
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.

        { return Manipulator(&store[bit / wordSize], bit % wordSize); }
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().

{ return bits_; }

Member Data Documentation

Definition at line 190 of file BitSet.h.

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

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 [static, private]