BitSet Class Reference

A compact representation of an array of bits (boolean values). More...

#include <BitSet.h++>

Inheritance diagram for BitSet:

Inheritance graph
[legend]

List of all members.

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.
 BitSet (const BitSet &other)
 Copy constructor.
 BitSet (const String &bits)
 Construct a BitSet from a String.
virtual ~BitSet () throw ()
 Destructor.
BitSetset (uint_t pos, bool value=true) throw ()
 Set (or clear) a bit at the given position.
BitSetsetRange (uint_t startPos, uint_t endPos, bool value=true) throw ()
 Set (or clear) the bits in the given (inclusive) range.
BitSetsetAll (bool value=true) throw ()
 Set (or clear) all of the bits in the BitSet.
BitSetclear (uint_t pos) throw ()
 Clear the bit at the given position.
BitSetclearRange (uint_t startPos, uint_t endPos) throw ()
 Clear the bits in the given (inclusive) range.
BitSetclearAll () throw ()
 Clear all of the bits in the BitSet.
bool isSet (uint_t pos) const throw ()
 Test if a bit at the given position is set.
bool get (uint_t pos) const throw ()
 Get the value of the bit at the given position.
bool isClear (uint_t pos) const throw ()
 Test if a bit at the given position is clear.
bool isAnySet () const throw ()
 Test if at least one bit is set in the BitSet.
bool isAllSet () const throw ()
 Test if all of the bits are set in the BitSet.
bool isAllClear () const throw ()
 Test if all of the bits are clear in the BitSet.
int nextSetBit (uint_t startPos) const throw ()
 Find the index of the next bit that is set, beginning at the given position.
int firstSetBit () const throw ()
 Find the index of the first bit that is set.
int nextClearBit (uint_t startPos) const throw ()
 Find the index of the next bit that is clear, beginning at the given position.
int firstClearBit () const throw ()
 Find the index of the first bit that is clear.
bool operator! () const throw ()
 Test if all of the bits in the BitSet are cleared.
BitSetflip () throw ()
 Flip (toggle) all of the bits in the BitSet.
BitSetflip (uint_t pos) throw (OutOfBoundsException)
 Flip (toggle) the bit at the given position.
void swap (BitSet &other) throw (OutOfBoundsException)
 Swap the bits of this BitSet with those of another.
Bit operator[] (uint_t pos) throw (OutOfBoundsException)
 Obtain a "reference" to a bit at the given position.
bool operator[] (uint_t pos) const throw ()
 Get the value of a bit at the given position.
uint_t getSize () const throw ()
 Get the size of the BitSet, in bits.
size_t getWordCount () const throw ()
 Get the number of words in the BitSet.
uint32_t getWord (uint_t index) const throw ()
 Get the word at the specified index in the BitSet.
uint32_t getWordDiff (uint_t index, uint32_t other) const throw ()
 "Diff" the word at the specificed index in the BitSet against another word.
void setWord (uint_t index, uint32_t word) throw ()
 Set the word at the specified index in the BitSet.
String toString () const
 Get a String representation of the BitSet.
void write (std::ostream &stream) const
 Write a string representation of the BitSet to a stream.
bool operator== (const BitSet &other) const throw ()
 Equality operator.
bool operator!= (const BitSet &other) const throw ()
 Inequality operator.
BitSetoperator= (const BitSet &other)
 Assignment operator.
BitSetoperator|= (const BitSet &other) throw (OutOfBoundsException)
 Bitwise OR assignment operator.
BitSetoperator&= (const BitSet &other) throw (OutOfBoundsException)
 Bitwise AND assignment operator.
BitSetoperator^= (const BitSet &other) throw (OutOfBoundsException)
 Bitwise XOR assignment operator.
BitSetoperator>>= (size_t n) throw ()
 Bitwise right-shift assignment operator.
BitSetoperator<<= (size_t n) throw ()
 Bitwise left-shift assignment operator.
BitSet operator>> (size_t n) const
 Bitwise right-shift operator.
BitSet operator<< (size_t n) const
 Bitwise left-shift operator.
BitSet operator~ () const throw ()
 Bitwise NOT operator.


Detailed Description

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.

Author:
Mark Lindner

Constructor & Destructor Documentation

BitSet ( uint_t  size  ) 

Construct a new BitSet of the given size.

Parameters:
size The number of bits the BitSet will hold.

BitSet ( const BitSet other  ) 

Copy constructor.

BitSet ( const String bits  ) 

Construct a BitSet from a String.

Parameters:
bits A String consisting of only the characters '0' and '1'; any other characters will be interpreted as 0.

~BitSet (  )  throw () [virtual]

Destructor.


Member Function Documentation

BitSet& clear ( uint_t  pos  )  throw () [inline]

Clear the bit at the given position.

Parameters:
pos The position.

BitSet& clearAll (  )  throw () [inline]

Clear all of the bits in the BitSet.

BitSet& clearRange ( uint_t  startPos,
uint_t  endPos 
) throw () [inline]

Clear the bits in the given (inclusive) range.

Parameters:
startPos The start position of the range.
endPos The end position of the range.

int firstClearBit (  )  const throw () [inline]

Find the index of the first bit that is clear.

Returns:
The index of the bit, or -1 if there are no clear bits in the BitSet.

int firstSetBit (  )  const throw () [inline]

Find the index of the first bit that is set.

Returns:
The index of the bit, or -1 if there are no set bits in the BitSet.

BitSet & flip ( uint_t  pos  )  throw (OutOfBoundsException)

