Darwin
1.10(beta)
|
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 | |
drwnBitArray & | ones () |
sets all bits in the array | |
drwnBitArray & | zeros () |
clears all bits in the array | |
drwnBitArray & | negate () |
flips all bits in the array | |
drwnBitArray & | bitwiseand (const drwnBitArray &c) |
performs a bitwise and with an array of equal size | |
drwnBitArray & | bitwiseor (const drwnBitArray &c) |
performs a bitwise or with an array of equal size | |
drwnBitArray & | bitwisenand (const drwnBitArray &c) |
performs a bitwise nand with an array of equal size | |
drwnBitArray & | bitwisenor (const drwnBitArray &c) |
performs a bitwise nor with an array of equal size | |
drwnBitArray & | bitwisexor (const drwnBitArray &c) |
performs a bitwise xor with an array of equal size | |
drwnBitArray & | operator= (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 | |
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.