libcommonc++
0.7
|
A compact representation of an array of bits (boolean values). More...
#include <BitSet.h++>
Classes | |
class | Bit |
A "reference" to a bit within a BitSet. More... | |
Public Member Functions | |
BitSet (uint_t size) | |
Construct a new BitSet of the given size. More... | |
BitSet (const BitSet &other) | |
Copy constructor. More... | |
BitSet (const String &bits) | |
Construct a BitSet from a String. More... | |
virtual | ~BitSet () |
Destructor. More... | |
BitSet & | set (uint_t pos, bool value=true) |
Set (or clear) a bit at the given position. More... | |
BitSet & | setRange (uint_t startPos, uint_t endPos, bool value=true) |
Set (or clear) the bits in the given (inclusive) range. More... | |
BitSet & | setAll (bool value=true) |
Set (or clear) all of the bits in the BitSet. More... | |
BitSet & | clear (uint_t pos) |
Clear the bit at the given position. More... | |
BitSet & | clearRange (uint_t startPos, uint_t endPos) |
Clear the bits in the given (inclusive) range. More... | |
BitSet & | clearAll () |
Clear all of the bits in the BitSet. More... | |
bool | isSet (int pos) const |
Test if a bit at the given position is set. More... | |
bool | get (uint_t pos) const |
Get the value of the bit at the given position. More... | |
bool | isClear (uint_t pos) const |
Test if a bit at the given position is clear. More... | |
bool | isAnySet () const |
Test if at least one bit is set in the BitSet. More... | |
bool | isAllSet () const |
Test if all of the bits are set in the BitSet. More... | |
bool | isAllClear () const |
Test if all of the bits are clear in the BitSet. More... | |
int | nextSetBit (uint_t startPos) const |
Find the index of the next bit that is set, beginning at the given position. More... | |
int | firstSetBit () const |
Find the index of the first bit that is set. More... | |
int | nextClearBit (uint_t startPos) const |
Find the index of the next bit that is clear, beginning at the given position. More... | |
int | firstClearBit () const |
Find the index of the first bit that is clear. More... | |
bool | operator! () const |
Test if all of the bits in the BitSet are cleared. More... | |
BitSet & | flip () |
Flip (toggle) all of the bits in the BitSet. More... | |
BitSet & | flip (uint_t pos) |
Flip (toggle) the bit at the given position. More... | |
void | swap (BitSet &other) |
Swap the bits of this BitSet with those of another. More... | |
Bit | operator[] (int pos) |
Obtain a "reference" to a bit at the given position. More... | |
bool | operator[] (int pos) const |
Get the value of a bit at the given position. More... | |
uint_t | getSize () const |
Get the size of the BitSet, in bits. More... | |
uint_t | getWordCount () const |
Get the number of words in the BitSet. More... | |
uint32_t | getWord (uint_t index) const |
Get the word at the specified index in the BitSet. More... | |
uint32_t | getWordDiff (uint_t index, uint32_t other) const |
"Diff" the word at the specificed index in the BitSet against another word. More... | |
void | setWord (uint_t index, uint32_t word) |
Set the word at the specified index in the BitSet. More... | |
String | toString () const |
Get a String representation of the BitSet. More... | |
void | write (std::ostream &stream) const |
Write a string representation of the BitSet to a stream. More... | |
bool | operator== (const BitSet &other) const |
Equality operator. More... | |
bool | operator!= (const BitSet &other) const |
Inequality operator. More... | |
BitSet & | operator= (const BitSet &other) |
Assignment operator. More... | |
BitSet & | operator|= (const BitSet &other) |
Bitwise OR assignment operator. More... | |
BitSet & | operator &= (const BitSet &other) |
Bitwise AND assignment operator. More... | |
BitSet & | operator^= (const BitSet &other) |
Bitwise XOR assignment operator. More... | |
BitSet & | operator>>= (uint_t n) |
Bitwise right-shift assignment operator. More... | |
BitSet & | operator<<= (uint_t n) |
Bitwise left-shift assignment operator. More... | |
BitSet | operator>> (uint_t n) const |
Bitwise right-shift operator. More... | |
BitSet | operator<< (uint_t n) const |
Bitwise left-shift operator. More... | |
BitSet | operator~ () const |
Bitwise NOT operator. More... | |
A compact representation of an array of bits (boolean values).
The bits are stored internally in an array of words, each word being a 32-bit unsigned integer that represents 32 boolean values. Complete words can be fetched if the caller needs efficient access to multiple bits at a time.
|
virtual |
Destructor.
Clear the bits in the given (inclusive) range.
startPos | The start position of the range. |
endPos | The end position of the range. |
|
inline |
Find the index of the first bit that is clear.
|
inline |
Find the index of the first bit that is set.
Flip (toggle) the bit at the given position.
OutOfBoundsException | If the position is invalid. |
|
inline |
Get the value of the bit at the given position.
|
inline |
Get the word at the specified index in the BitSet.
index | The index. If the index is out of range, a value of 0 is returned. |
|
inline |
Get the number of words in the BitSet.
(Each word is a 32-bit integer.)
|
inline |
"Diff" the word at the specificed index in the BitSet against another word.
Essentially, this function simply returns a bitwise XOR of the two words.
index | The index. If the index is out of range, a value of 0 is returned. |
other | The other word to "diff" against. |
|
inline |
Test if all of the bits are clear in the BitSet.
bool isAllSet | ( | ) | const |
Test if all of the bits are set in the BitSet.
bool isAnySet | ( | ) | const |
Test if at least one bit is set in the BitSet.
|
inline |
Test if a bit at the given position is clear.
bool isSet | ( | int | pos | ) | const |
Test if a bit at the given position is set.
|
inline |
Find the index of the next bit that is clear, beginning at the given position.
startPos | The starting bit position to search from. |
|
inline |
Find the index of the next bit that is set, beginning at the given position.
startPos | The starting bit position to search from. |
Bitwise AND assignment operator.
OutOfBoundsException | If the two BitSets are not of equal size. |
|
inline |
Test if all of the bits in the BitSet are cleared.
Equivalent to isAllClear().
Bitwise left-shift assignment operator.
n | The number of bit positions by which to shift the BitSet. |
bool operator== | ( | const BitSet & | other | ) | const |
Equality operator.
Bitwise right-shift assignment operator.
n | The number of bit positions by which to shift the BitSet. |
BitSet::Bit operator[] | ( | int | pos | ) |
Obtain a "reference" to a bit at the given position.
pos | The position. |
OutOfBoundsException | If the position is invalid. |
|
inline |
Get the value of a bit at the given position.
pos | The position. |
OutOfBoundsException | If the position is invalid. |
Bitwise XOR assignment operator.
OutOfBoundsException | If the two BitSets are not of equal size. |
Bitwise OR assignment operator.
OutOfBoundsException | If the two BitSets are not of equal size. |
|
inline |
Bitwise NOT operator.
Set (or clear) a bit at the given position.
pos | The position of the bit. |
value | The value to set the bit to. |
BitSet & setAll | ( | bool | value = true | ) |
Set (or clear) all of the bits in the BitSet.
value | The value to set all of the bits to. |
Set (or clear) the bits in the given (inclusive) range.
startPos | The start position of the range. |
endPos | The end position of the range. |
value | The value to set the bits to. |
void setWord | ( | uint_t | index, |
uint32_t | word | ||
) |
Set the word at the specified index in the BitSet.
index | The index. If the index is out of range, the method has no effect. |
word | The word. |
void swap | ( | BitSet & | other | ) |
Swap the bits of this BitSet with those of another.
OutOfBoundsException | If both BitSets are not of equal size. |
void write | ( | std::ostream & | stream | ) | const |
Write a string representation of the BitSet to a stream.