Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
drwnBitArray Class Reference

Implements an efficient packed array of bits. More...

Public Member Functions

 drwnBitArray (int sz)
 creates an array with sz bits
 
 drwnBitArray (const drwnBitArray &m)
 copy constructor
 
bool empty () const
 returns true if the array is empty
 
int size () const
 returns the number of bits in the array
 
int count () const
 counts the number of bits in the array that are set
 
bool get (int i) const
 returns true if the i-th bit of the array is set
 
void set (int i)
 sets the i-th bit of the array to true
 
void clear (int i)
 sets the i-th bit of the array to false
 
void flip (int i)
 negates the i-th bit of the array
 
drwnBitArrayones ()
 sets all bits in the array
 
drwnBitArrayzeros ()
 clears all bits in the array
 
drwnBitArraynegate ()
 flips all bits in the array
 
drwnBitArraybitwiseand (const drwnBitArray &c)
 performs a bitwise and with an array of equal size
 
drwnBitArraybitwiseor (const drwnBitArray &c)
 performs a bitwise or with an array of equal size
 
drwnBitArraybitwisenand (const drwnBitArray &c)
 performs a bitwise nand with an array of equal size
 
drwnBitArraybitwisenor (const drwnBitArray &c)
 performs a bitwise nor with an array of equal size
 
drwnBitArraybitwisexor (const drwnBitArray &c)
 performs a bitwise xor with an array of equal size
 
drwnBitArrayoperator= (const drwnBitArray &c)
 assignment operator
 
bool operator== (const drwnBitArray &c) const
 equality operator (returns true if arrays are the same size and all bits are equal)
 
bool operator!= (const drwnBitArray &c) const
 not-equality operator (returns true if arrays are different sizes or some bits are not equal)
 
bool operator<= (const drwnBitArray &c) const
 less-than operator (returns true if this array preceeds c lexigraphically when printed)
 
bool operator[] (int i) const
 returns true if the i-th bit of the array is set (see drwnBitArray::get)
 
void print (ostream &os=cout, int stride=-1) const
 prints the array as a string of 1's and 0's
 

Protected Attributes

int _sz
 size of the array in bits
 
int _map_sz
 size of the array in words
 
int * _map
 storage for the array
 
int _mask
 mask for the last word in _map
 

Static Protected Attributes

static const int NUMSETLOOKUP [256]
 lookup table for counting the number of set bits
 

Detailed Description

Implements an efficient packed array of bits.

For example the following code creates two arrays of size eight and counts the number of bits set when one array is xor'd with the other.

drwnBitArray a(8), b(8);
a.ones(); b.zeros();
cout << a.bitwisexor(b).count();

The documentation for this class was generated from the following files: