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/latest/src/axom/slam/BitSet.hpp>

Public Types

using Index = int
 
using Word = std::uint64_t
 
using ArrayType = axom::Array< Word, 1 >
 

Public Member Functions

 BitSet (int numBits=0, int allocatorID=axom::getDefaultAllocatorID())
 BitSet class constructor. 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...
 
AXOM_HOST_DEVICE const Worddata () const
 Gets the underlying data of a BitSet. More...
 
Bitset bitwise assignment operators
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
AXOM_HOST_DEVICE 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...
 
Atomic versions of single-bit operations
void atomicClear (Index idx)
 Clears bit at index idx. More...
 
AXOM_HOST_DEVICE void atomicSet (Index idx)
 Sets bit at index idx. More...
 
void atomicFlip (Index idx)
 Toggles bit at index idx. More...
 

Static Public Attributes

static constexpr Index npos = -2
 
static constexpr int BitsPerWord
 

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 sentinel to indicate no more set bits.

Member Typedef Documentation

◆ Index

◆ Word

using axom::slam::BitSet::Word = std::uint64_t

◆ ArrayType

Constructor & Destructor Documentation

◆ BitSet()

axom::slam::BitSet::BitSet ( int  numBits = 0,
int  allocatorID = axom::getDefaultAllocatorID() 
)
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 BitsPerWord, axom::Array< T, DIM, SPACE >::fill(), axom::utilities::max(), and SLIC_ASSERT_MSG.

Member Function Documentation

◆ operator==()

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

Equality operator for two bitsets.

◆ operator!=()

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

Inequality operator for two bitsets.

References operator==().

◆ data()

AXOM_HOST_DEVICE const Word* axom::slam::BitSet::data ( ) const
inline

Gets the underlying data of a BitSet.

References axom::Array< T, DIM, SPACE >::data().

◆ 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

◆ 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

◆ 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.

◆ 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

◆ 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

◆ 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

◆ size()

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

Returns the cardinality of the bitset.

◆ count()

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

Returns the number of bits that are set.

◆ clear() [1/2]

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

Clears all bits in the bitset.

◆ 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.

◆ 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.

◆ 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 idx is valid and its bit is set, false otherwise

◆ atomicClear()

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

Clears bit at index idx.

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

References clear().

◆ atomicSet()

AXOM_HOST_DEVICE void axom::slam::BitSet::atomicSet ( Index  idx)
inline

Sets bit at index idx.

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

References set().

◆ atomicFlip()

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

Toggles bit at index idx.

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

References flip().

Member Data Documentation

◆ npos

constexpr Index axom::slam::BitSet::npos = -2
staticconstexpr

◆ BitsPerWord

constexpr int axom::slam::BitSet::BitsPerWord
staticconstexpr
Initial value:

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