carl  24.04
Computer ARithmetic Library
carl::Bitset Class Reference

This class is a simple wrapper around boost::dynamic_bitset. More...

#include <Bitset.h>

Data Structures

struct  iterator
 Iterate for iterate over all bits of a Bitset that are set to true. More...
 

Public Types

using BaseType = boost::dynamic_bitset<>
 Underlying storage type. More...
 

Public Member Functions

 Bitset (bool defaultValue=false)
 Create an empty bitset. More...
 
 Bitset (BaseType &&base, bool defaultValue)
 Create a bitset from a BaseType object. More...
 
 Bitset (const std::initializer_list< std::size_t > &bits, bool defaultValue=false)
 Create a bitset from a list of bits indices that shall be set to true. More...
 
auto resize (std::size_t num_bits, bool value) const
 Resize the Bitset to hold at least num_bits bits. New bits are set to the given value. More...
 
auto resize (std::size_t num_bits) const
 Resize the Bitset to hold at least num_bits bits. New bits are set to mDefault. More...
 
Bitsetoperator-= (const Bitset &rhs)
 Sets all bits to false that are true in rhs. More...
 
Bitsetoperator&= (const Bitset &rhs)
 Computes the bitwise and with rhs. More...
 
Bitsetoperator|= (const Bitset &rhs)
 Computes the bitwise or with rhs. More...
 
Bitsetset (std::size_t n, bool value=true)
 Sets the given bit to a value, true by default. More...
 
Bitsetset_interval (std::size_t start, std::size_t end, bool value=true)
 Sets the a range of bits to a value, true by default. More...
 
Bitsetreset (std::size_t n)
 Resets a bit to false. More...
 
bool test (std::size_t n) const
 Retrieves the value of the given bit. More...
 
bool any () const
 Checks if any bits are set to true. Asserts that mDefault is false. More...
 
bool none () const
 Checks if no bits are set to true. Asserts that mDefault is false. More...
 
auto count () const noexcept
 Counts the number of bits that are set to true. Asserts that mDefault is false. More...
 
auto size () const
 Retrieves the size of mData. More...
 
auto num_blocks () const
 Retrieves the number of blocks used to store mData. More...
 
auto is_subset_of (const Bitset &rhs) const
 Checks wether the bits set is a subset of the bits set in rhs. More...
 
std::size_t find_first () const
 Retrieves the index of the first bit that is set to true. More...
 
std::size_t find_next (std::size_t pos) const
 Retrieves the index of the first bit set to true after the given position. More...
 
iterator begin () const
 Returns an iterator to the first bit that is set to true. More...
 
iterator end () const
 Returns an past-the-end iterator. More...
 

Static Public Attributes

static constexpr auto npos = BaseType::npos
 Sentinel element for iteration. More...
 
static constexpr auto bits_per_block = BaseType::bits_per_block
 Number of bits in each storage block. More...
 

Private Member Functions

void ensureSize (std::size_t pos)
 Resize mData to hold at least pos bits. More...
 

Private Attributes

BaseType mData
 The actual data. More...
 
bool mDefault
 The default value for bits beyond mData. More...
 

Friends

struct std::hash< carl::Bitset >
 
void alignSize (const Bitset &lhs, const Bitset &rhs)
 Ensures that the explicitly stored bits of lhs and rhs have the same size. More...
 
bool operator== (const Bitset &lhs, const Bitset &rhs)
 Compares lhs and rhs. More...
 
bool operator< (const Bitset &lhs, const Bitset &rhs)
 Compares lhs and rhs according to some order. More...
 
Bitset operator~ (const Bitset &lhs)
 Returns the bitwise negation of lhs. More...
 
Bitset operator& (const Bitset &lhs, const Bitset &rhs)
 Returns the bitwise and of lhs and rhs. More...
 
Bitset operator| (const Bitset &lhs, const Bitset &rhs)
 Returns the bitwise or of lhs and rhs. More...
 
