AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::slam::BitSet Class Reference

A bitset class. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.5.0/src/axom/slam/BitSet.hpp>

Public Types

using Index = int
 
using Word = axom::uint64
 
using ArrayType = std::vector< Word >
 

Public Member Functions

 BitSet (int numBits=0)
 BitSet class constructor. More...
 
 BitSet (const BitSet &other)
 Copy constructor for BitSet class. More...
 
bool operator== (const BitSet &other) const
 Equality operator for two bitsets. More...
 
bool operator!= (const BitSet &other) const
 Inequality operator for two bitsets. More...
 
Bitset bitwise assignment operators
BitSetoperator= (const BitSet &other)
 Assignment operator for BitSet class. More...
 
BitSetoperator|= (const BitSet &other)
 BitSet union-assignment operator. More...
 
BitSetoperator &= (const BitSet &other)
 BitSet intersection-assignment operator. More...
 
BitSetoperator^= (const BitSet &other)
 BitSet exclusive-or-assignment operator. More...
 
BitSetoperator-= (const BitSet &other)
 BitSet difference-assignment operator. More...
 
Bitset iteration interface
Index find_first () const
 Finds the index of the first bit that is set in the bitset. More...
 
Index find_next (Index idx) const
 Finds the index of the next set bit in the bitset after idx. More...
 
Operations that affect all bits in the bitset
int size () const
 Returns the cardinality of the bitset. More...
 
int count () const
 Returns the number of bits that are set. More...
 
void clear ()
 Clears all bits in the bitset. More...
 
void set ()
 Sets all bits in the bitset. More...
 
void flip ()
 Toggles all bits in the bitset. More...
 
bool isValid () const
 Checks if the bitset instance is valid. More...
 
Operations that affect a single bits in the bitset
void clear (Index idx)
 Clears bit at index idx. More...
 
void set (Index idx)
 Sets bit at index idx. More...
 
void flip (Index idx)
 Toggles bit at index idx. More...
 
bool test (Index idx) const
 Tests the bit at index idx. More...
 

Static Public Attributes

static const Index npos
 

Detailed Description

A bitset class.

This class supports bitwise manipulation operations (e.g. set intersection, union and difference) on an ordered set of bits. The class has a similar interface to std::bitset and boost::dynamic_bitset, but with the following differences:

  • The size of the bitset is supplied at runtime in the class constructor. However, BitSet does not currently support changing the size after construction.
  • We do not support the random access operation ( operator[](index) ). The value of individual bits can be checked using the test function (e.g. bset.test(i) )
  • There is no support for directly initializing the bits in the bitset (e.g. via strings).

The individual bits in the bitset are packed into a contiguous array of Words (an unsigned integer type). Many bitset operations such as count() and flip() are performed at the granularity of a word.

BitSet uses the same interface as boost::dynamic_bitset to enumerate the set bits. Specifically, find_first() returns the index of the first set bit. and find_next(idx) returns the next bit that is set after bit index idx. BitSet::npos is used as a sentinal to indicate no more set bits.

Member Typedef Documentation

◆ Index

◆ Word

◆ ArrayType

using axom::slam::BitSet::ArrayType = std::vector<Word>

Constructor & Destructor Documentation

◆ BitSet() [1/2]

axom::slam::BitSet::BitSet ( int  numBits = 0)
inlineexplicit

BitSet class constructor.

Parameters
numBitsThe number of bits in the bitset.
Precondition
numBits must be non-negative
Postcondition
bset.size() == numBits
All bits will be off

References axom::utilities::max(), and SLIC_ASSERT_MSG.

◆ BitSet() [2/2]

axom::slam::BitSet::BitSet ( const BitSet other)
inline

Copy constructor for BitSet class.

References operator==().

Member Function Documentation

◆ operator==()

bool axom::slam::BitSet::operator== ( const BitSet other) const

Equality operator for two bitsets.

Referenced by BitSet(), and operator!=().

◆ operator!=()

bool axom::slam::BitSet::operator!= ( const BitSet other) const
inline

Inequality operator for two bitsets.

References operator==().

◆ operator=()

BitSet& axom::slam::BitSet::operator= ( const BitSet other)
inline

Assignment operator for BitSet class.