Flip (toggle) the bit at the given position.

Exceptions:
OutOfBoundsException If the position is invalid.

BitSet & flip (  )  throw ()

Flip (toggle) all of the bits in the BitSet.

bool get ( uint_t  pos  )  const throw () [inline]

Get the value of the bit at the given position.

uint_t getSize (  )  const throw () [inline]

Get the size of the BitSet, in bits.

Reimplemented in AllocationMap.

uint32_t getWord ( uint_t  index  )  const throw () [inline]

Get the word at the specified index in the BitSet.

Parameters:
index The index. If the index is out of range, a value of 0 is returned.
Returns:
The word.

size_t getWordCount (  )  const throw () [inline]

Get the number of words in the BitSet.

(Each word is a 32-bit integer.)

uint32_t getWordDiff ( uint_t  index,
uint32_t  other 
) const throw () [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.

Parameters:
index The index. If the index is out of range, a value of 0 is returned.
other The other word to "diff" against.
Returns:
The "diff" of the two words.

bool isAllClear (  )  const throw () [inline]

Test if all of the bits are clear in the BitSet.

bool isAllSet (  )  const throw ()

Test if all of the bits are set in the BitSet.

bool isAnySet (  )  const throw ()

Test if at least one bit is set in the BitSet.

bool isClear ( uint_t  pos  )  const throw () [inline]

Test if a bit at the given position is clear.

bool isSet ( uint_t  pos  )  const throw ()

Test if a bit at the given position is set.

int nextClearBit ( uint_t  startPos  )  const throw () [inline]

Find the index of the next bit that is clear, beginning at the given position.

Parameters:
startPos The starting bit position to search from.
Returns:
The index of the bit, or -1 if there are no clear bits between the start position and the end of the BitSet, inclusive.

int nextSetBit ( uint_t  startPos  )  const throw () [inline]

Find the index of the next bit that is set, beginning at the given position.

Parameters:
startPos The starting bit position to search from.
Returns:
The index of the bit, or -1 if there are no set bits between the start position and the end of the BitSet, inclusive.

bool operator! (  )  const throw () [inline]

Test if all of the bits in the BitSet are cleared.

Equivalent to isAllClear().

bool operator!= ( const BitSet other  )  const throw () [inline]

Inequality operator.

BitSet & operator&= ( const BitSet other  )  throw (OutOfBoundsException)

Bitwise AND assignment operator.

Exceptions:
OutOfBoundsException If the two BitSets are not of equal size.

BitSet operator<< ( size_t  n  )  const [inline]

Bitwise left-shift operator.

Parameters:
n The number of bit positions by which to shift the BitSet.
Returns:
A new BitSet that is a bit-shifted version of the original.

BitSet & operator<<= ( size_t  n  )  throw ()

Bitwise left-shift assignment operator.

Parameters:
n The number of bit positions by which to shift the BitSet.

BitSet & operator= ( const BitSet other  ) 

Assignment operator.

bool operator== ( const BitSet other  )  const throw ()

Equality operator.

BitSet operator>> ( size_t  n  )  const [inline]

Bitwise right-shift operator.

Parameters:
n The number of bit positions by which to shift the BitSet.
Returns:
A new BitSet that is a bit-shifted version of the original.

BitSet & operator>>= ( size_t  n  )  throw ()

Bitwise right-shift assignment operator.

Parameters:
n The number of bit positions by which to shift the BitSet.

bool operator[] ( uint_t  pos  )  const throw () [inline]

Get the value of a bit at the given position.

Parameters:
pos The position.
Returns:
The value of the bit, or false if the position is invalid.

BitSet::Bit operator[] ( uint_t  pos  )  throw (OutOfBoundsException)

Obtain a "reference" to a bit at the given position.

Parameters:
pos The position.
Returns:
The bit.
Exceptions:
OutOfBoundsException If the position is invalid.

BitSet & operator^= ( const BitSet other  )  throw (OutOfBoundsException)

Bitwise XOR assignment operator.

Exceptions:
OutOfBoundsException If the two BitSets are not of equal size.

BitSet & operator|= ( const BitSet other  )  throw (OutOfBoundsException)

Bitwise OR assignment operator.

Exceptions:
OutOfBoundsException If the two BitSets are not of equal size.

BitSet operator~ (  )  const throw () [inline]

Bitwise NOT operator.

Returns:
A new BitSet that is a bit-flipped version of the original.

BitSet & set ( uint_t  pos,
bool  value = true 
) throw ()

Set (or clear) a bit at the given position.

Parameters:
pos The position of the bit.
value The value to set the bit to.

BitSet & setAll ( bool  value = true  )  throw ()

Set (or clear) all of the bits in the BitSet.

Parameters:
value The value to set all of the bits to.

BitSet & setRange ( uint_t  startPos,
uint_t  endPos,
bool  value = true 
) throw ()

Set (or clear) the bits in the given (inclusive) range.

Parameters:
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 
) throw ()

Set the word at the specified index in the BitSet.

Parameters:
index The index. If the index is out of range, the method has no effect.
word The word.

void swap ( BitSet other  )  throw (OutOfBoundsException)

Swap the bits of this BitSet with those of another.

Exceptions:
OutOfBoundsException If both BitSets are not of equal size.

String toString (  )  const

Get a String representation of the BitSet.

void write ( std::ostream &  stream  )  const

Write a string representation of the BitSet to a stream.


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

Generated on Sat Apr 17 23:03:07 2010 for libcommonc++ by  doxygen 1.5.9