Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
Bitset Class Reference

A class representing a bitset with dynamic size. More...

#include <Bitset.hpp>

Collaboration diagram for Bitset:

Public Member Functions

 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
 
Bitsetset (int)
 
void reset () noexcept
 
Bitsetreset (int)
 
Bitsetflip () noexcept
 
Bitsetoperator= (const Bitset &other) noexcept
 
Bitset operator~ () const noexcept
 
int operator[] (int) noexcept
 

Public Attributes

int bits = 8 * sizeof(ull)
 
int m_size = 0
 
int n = 0
 
ull * array
 
ull hashval
 

Static Public Attributes

static const ull size_correcter = 1ull
 
static const ull one_bit = 1ull
 
static const ull zero_bit = 0ull
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Bitset()

Bitset::Bitset ( size_t size,
bool default_value = false )
inline

Construct a new Bitset object.

Parameters
sizeThe number of bits in the bitset.
default_valueThe 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.

Member Function Documentation

◆ 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
BinaryOpA 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_bitsetsA vector of Bitsets to merge with this Bitset.
opA 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_bitsetsThe 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_bitsetsThe 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
posThe 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_sizeThe new size of the bitset.

◆ set()

void Bitset::set ( size_t pos,
bool value = true )
inline

Set a bit in the bitset.

Parameters
posThe position of the bit to set.
valueThe 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: