A class representing a bitset with dynamic size.
More...
#include <Bitset.hpp>
|
| | Bitset (size_t size, bool default_value=false) |
| | Construct a new Bitset object.
|
| |
| size_t | num_blocks () const |
| | Calculate the number of blocks needed to store the bits.
|
| |
| bool | operator[] (size_t pos) const |
| | Access a bit in the bitset.
|
| |
| void | set (size_t pos, bool value=true) |
| | Set a bit in the bitset.
|
| |
|
void | clear () |
| | Clear all bits in the bitset.
|
| |
| void | resize (size_t new_size) |
| | Resize the bitset.
|
| |
| size_t | size () const |
| | Get the size of the bitset.
|
| |
| template<typename BinaryOp > |
| void | merge (const std::vector< Bitset > &other_bitsets, BinaryOp op) |
| | Merge multiple bitsets with this bitset using a custom binary operation.
|
| |
| void | merge_or (const std::vector< Bitset > &other_bitsets) |
| | Merge multiple bitsets using the OR operation.
|
| |
| void | merge_and (const std::vector< Bitset > &other_bitsets) |
| | Merge multiple bitsets using the AND operation.
|
| |
| unsigned long long * | data () |
| | Get a pointer to the underlying data.
|
| |
| const unsigned long long * | data () const |
| | Get a const pointer to the underlying data.
|
| |
|
void | print () |
| |
|
void | hash () noexcept |
| |
|
void | allocate (int sz) noexcept |
| |
|
void | random () noexcept |
| |
|
void | free () noexcept |
| |
|
void | eqs (const Bitset &u, int s) noexcept |
| |
|
void | ands (const Bitset &u, const Bitset &v, int s, int s1, int s2) noexcept |
| |
|
void | xors (const Bitset &u, const Bitset &v, int s, int s1, int s2) noexcept |
| |
|
bool | operator== (const Bitset &rhs) const noexcept |
| |
|
constexpr int | size () const noexcept |
| |
|
void | set () noexcept |
| |
|
Bitset & | set (int) |
| |
|
void | reset () noexcept |
| |
|
Bitset & | reset (int) |
| |
|
Bitset & | flip () noexcept |
| |
|
Bitset & | operator= (const Bitset &other) noexcept |
| |
|
Bitset | operator~ () const noexcept |
| |
|
int | operator[] (int) noexcept |
| |
|
|
int | bits = 8 * sizeof(ull) |
| |
|
int | m_size = 0 |
| |
|
int | n = 0 |
| |
|
ull * | array |
| |
|
ull | hashval |
| |
|
|
static const ull | size_correcter = 1ull |
| |
|
static const ull | one_bit = 1ull |
| |
|
static const ull | zero_bit = 0ull |
| |
A class representing a bitset with dynamic size.
This class provides efficient storage and manipulation of a sequence of bits. It uses unsigned long long as the underlying storage type. Out of bound bits are set to zero for consistency in merge
◆ Bitset()
| Bitset::Bitset |
( |
size_t | size, |
|
|
bool | default_value = false ) |
|
inline |
Construct a new Bitset object.
- Parameters
-
| size | The number of bits in the bitset. |
| default_value | The default value for all bits (false by default). |
This constructor initializes a Bitset with the given number of bits. All bits are set to the specified default value. If the size is not a multiple of BITS_PER_BLOCK (typically 64), the constructor ensures that any unused bits in the last block are set to zero, maintaining consistency of the bitset.
◆ data() [1/2]
| unsigned long long * Bitset::data |
( |
| ) |
|
|
inline |
Get a pointer to the underlying data.
- Returns
- A pointer to the first element of the underlying data.
◆ data() [2/2]
| const unsigned long long * Bitset::data |
( |
| ) |
const |
|
inline |
Get a const pointer to the underlying data.
- Returns
- A const pointer to the first element of the underlying data.
◆ merge()
template<typename BinaryOp >
| void Bitset::merge |
( |
const std::vector< Bitset > & | other_bitsets, |
|
|
BinaryOp | op ) |
|
inline |
Merge multiple bitsets with this bitset using a custom binary operation.
- Template Parameters
-
| BinaryOp | A callable type that takes two unsigned long long arguments and returns an unsigned long long. This type is deduced from the argument passed to the function. |
- Parameters
-
| other_bitsets | A vector of Bitsets to merge with this Bitset. |
| op | A binary operation used to combine bits. It should be a callable (function, lambda, or function object) that takes two unsigned long long arguments and returns an unsigned long long. |
- Note
- This function uses template argument deduction, allowing for flexible usage with different types of binary operations without explicitly specifying the template parameter.
// Using a lambda function bitset.merge(other_bitsets, [](unsigned long long a, unsigned long long b) { return a | b; });
// Using a standard library function object bitset.merge(other_bitsets, std::bit_or<unsigned long long>());
// Using a custom function unsigned long long custom_or(unsigned long long a, unsigned long long b) { return a | b; } bitset.merge(other_bitsets, custom_or);
◆ merge_and()
| void Bitset::merge_and |
( |
const std::vector< Bitset > & | other_bitsets | ) |
|
|
inline |
Merge multiple bitsets using the AND operation.
- Parameters
-
| other_bitsets | The bitsets to merge with. |
◆ merge_or()
| void Bitset::merge_or |
( |
const std::vector< Bitset > & | other_bitsets | ) |
|
|
inline |
Merge multiple bitsets using the OR operation.
- Parameters
-
| other_bitsets | The bitsets to merge with. |
◆ num_blocks()
| size_t Bitset::num_blocks |
( |
| ) |
const |
|
inline |
Calculate the number of blocks needed to store the bits.
- Returns
- The number of blocks.
◆ operator[]()
| bool Bitset::operator[] |
( |
size_t | pos | ) |
const |
|
inline |
Access a bit in the bitset.
- Parameters
-
| pos | The position of the bit to access. |
- Returns
- The value of the bit at the specified position.
◆ resize()
| void Bitset::resize |
( |
size_t | new_size | ) |
|
|
inline |
Resize the bitset.
- Parameters
-
| new_size | The new size of the bitset. |
◆ set()
| void Bitset::set |
( |
size_t | pos, |
|
|
bool | value = true ) |
|
inline |
Set a bit in the bitset.
- Parameters
-
| pos | The position of the bit to set. |
| value | The value to set (true by default). |
◆ size()
| size_t Bitset::size |
( |
| ) |
const |
|
inline |
Get the size of the bitset.
- Returns
- The number of bits in the bitset.
The documentation for this class was generated from the following files:
- /github/workspace/src/containers/Bitset.hpp
- /github/workspace/src/preprocessors/PRS-Preprocessors/utils-prs/bitset.hpp