References find_first(), find_next(), operator &=(), operator-=(), operator^=(), and operator|=().

◆ operator|=()

BitSet& axom::slam::BitSet::operator|= ( const BitSet other)

BitSet union-assignment operator.

Parameters
otherThe other bitset
Precondition
other.size() == size()
Returns
A reference to the modified bitset

Set union of the current instance and other. The i^th bit will be set if it is set in this bitset or in other

Referenced by operator=().

◆ operator &=()

BitSet& axom::slam::BitSet::operator&= ( const BitSet other)

BitSet intersection-assignment operator.

Parameters
otherThe other bitset
Precondition
other.size() == size()
Returns
A reference to the modified bitset

Set intersection of the current instance and other. The i^th bit will be set if it is set in this bitset and in other

Referenced by operator=().

◆ operator^=()

BitSet& axom::slam::BitSet::operator^= ( const BitSet other)

BitSet exclusive-or-assignment operator.

Parameters
otherThe other bitset
Precondition
other.size() == size()
Returns
A reference to the modified bitset

Set exclusive-or of the current instance and other. The i^th bit will be set if it is set in this bitset or in other, but not both.

Referenced by operator=().

◆ operator-=()

BitSet& axom::slam::BitSet::operator-= ( const BitSet other)

BitSet difference-assignment operator.

Parameters
otherThe other bitset
Precondition
other.size() == size()
Returns
A reference to the modified bitset

Set difference of the current instance and other. The i^th bit will be set if it is set in this bitset and not in other

Referenced by operator=().

◆ find_first()

Index axom::slam::BitSet::find_first ( ) const

Finds the index of the first bit that is set in the bitset.

Returns
The index of the first set bit, or BitSet::npos if no bits are set

Referenced by axom::spin::ImplicitGrid< NDIMS, TheIndexType >::getCandidatesAsArray(), and operator=().

◆ find_next()

Index axom::slam::BitSet::find_next ( Index  idx) const

Finds the index of the next set bit in the bitset after idx.

Parameters
idxThe starting index
Returns
The index of the first set bit after index idx or BitSet::npos if none can be found
Note
Will also return BitSet::npos if idx is BitSet::npos

Referenced by axom::spin::ImplicitGrid< NDIMS, TheIndexType >::getCandidatesAsArray(), and operator=().

◆ size()

int axom::slam::BitSet::size ( ) const
inline

Returns the cardinality of the bitset.

References clear(), count(), flip(), and isValid().

◆ count()

int axom::slam::BitSet::count ( ) const

Returns the number of bits that are set.

Referenced by axom::spin::ImplicitGrid< NDIMS, TheIndexType >::getCandidatesAsArray(), and size().

◆ clear() [1/2]

void axom::slam::BitSet::clear ( )

Clears all bits in the bitset.

Referenced by size().

◆ set() [1/2]

void axom::slam::BitSet::set ( )

Sets all bits in the bitset.

◆ flip() [1/2]

void axom::slam::BitSet::flip ( )

Toggles all bits in the bitset.

Referenced by size().

◆ isValid()

bool axom::slam::BitSet::isValid ( ) const

Checks if the bitset instance is valid.

Returns
True if the bitset is valid, false otherwise

A bitset is valid if it has sufficient storage for size() bits. If we have storage for more than size() bits, none of these additional bits are set.

Referenced by size().

◆ clear() [2/2]

void axom::slam::BitSet::clear ( Index  idx)
inline

Clears bit at index idx.

Precondition
idx must be between 0 and bitset.size()

◆ set() [2/2]

void axom::slam::BitSet::set ( Index  idx)
inline

Sets bit at index idx.

Precondition
idx must be between 0 and bitset.size()

◆ flip() [2/2]

void axom::slam::BitSet::flip ( Index  idx)
inline

Toggles bit at index idx.

Precondition
idx must be between 0 and bitset.size()

◆ test()

bool axom::slam::BitSet::test ( Index  idx) const
inline

Tests the bit at index idx.

Returns
True if bit is set, false otherwise
Precondition
idx must be between 0 and bitset.size()

References AXOM_DEBUG_VAR, and SLIC_ASSERT_MSG.

Member Data Documentation

◆ npos

const Index axom::slam::BitSet::npos
static

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