std::ostream & operator<< (std::ostream &os, const Bitset &b)
 Outputs b to os using the format <explicit bits>[<default>]. More...
 

Detailed Description

This class is a simple wrapper around boost::dynamic_bitset.

Its purpose is to allow for on-the-fly resizing of the bitset. Formally, a Bitset object represents an infinite bitset that starts with the bits stored in mData extended by mDefault. Whenever a bit is written that is not yet stored explicitly in mData or two Bitset objects with different mData sizes are involved, the size of mData is expanded transparently.

Note that some operations only make sense for a certain value of mDefault. For example, any() or none() require mDefault to be false.

Definition at line 20 of file Bitset.h.

Member Typedef Documentation

◆ BaseType

using carl::Bitset::BaseType = boost::dynamic_bitset<>

Underlying storage type.

Definition at line 25 of file Bitset.h.

Constructor & Destructor Documentation

◆ Bitset() [1/3]

carl::Bitset::Bitset ( bool  defaultValue = false)
inlineexplicit

Create an empty bitset.

Definition at line 100 of file Bitset.h.

◆ Bitset() [2/3]

carl::Bitset::Bitset ( BaseType &&  base,
bool  defaultValue 
)
inline

Create a bitset from a BaseType object.

Definition at line 102 of file Bitset.h.

◆ Bitset() [3/3]

carl::Bitset::Bitset ( const std::initializer_list< std::size_t > &  bits,
bool  defaultValue = false 
)
inline

Create a bitset from a list of bits indices that shall be set to true.

Definition at line 104 of file Bitset.h.

Here is the call graph for this function:

Member Function Documentation

◆ any()

bool carl::Bitset::any ( ) const
inline

Checks if any bits are set to true. Asserts that mDefault is false.

Definition at line 167 of file Bitset.h.

Here is the caller graph for this function:

◆ begin()

iterator carl::Bitset::begin ( ) const
inline

Returns an iterator to the first bit that is set to true.

Definition at line 208 of file Bitset.h.

Here is the call graph for this function:

◆ count()

auto carl::Bitset::count ( ) const
inlinenoexcept

Counts the number of bits that are set to true. Asserts that mDefault is false.

Definition at line 178 of file Bitset.h.

◆ end()

iterator carl::Bitset::end ( ) const
inline

Returns an past-the-end iterator.

Definition at line 212 of file Bitset.h.

Here is the caller graph for this function:

◆ ensureSize()

void carl::Bitset::ensureSize ( std::size_t  pos)
inlineprivate

Resize mData to hold at least pos bits.

Definition at line 93 of file Bitset.h.

Here is the caller graph for this function:

◆ find_first()

std::size_t carl::Bitset::find_first ( ) const
inline

Retrieves the index of the first bit that is set to true.

Definition at line 200 of file Bitset.h.

Here is the caller graph for this function:

◆ find_next()

std::size_t carl::Bitset::find_next ( std::size_t  pos) const
inline

Retrieves the index of the first bit set to true after the given position.

Definition at line 204 of file Bitset.h.

Here is the caller graph for this function:

◆ is_subset_of()

auto carl::Bitset::is_subset_of ( const Bitset rhs) const
inline

Checks wether the bits set is a subset of the bits set in rhs.

Definition at line 192 of file Bitset.h.

Here is the caller graph for this function:

◆ none()

bool carl::Bitset::none ( ) const
inline

Checks if no bits are set to true. Asserts that mDefault is false.

Definition at line 172 of file Bitset.h.

◆ num_blocks()

auto carl::Bitset::num_blocks ( ) const
inline

Retrieves the number of blocks used to store mData.

Definition at line 188 of file Bitset.h.

Here is the caller graph for this function:

◆ operator&=()

Bitset& carl::Bitset::operator&= ( const Bitset rhs)
inline

Computes the bitwise and with rhs.

Definition at line 127 of file Bitset.h.

