3 #include "../util/boost_util.h"
5 #include <boost/dynamic_bitset.hpp>
27 static auto constexpr
npos = BaseType::npos;
45 return &mBitset == &rhs.
mBitset;
52 operator std::size_t()
const {
72 assert(compatible(rhs));
73 return mBit == rhs.
mBit;
77 assert(compatible(rhs));
78 return !(*
this == rhs);
82 assert(compatible(rhs));
83 return mBit < rhs.
mBit;
94 if (pos >=
mData.size()) {
104 Bitset(
const std::initializer_list<std::size_t>& bits,
bool defaultValue =
false):
mDefault(defaultValue) {
111 auto resize(std::size_t num_bits,
bool value)
const {
112 return mData.resize(num_bits, value);
115 auto resize(std::size_t num_bits)
const {
148 for (; start <=
end; start++) {
149 mData.set(start, value);
160 bool test(std::size_t n)
const {
161 if (n >=
mData.size()) {
164 return mData.test(n);
180 return mData.count();
189 return mData.num_blocks();
201 return mData.find_first();
205 return mData.find_next(pos);
220 }
else if (lhs.
size() > rhs.
size()) {
268 return std::hash<carl::Bitset::BaseType>()(bs.
mData);
carl is the main namespace for the library.
This class is a simple wrapper around boost::dynamic_bitset.
static constexpr auto bits_per_block
Number of bits in each storage block.
friend std::ostream & operator<<(std::ostream &os, const Bitset &b)
Outputs b to os using the format <explicit bits>[<default>].
auto is_subset_of(const Bitset &rhs) const
Checks wether the bits set is a subset of the bits set in rhs.
Bitset & operator|=(const Bitset &rhs)
Computes the bitwise or with rhs.
Bitset(bool defaultValue=false)
Create an empty bitset.
iterator end() const
Returns an past-the-end iterator.
friend bool operator==(const Bitset &lhs, const Bitset &rhs)
Compares lhs and rhs.
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.
friend void alignSize(const Bitset &lhs, const Bitset &rhs)
Ensures that the explicitly stored bits of lhs and rhs have the same size.
bool mDefault
The default value for bits beyond mData.
bool none() const
Checks if no bits are set to true. Asserts that mDefault is false.
auto num_blocks() const
Retrieves the number of blocks used to store mData.
friend Bitset operator~(const Bitset &lhs)
Returns the bitwise negation of lhs.
friend Bitset operator|(const Bitset &lhs, const Bitset &rhs)
Returns the bitwise or of lhs and rhs.
std::size_t find_first() const
Retrieves the index of the first bit that is set to true.
friend bool operator<(const Bitset &lhs, const Bitset &rhs)
Compares lhs and rhs according to some order.
void ensureSize(std::size_t pos)
Resize mData to hold at least pos bits.
std::size_t find_next(std::size_t pos) const
Retrieves the index of the first bit set to true after the given position.
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.
Bitset & reset(std::size_t n)
Resets a bit to false.
Bitset(BaseType &&base, bool defaultValue)
Create a bitset from a BaseType object.
static constexpr auto npos
Sentinel element for iteration.
auto resize(std::size_t num_bits) const
Resize the Bitset to hold at least num_bits bits. New bits are set to mDefault.
auto count() const noexcept
Counts the number of bits that are set to true. Asserts that mDefault is false.
Bitset & set(std::size_t n, bool value=true)
Sets the given bit to a value, true by default.
Bitset & operator&=(const Bitset &rhs)
Computes the bitwise and with rhs.
Bitset & operator-=(const Bitset &rhs)
Sets all bits to false that are true in rhs.
bool any() const
Checks if any bits are set to true. Asserts that mDefault is false.
auto size() const
Retrieves the size of mData.
BaseType mData
The actual data.
iterator begin() const
Returns an iterator to the first bit that is set to true.
Bitset & set_interval(std::size_t start, std::size_t end, bool value=true)
Sets the a range of bits to a value, true by default.
boost::dynamic_bitset<> BaseType
Underlying storage type.
bool test(std::size_t n) const
Retrieves the value of the given bit.
friend Bitset operator&(const Bitset &lhs, const Bitset &rhs)
Returns the bitwise and of lhs and rhs.
Iterate for iterate over all bits of a Bitset that are set to true.
bool compatible(const iterator &rhs) const
Check that two iterators speak about the same Bitset.
iterator(const Bitset &b, std::size_t bit)
Construct a new iterator from a Bitset and a bit.
std::size_t operator*() const
Retrieve the index into the Bitset.
bool operator!=(const iterator &rhs) const
Compare two iterators. Asserts that they are compatible.
std::size_t mBit
The current bit.
bool operator==(const iterator &rhs) const
Compare two iterators. Asserts that they are compatible.
bool operator<(const iterator &rhs) const
Compare two iterators. Asserts that they are compatible.
iterator & operator++()
Step to the next bit that is set to true.
const Bitset & mBitset
The Bitset iterated over.
iterator operator++(int)
Step to the next bit that is set to true.
std::size_t operator()(const carl::Bitset &bs) const