◆ operator-=()

Bitset& carl::Bitset::operator-= ( const Bitset rhs)
inline

Sets all bits to false that are true in rhs.

Definition at line 120 of file Bitset.h.

◆ operator|=()

Bitset& carl::Bitset::operator|= ( const Bitset rhs)
inline

Computes the bitwise or with rhs.

Definition at line 133 of file Bitset.h.

◆ reset()

Bitset& carl::Bitset::reset ( std::size_t  n)
inline

Resets a bit to false.

Definition at line 154 of file Bitset.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize() [1/2]

auto carl::Bitset::resize ( std::size_t  num_bits) const
inline

Resize the Bitset to hold at least num_bits bits. New bits are set to mDefault.

Definition at line 115 of file Bitset.h.

◆ resize() [2/2]

auto carl::Bitset::resize ( std::size_t  num_bits,
bool  value 
) const
inline

Resize the Bitset to hold at least num_bits bits. New bits are set to the given value.

Definition at line 111 of file Bitset.h.

Here is the caller graph for this function:

◆ set()

Bitset& carl::Bitset::set ( std::size_t  n,
bool  value = true 
)
inline

Sets the given bit to a value, true by default.

Definition at line 140 of file Bitset.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_interval()

Bitset& carl::Bitset::set_interval ( std::size_t  start,
std::size_t  end,
bool  value = true 
)
inline

Sets the a range of bits to a value, true by default.

Definition at line 146 of file Bitset.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

auto carl::Bitset::size ( ) const
inline

Retrieves the size of mData.

Definition at line 184 of file Bitset.h.

Here is the caller graph for this function:

◆ test()

bool carl::Bitset::test ( std::size_t  n) const
inline

Retrieves the value of the given bit.

Definition at line 160 of file Bitset.h.

Friends And Related Function Documentation

◆ alignSize

void alignSize ( const Bitset lhs,
const Bitset rhs 
)
friend

Ensures that the explicitly stored bits of lhs and rhs have the same size.

Definition at line 217 of file Bitset.h.

◆ operator&

Bitset operator& ( const Bitset lhs,
const Bitset rhs 
)
friend

Returns the bitwise and of lhs and rhs.

Definition at line 246 of file Bitset.h.

◆ operator<

bool operator< ( const Bitset lhs,
const Bitset rhs 
)
friend

Compares lhs and rhs according to some order.

Definition at line 231 of file Bitset.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Bitset b 
)
friend

Outputs b to os using the format <explicit bits>[<default>].

Definition at line 257 of file Bitset.h.

◆ operator==

bool operator== ( const Bitset lhs,
const Bitset rhs 
)
friend

Compares lhs and rhs.

Definition at line 226 of file Bitset.h.

◆ operator|

Bitset operator| ( const Bitset lhs,
const Bitset rhs 
)
friend

Returns the bitwise or of lhs and rhs.

Definition at line 251 of file Bitset.h.

◆ operator~

Bitset operator~ ( const Bitset lhs)
friend

Returns the bitwise negation of lhs.

Definition at line 242 of file Bitset.h.

◆ std::hash< carl::Bitset >

friend struct std::hash< carl::Bitset >
friend

Definition at line 1 of file Bitset.h.

Field Documentation

◆ bits_per_block

constexpr auto carl::Bitset::bits_per_block = BaseType::bits_per_block
staticconstexpr

Number of bits in each storage block.

Definition at line 29 of file Bitset.h.

◆ mData

BaseType carl::Bitset::mData
mutableprivate

The actual data.

Definition at line 89 of file Bitset.h.

◆ mDefault

bool carl::Bitset::mDefault
private

The default value for bits beyond mData.

Definition at line 91 of file Bitset.h.

◆ npos

constexpr auto carl::Bitset::npos = BaseType::npos
staticconstexpr

Sentinel element for iteration.

Definition at line 27 of file Bitset.h.


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