dynamic_bitset 1.3.2
Simple Useful Libraries: C++17/20 header-only dynamic bitset
Loading...
Searching...
No Matches
sul::dynamic_bitset< Block, Allocator > Class Template Reference

Dynamic bitset. More...

#include <sul/dynamic_bitset.hpp>

Classes

class  reference
 Reference to a sul::dynamic_bitset bit. More...
 

Public Types

typedef size_t size_type
 Type used to represent the size of a sul::dynamic_bitset.
 
typedef Block block_type
 Same type as Block.
 
typedef Allocator allocator_type
 Same type as Allocator.
 
typedef bool const_reference
 Const reference to a sul::dynamic_bitset bit, type bool.
 

Public Member Functions

constexpr dynamic_bitset (const dynamic_bitset< Block, Allocator > &other)=default
 Copy constructor.
 
constexpr dynamic_bitset (dynamic_bitset< Block, Allocator > &&other) noexcept=default
 Move constructor.
 
constexpr dynamic_bitset< Block, Allocator > & operator= (const dynamic_bitset< Block, Allocator > &other)=default
 Copy assignment operator.
 
constexpr dynamic_bitset< Block, Allocator > & operator= (dynamic_bitset< Block, Allocator > &&other) noexcept=default
 Move assignment operator.
 
constexpr dynamic_bitset (const allocator_type &allocator=allocator_type())
 Constructs an empty sul::dynamic_bitset.
 
constexpr dynamic_bitset (size_type nbits, unsigned long long init_val=0, const allocator_type &allocator=allocator_type())
 Constructs a sul::dynamic_bitset of nbits bits from an initial value.
 
constexpr dynamic_bitset (std::initializer_list< block_type > init_vals, const allocator_type &allocator=allocator_type())
 Constructs a sul::dynamic_bitset using init_vals to initialize the first blocks.
 
template<typename _CharT , typename _Traits >
constexpr dynamic_bitset (std::basic_string_view< _CharT, _Traits > str, typename std::basic_string_view< _CharT, _Traits >::size_type pos=0, typename std::basic_string_view< _CharT, _Traits >::size_type n=std::basic_string_view< _CharT, _Traits >::npos, _CharT zero=_CharT('0'), _CharT one=_CharT('1'), const allocator_type &allocator=allocator_type())
 Constructs a sul::dynamic_bitset from a string or a part of a string.
 
template<typename _CharT , typename _Traits , typename _Alloc >
constexpr dynamic_bitset (const std::basic_string< _CharT, _Traits, _Alloc > &str, typename std::basic_string< _CharT, _Traits, _Alloc >::size_type pos=0, typename std::basic_string< _CharT, _Traits, _Alloc >::size_type n=std::basic_string< _CharT, _Traits, _Alloc >::npos, _CharT zero=_CharT('0'), _CharT one=_CharT('1'), const allocator_type &allocator=allocator_type())
 Constructs a sul::dynamic_bitset from a string or a part of a string.
 
template<typename _CharT , typename _Traits = std::char_traits<_CharT>>
constexpr dynamic_bitset (const _CharT *str, typename std::basic_string< _CharT >::size_type pos=0, typename std::basic_string< _CharT >::size_type n=std::basic_string< _CharT >::npos, _CharT zero=_CharT('0'), _CharT one=_CharT('1'), const allocator_type &allocator=allocator_type())
 Constructs a sul::dynamic_bitset from a string or a part of a string.
 
 ~dynamic_bitset () noexcept=default
 Destructor.
 
constexpr void resize (size_type nbits, bool value=false)
 Resize the sul::dynamic_bitset to contain nbits bits.
 
constexpr void clear ()
 Clears the sul::dynamic_bitset, resize it to 0.
 
constexpr void push_back (bool value)
 Add a new bit with the value value at the end of the sul::dynamic_bitset.
 
constexpr void pop_back ()
 Remove the last bit of the sul::dynamic_bitset.
 
constexpr void append (block_type block)
 Append a block of bits block at the end of the sul::dynamic_bitset.
 
constexpr void append (std::initializer_list< block_type > blocks)
 Append blocks of bits from blocks at the end of the sul::dynamic_bitset.
 
template<typename BlockInputIterator >
constexpr void append (BlockInputIterator first, BlockInputIterator last)
 Append blocks of bits from the range [first, last[ at the end of the dynamic_bitset.
 
constexpr dynamic_bitset< Block, Allocator > & operator&= (const dynamic_bitset< Block, Allocator > &rhs)
 Sets the bits to the result of binary AND on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitset< Block, Allocator > & operator|= (const dynamic_bitset< Block, Allocator > &rhs)
 Sets the bits to the result of binary OR on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitset< Block, Allocator > & operator^= (const dynamic_bitset< Block, Allocator > &rhs)
 Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and rhs.
 
constexpr dynamic_bitset< Block, Allocator > & operator-= (const dynamic_bitset< Block, Allocator > &rhs)
 Sets the bits to the result of the binary difference between the bits of *this and rhs.
 
constexpr dynamic_bitset< Block, Allocator > & operator<<= (size_type shift)
 Performs binary shift left of shift bits.
 
constexpr dynamic_bitset< Block, Allocator > & operator>>= (size_type shift)
 Performs binary shift right of shift bits.
 
constexpr dynamic_bitset< Block, Allocator > operator<< (size_type shift) const
 Performs binary shift right of shift bits.
 
constexpr dynamic_bitset< Block, Allocator > operator>> (size_type shift) const
 Performs binary shift left of shift bits.
 
constexpr dynamic_bitset< Block, Allocator > operator~ () const
 Performs a unary NOT on all bits.
 
constexpr dynamic_bitset< Block, Allocator > & set (size_type pos, size_type len, bool value)
 Set the bits of the range [pos, pos + len[ to value value.
 
constexpr dynamic_bitset< Block, Allocator > & set (size_type pos, bool value=true)
 Set the bit at the position pos to true or value value.
 
constexpr dynamic_bitset< Block, Allocator > & set ()
 Set all the bits of the sul::dynamic_bitset to true.
 
constexpr dynamic_bitset< Block, Allocator > & reset (size_type pos, size_type len)
 Reset the bits of the range [pos, pos + len[ to false.
 
constexpr dynamic_bitset< Block, Allocator > & reset (size_type pos)
 Reset the bit at the position pos to false.
 
constexpr dynamic_bitset< Block, Allocator > & reset ()
 Reset all the bits of the sul::dynamic_bitset to false.
 
constexpr dynamic_bitset< Block, Allocator > & flip (size_type pos, size_type len)
 Flip the bits of the range [pos, pos + len[.
 
constexpr dynamic_bitset< Block, Allocator > & flip (size_type pos)
 Flip the bit at the position pos.
 
constexpr dynamic_bitset< Block, Allocator > & flip ()
 Flip all the bits of the sul::dynamic_bitset.
 
constexpr bool test (size_type pos) const
 Test the value of the bit at position pos.
 
constexpr bool test_set (size_type pos, bool value=true)
 Test the value of the bit at position pos and set it to true or value value.
 
constexpr bool all () const
 Checks if all bits are set to true.
 
constexpr bool any () const
 Checks if any bits are set to true.
 
constexpr bool none () const
 Checks if none of the bits are set to true.
 
constexpr size_type count () const noexcept
 Count the number of bits set to true.
 
constexpr reference operator[] (size_type pos)
 Accesses the bit at position pos.
 
constexpr const_reference operator[] (size_type pos) const
 Accesses the bit at position pos.
 
constexpr size_type size () const noexcept
 Give the number of bits of the sul::dynamic_bitset.
 
constexpr size_type num_blocks () const noexcept
 Give the number of blocks used by the sul::dynamic_bitset.
 
constexpr bool empty () const noexcept
 Checks if the sul::dynamic_bitset is empty.
 
constexpr size_type capacity () const noexcept
 Give the number of bits that the sul::dynamic_bitset has currently allocated space for.
 
constexpr void reserve (size_type num_bits)
 Increase the capacity of the sul::dynamic_bitset to a value that's greater or equal to num_bits.
 
constexpr void shrink_to_fit ()
 Requests the removal of unused capacity.
 
constexpr bool is_subset_of (const dynamic_bitset< Block, Allocator > &bitset) const
 Determines if this sul::dynamic_bitset is a subset of bitset.
 
constexpr bool is_proper_subset_of (const dynamic_bitset< Block, Allocator > &bitset) const
 Determines if this sul::dynamic_bitset is a proper subset of bitset.
 
constexpr bool intersects (const dynamic_bitset< Block, Allocator > &bitset) const
 Determines if this sul::dynamic_bitset and bitset intersect.
 
constexpr size_type find_first () const
 Find the position of the first bit set in the sul::dynamic_bitset starting from the least-significant bit.
 
constexpr size_type find_next (size_type prev) const
 Find the position of the first bit set in the range [prev + 1, size()[ of the sul::dynamic_bitset starting from the position prev + 1.
 
constexpr void swap (dynamic_bitset< Block, Allocator > &other) noexcept(noexcept(std::swap(m_blocks, other.m_blocks)))
 Exchanges the bits of this sul::dynamic_bitset with those of other.
 
constexpr allocator_type get_allocator () const
 Gets the associated allocator.
 
template<typename _CharT = char, typename _Traits = std::char_traits<_CharT>, typename _Alloc = std::allocator<_CharT>>
constexpr std::basic_string< _CharT, _Traits, _Alloc > to_string (_CharT zero=_CharT('0'), _CharT one=_CharT('1')) const
 Generate a string representation of the sul::dynamic_bitset.
 
constexpr unsigned long to_ulong () const
 Converts the contents of the bitset to an unsigned long integer.
 
constexpr unsigned long long to_ullong () const
 Converts the contents of the bitset to an unsigned long long integer.
 
template<typename Function , typename... Parameters>
constexpr void iterate_bits_on (Function &&function, Parameters &&... parameters) const
 Iterate on the sul::dynamic_bitset and call function with the position of the bits on.
 
constexpr block_typedata () noexcept
 Return a pointer to the underlying array serving as blocks storage.
 
constexpr const block_typedata () const noexcept
 Return a pointer to the underlying array serving as blocks storage.
 

Static Public Attributes

static constexpr size_type bits_per_block = std::numeric_limits<block_type>::digits
 Number of bits that can be stored in a block.
 
static constexpr size_type npos = std::numeric_limits<size_type>::max()
 Maximum value of size_type, returned for invalid positions.
 

Friends

template<typename Block_ , typename Allocator_ >
constexpr bool operator== (const dynamic_bitset< Block_, Allocator_ > &lhs, const dynamic_bitset< Block_, Allocator_ > &rhs)
 Test if two sul::dynamic_bitset have the same content.
 
template<typename Block_ , typename Allocator_ >
constexpr bool operator< (const dynamic_bitset< Block_, Allocator_ > &lhs, const dynamic_bitset< Block_, Allocator_ > &rhs)
 Test if lhs is "less than" rhs. The comparison of the two dynamic_bitset is first on numbers their content represent and then on their size.
 

Related Symbols

(Note that these are not member symbols.)

template<typename Block , typename Allocator >
constexpr bool operator!= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if two sul::dynamic_bitset content are different.
 
template<typename Block , typename Allocator >
constexpr bool operator<= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "less than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr bool operator> (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "greater than" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr bool operator>= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "greater than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocator > operator& (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary AND on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocator > operator| (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary OR on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocator > operator^ (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary XOR on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocator > operator- (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary difference between bits of lhs and rhs.
 
template<typename _CharT , typename _Traits , typename Block , typename Allocator >
constexpr std::basic_ostream< _CharT, _Traits > & operator<< (std::basic_ostream< _CharT, _Traits > &os, const dynamic_bitset< Block, Allocator > &bitset)
 Insert a string representation of this sul::dynamic_bitset to a character stream.
 
template<typename _CharT , typename _Traits , typename Block , typename Allocator >
constexpr std::basic_istream< _CharT, _Traits > & operator>> (std::basic_istream< _CharT, _Traits > &is, dynamic_bitset< Block, Allocator > &bitset)
 Extract a sul::dynamic_bitset from a character stream using its string representation.
 
template<typename Block , typename Allocator >
constexpr void swap (dynamic_bitset< Block, Allocator > &bitset1, dynamic_bitset< Block, Allocator > &bitset2) noexcept(noexcept(bitset1.swap(bitset2)))
 Exchange the content of bitset1 and bitset2.
 

Detailed Description

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
class sul::dynamic_bitset< Block, Allocator >

Dynamic bitset.

Data structure used to store a vector of bits and apply binary operations to it. The bits are stored in an optimized way in an underling block type. It is highly inspired by std::bitset but with a run-time changeable size.

Preconditions are checked with assert but no exception will be thrown if one is violated (as with std::bitset).

Remarks
It is not a Container as it does not provide iterators because of the reference proxy class used to access the bits.
Template Parameters
BlockBlock type to use for storing the bits, must be an unsigned integral type
AllocatorAllocator type to use for memory management, must meet the standard requirements of Allocator
Since
1.0.0

Member Typedef Documentation

◆ allocator_type

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
Allocator sul::dynamic_bitset< Block, Allocator >::allocator_type

Same type as Allocator.

Since
1.0.0

◆ block_type

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
Block sul::dynamic_bitset< Block, Allocator >::block_type

Same type as Block.

Since
1.0.0

◆ const_reference

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
bool sul::dynamic_bitset< Block, Allocator >::const_reference

Const reference to a sul::dynamic_bitset bit, type bool.

Since
1.0.0

◆ size_type

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
size_t sul::dynamic_bitset< Block, Allocator >::size_type

Type used to represent the size of a sul::dynamic_bitset.

Since
1.0.0

Constructor & Destructor Documentation

◆ dynamic_bitset() [1/8]

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( const dynamic_bitset< Block, Allocator > & other)
constexprdefault

Copy constructor.

Since
1.0.0

◆ dynamic_bitset() [2/8]

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( dynamic_bitset< Block, Allocator > && other)
constexprdefaultnoexcept

Move constructor.

Since
1.0.0

◆ dynamic_bitset() [3/8]

template<typename Block , typename Allocator >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( const allocator_type & allocator = allocator_type())
explicitconstexpr

Constructs an empty sul::dynamic_bitset.

A copy of allocator will be used for memory management.

Parameters
[in]allocatorAllocator to use for memory management
Complexity
Constant.
Since
1.0.0

◆ dynamic_bitset() [4/8]

template<typename Block , typename Allocator >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( size_type nbits,
unsigned long long init_val = 0,
const allocator_type & allocator = allocator_type() )
explicitconstexpr

Constructs a sul::dynamic_bitset of nbits bits from an initial value.

The first bits are initialized with the bits from init_val, if nbits > std::numeric_limits<unsigned long long>::digits , all other bits are initialized to false. A copy of allocator will be used for memory management.

Parameters
[in]nbitsNumber of bits of the sul::dynamic_bitset
[in]init_valValue to initialize the sul::dynamic_bitset with
[in]allocatorAllocator to use for memory management
Complexity
Linear in nbits / bits_per_block.
Since
1.0.0

◆ dynamic_bitset() [5/8]

template<typename Block , typename Allocator >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( std::initializer_list< block_type > init_vals,
const allocator_type & allocator = allocator_type() )
constexpr

Constructs a sul::dynamic_bitset using init_vals to initialize the first blocks.

The size of the newly created sul::dynamic_bitset is init_vals.size() * bits_per_block. A copy of allocator will be used for memory management.

Parameters
[in]init_valsValue of the sul::dynamic_bitset first blocks
[in]allocatorAllocator to use for memory management
Complexity
Linear in init_vals.size().
Since
1.0.0

◆ dynamic_bitset() [6/8]

template<typename Block , typename Allocator >
template<typename _CharT , typename _Traits >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( std::basic_string_view< _CharT, _Traits > str,
typename std::basic_string_view< _CharT, _Traits >::size_type pos = 0,
typename std::basic_string_view< _CharT, _Traits >::size_type n = std::basic_string_view<_CharT, _Traits>::npos,
_CharT zero = _CharT('0'),
_CharT one = _CharT('1'),
const allocator_type & allocator = allocator_type() )
explicitconstexpr

Constructs a sul::dynamic_bitset from a string or a part of a string.

Construct the sul::dynamic_bitset using the characters from str in the range [pos, std::min(pos + n, str.size())[.

Parameters
[in]strString containing the part to use
[in]posStarting position of the string part to use in str
[in]nNumber of characters of str to use from the starting position
[in]zeroCharacter used to represent false bits in str
[in]oneCharacter used to represent true bits in str
[in]allocatorAllocator to use for memory management
Template Parameters
_CharTCharacter type of the string
_TraitsTraits class specifying the operations on the character type of the string
Precondition
pos < str.size()
Complexity
Linear in std::min(n, str.size() - pos).
Since
1.0.0

◆ dynamic_bitset() [7/8]

template<typename Block , typename Allocator >
template<typename _CharT , typename _Traits , typename _Alloc >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( const std::basic_string< _CharT, _Traits, _Alloc > & str,
typename std::basic_string< _CharT, _Traits, _Alloc >::size_type pos = 0,
typename std::basic_string< _CharT, _Traits, _Alloc >::size_type n = std::basic_string<_CharT, _Traits, _Alloc>::npos,
_CharT zero = _CharT('0'),
_CharT one = _CharT('1'),
const allocator_type & allocator = allocator_type() )
explicitconstexpr

Constructs a sul::dynamic_bitset from a string or a part of a string.

Construct the sul::dynamic_bitset using the characters from str in the range [pos, std::min(pos + n, str.size())[.

Parameters
[in]strString containing the part to use
[in]posStarting position of the string part to use in str
[in]nNumber of characters of str to use from the starting position
[in]zeroCharacter used to represent false bits in str
[in]oneCharacter used to represent true bits in str
[in]allocatorAllocator to use for memory management
Template Parameters
_CharTCharacter type of the string
_TraitsTraits class specifying the operations on the character type of the string
_AllocAllocator type used to allocate internal storage of the string
Precondition
pos < str.size()
Complexity
Linear in std::min(n, str.size() - pos).
Since
1.0.0

◆ dynamic_bitset() [8/8]

template<typename Block , typename Allocator >
template<typename _CharT , typename _Traits >
sul::dynamic_bitset< Block, Allocator >::dynamic_bitset ( const _CharT * str,
typename std::basic_string< _CharT >::size_type pos = 0,
typename std::basic_string< _CharT >::size_type n = std::basic_string<_CharT>::npos,
_CharT zero = _CharT('0'),
_CharT one = _CharT('1'),
const allocator_type & allocator = allocator_type() )
explicitconstexpr

Constructs a sul::dynamic_bitset from a string or a part of a string.

Construct the sul::dynamic_bitset using the characters from str in the range [pos, std::min(pos + n, _Traits::length(str))[.

Parameters
[in]strString containing the part to use
[in]posStarting position of the string part to use
[in]nNumber of characters to use from the starting position
[in]zeroCharacter used to represent false bits in the string
[in]oneCharacter used to represent 1 true bitsn the string
[in]allocatorAllocator to use for memory management
Template Parameters
_CharTCharacter type of the string
_TraitsTraits class specifying the operations on the character type of the string
Precondition
pos < _Traits::length(str)
Complexity
Linear in std::min(n, _Traits::length(str) - pos).
Since
1.0.0

◆ ~dynamic_bitset()

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
sul::dynamic_bitset< Block, Allocator >::~dynamic_bitset ( )
defaultnoexcept

Destructor.

Since
1.0.0

Member Function Documentation

◆ all()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::all ( ) const
nodiscardconstexpr

Checks if all bits are set to true.

Returns
true if all bits are set to true, otherwise false
Remarks
Return true if the sul::dynamic_bitset is empty, the logic is that you are checking if all bits are set to true, meaning none of them is set to false, and in an empty sul::dynamic_bitset no bits are set to false.
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ any()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::any ( ) const
nodiscardconstexpr

Checks if any bits are set to true.

Returns
true if any of the bits is set to true, otherwise false
Remarks
Return false if the sul::dynamic_bitset is empty, the logic is you are checking if there is at least one bit set to true and in an empty dynamic_bitset there is no bit set to true.
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ append() [1/3]

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::append ( block_type block)
constexpr

Append a block of bits block at the end of the sul::dynamic_bitset.

Increase the size of the sul::dynamic_bitset by bits_per_block.

Parameters
[in]blockBlock of bits to add
Complexity
Amortized constant.
Since
1.0.0

◆ append() [2/3]

template<typename Block , typename Allocator >
template<typename BlockInputIterator >
void sul::dynamic_bitset< Block, Allocator >::append ( BlockInputIterator first,
BlockInputIterator last )
constexpr

Append blocks of bits from the range [first, last[ at the end of the dynamic_bitset.

Parameters
[in]firstFirst iterator of the range
[in]lastLast iterator of the range (after the last element to add)
Template Parameters
BlockInputIteratorType of the range iterators
Complexity
Linear in the size of the range. Additional complexity possible due to reallocation if capacity is less than size() + std::distance(first, last) * bits_per_block.
Since
1.0.0

◆ append() [3/3]

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::append ( std::initializer_list< block_type > blocks)
constexpr

Append blocks of bits from blocks at the end of the sul::dynamic_bitset.

Parameters
[in]blocksBlocks of bits to add
Complexity
Linear in the size of blocks. Additional complexity possible due to reallocation if capacity is less than size() + blocks.size() * bits_per_block.
Since
1.0.0

◆ capacity()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::capacity ( ) const
nodiscardconstexprnoexcept

Give the number of bits that the sul::dynamic_bitset has currently allocated space for.

Returns
Capacity of the currently allocated storage.
Complexity
Constant.
Since
1.0.0

◆ clear()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::clear ( )
constexpr

Clears the sul::dynamic_bitset, resize it to 0.

Equivalent to:

this.resize(0);
constexpr void resize(size_type nbits, bool value=false)
Resize the sul::dynamic_bitset to contain nbits bits.
Definition dynamic_bitset.hpp:2249
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ count()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::count ( ) const
nodiscardconstexprnoexcept

Count the number of bits set to true.

Return 0 if the sul::dynamic_bitset is empty.

Returns
The number of bits that are set to true
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ data() [1/2]

template<typename Block , typename Allocator >
const dynamic_bitset< Block, Allocator >::block_type * sul::dynamic_bitset< Block, Allocator >::data ( ) const
nodiscardconstexprnoexcept

Return a pointer to the underlying array serving as blocks storage.

The pointer is such that range [data(); data() + num_blocks()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

Postcondition
The bits past the end of the sul::dynamic_bitset in the last block are guaranteed to be 0s, example:
// random bitset of size 11
std::minstd_rand rand(std::random_device{}());
std::bernoulli_distribution dist;
for(size_t i = 0; i < 11; ++i)
{
bitset.push_back(dist(rand));
}
// the bitset use 2 blocks of 8 bits
// check that unused bits are set to 0
assert(*(bitset.data() + 1) >> 3 == 0);
Dynamic bitset.
Definition dynamic_bitset.hpp:171
constexpr void push_back(bool value)
Add a new bit with the value value at the end of the sul::dynamic_bitset.
Definition dynamic_bitset.hpp:2288
constexpr block_type * data() noexcept
Return a pointer to the underlying array serving as blocks storage.
Definition dynamic_bitset.hpp:3050
Remarks
If the sul::dynamic_bitset is empty, this function may or may not return a null pointer.
Returns
A pointer to the underlying array serving as blocks storage
Complexity
Constant.
Since
1.2.0

◆ data() [2/2]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::block_type * sul::dynamic_bitset< Block, Allocator >::data ( )
nodiscardconstexprnoexcept

Return a pointer to the underlying array serving as blocks storage.

The pointer is such that range [data(); data() + num_blocks()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

Postcondition
The bits past the end of the sul::dynamic_bitset in the last block are guaranteed to be 0s, example:
// random bitset of size 11
std::minstd_rand rand(std::random_device{}());
std::bernoulli_distribution dist;
for(size_t i = 0; i < 11; ++i)
{
bitset.push_back(dist(rand));
}
// the bitset use 2 blocks of 8 bits
// check that unused bits are set to 0
assert(*(bitset.data() + 1) >> 3 == 0);
Remarks
If the sul::dynamic_bitset is empty, this function may or may not return a null pointer.
Returns
A pointer to the underlying array serving as blocks storage
Complexity
Constant.
Since
1.2.0

◆ empty()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::empty ( ) const
nodiscardconstexprnoexcept

Checks if the sul::dynamic_bitset is empty.

Equivalent to:

size() == 0;
constexpr size_type size() const noexcept
Give the number of bits of the sul::dynamic_bitset.
Definition dynamic_bitset.hpp:2786
Returns
true if the sul::dynamic_bitset is empty, false otherwise
Complexity
Constant.
Since
1.0.0

◆ find_first()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::find_first ( ) const
nodiscardconstexpr

Find the position of the first bit set in the sul::dynamic_bitset starting from the least-significant bit.

Give the lowest index of the sul::dynamic_bitset with a bit set, or npos if no bits are set.

Returns
The position of the first bit set, or npos if no bits are set
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ find_next()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::find_next ( size_type prev) const
nodiscardconstexpr

Find the position of the first bit set in the range [prev + 1, size()[ of the sul::dynamic_bitset starting from the position prev + 1.

Give the lowest index superior to prev of the sul::dynamic_bitset with a bit set, or npos if no bits are set after the index prev.
If prev + 1 >= size(), return npos.

Parameters
[in]prevPosition of the bit preceding the search range
Returns
The position of the first bit set after prev, or npos if no bits are set after prev
Complexity
Linear in size() - prev.
Since
1.0.0

◆ flip() [1/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::flip ( )
constexpr

Flip all the bits of the sul::dynamic_bitset.

Returns
A reference to the sul::dynamic_bitset *this
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ flip() [2/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::flip ( size_type pos)
constexpr

Flip the bit at the position pos.

Parameters
[in]posPosition of the bit to reset
Returns
A reference to the sul::dynamic_bitset *this
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ flip() [3/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::flip ( size_type pos,
size_type len )
constexpr

Flip the bits of the range [pos, pos + len[.

Parameters
[in]posPosition of the first bit of the range
[in]lenLength of the range
Returns
A reference to the sul::dynamic_bitset *this
Precondition
(pos < size()) && ((len == 0) || (pos + len - 1 < size()))
Complexity
Linear in len.
Since
1.0.0

◆ get_allocator()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::allocator_type sul::dynamic_bitset< Block, Allocator >::get_allocator ( ) const
nodiscardconstexpr

Gets the associated allocator.

Returns
The associated allocator.
Complexity
Constant.
Since
1.0.0

◆ intersects()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::intersects ( const dynamic_bitset< Block, Allocator > & bitset) const
nodiscardconstexpr

Determines if this sul::dynamic_bitset and bitset intersect.

This sul::dynamic_bitset intersects with bitset if for at least one bit set in this sul::dynamic_bitset, the corresponding bit in bitset a is also set. In other words two bitsets intersect if they have at least one bit set in common.

Less efficient but equivalent way to get this result:

res = (this & bitset).any();
constexpr bool any() const
Checks if any bits are set to true.
Definition dynamic_bitset.hpp:2716
Parameters
[in]bitsetThe sul::dynamic_bitset for which to check if this sul::dynamic_bitset intersects
Returns
true if this sul::dynamic_bitset intersects with bitset, false otherwise
Precondition
size() == bitset.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ is_proper_subset_of()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::is_proper_subset_of ( const dynamic_bitset< Block, Allocator > & bitset) const
nodiscardconstexpr

Determines if this sul::dynamic_bitset is a proper subset of bitset.

This sul::dynamic_bitset is a proper subset of bitset if, for every bit that is set in this sul::dynamic_bitset, the corresponding bit in bitset a is also set and if this sul::dynamic_bitset is different from bitset.

Less efficient but equivalent way to get this result:

res = ((this != bitset) && (this & ~bitset).none());
Parameters
[in]bitsetThe sul::dynamic_bitset for which to check if this sul::dynamic_bitset is a proper subset
Returns
true if this sul::dynamic_bitset is a proper subset of bitset, false otherwise
Remarks
The relation "is a proper subset of" is asymmetric (A being a proper subset of B imply that B is not a proper subset of A).
Precondition
size() == bitset.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ is_subset_of()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::is_subset_of ( const dynamic_bitset< Block, Allocator > & bitset) const
nodiscardconstexpr

Determines if this sul::dynamic_bitset is a subset of bitset.

This sul::dynamic_bitset is a subset of bitset if, for every bit that is set in this sul::dynamic_bitset, the corresponding bit in bitset a is also set.

Less efficient but equivalent way to get this result:

res = (this & ~bitset).none();
constexpr bool none() const
Checks if none of the bits are set to true.
Definition dynamic_bitset.hpp:2729
Parameters
[in]bitsetThe sul::dynamic_bitset for which to check if this sul::dynamic_bitset is a subset
Returns
true if this sul::dynamic_bitset is a subset of bitset, false otherwise
Remarks
The relation "is a subset of" is not symmetric (A being a subset of B doesn't imply that B is a subset of A) but is antisymmetric (if A is a subset of B and B is a subset of A, then A == B).
Precondition
size() == bitset.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ iterate_bits_on()

template<typename Block , typename Allocator >
template<typename Function , typename... Parameters>
void sul::dynamic_bitset< Block, Allocator >::iterate_bits_on ( Function && function,
Parameters &&... parameters ) const
constexpr

Iterate on the sul::dynamic_bitset and call function with the position of the bits on.

For each set bit, function is called as follow:

std::invoke(std::forward<Function>(function), bit_pos, std::forward<Parameters>(parameters)...))

where bit_pos is the position of the current bit on. Thus function should take a size_t for the current set bit position as first argument, also parameters can be used to pass additional arguments to function when it is called by this method.

function can return nothing or a bool, if it return a bool, the return value indicate if the iteration should continue, true to continue the iteration, false to stop, this make it easy to do an early exit.

Parameters
functionFunction to call on all bits on, take the current bit position as first argument and parameters as next arguments
parametersExtra parameters for function
Template Parameters
FunctionType of function, must take a size_t as first argument and Parameters as next arguments
ParametersType of parameters
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ none()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::none ( ) const
nodiscardconstexpr

Checks if none of the bits are set to true.

Returns
true if none of the bits is set to true, otherwise false
Remarks
Return true if the sul::dynamic_bitset is empty, the logic is that you are checking if there is no bit set to true and in an empty sul::dynamic_bitset there is no bit that can be set to true.
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ num_blocks()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::num_blocks ( ) const
nodiscardconstexprnoexcept

Give the number of blocks used by the sul::dynamic_bitset.

Returns
The number of blocks used by the sul::dynamic_bitset
Complexity
Constant.
Since
1.0.0

◆ operator&=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator&= ( const dynamic_bitset< Block, Allocator > & rhs)
constexpr

Sets the bits to the result of binary AND on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsRight hand side sul::dynamic_bitset of the operator
Returns
A reference to the sul::dynamic_bitset *this
Precondition
size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator-=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator-= ( const dynamic_bitset< Block, Allocator > & rhs)
constexpr

Sets the bits to the result of the binary difference between the bits of *this and rhs.

Less efficient but equivalent way to get this result:

this &= ~rhs;
Parameters
[in]rhsRight hand side sul::dynamic_bitset of the operator
Returns
A reference to the sul::dynamic_bitset *this
Precondition
size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<<()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > sul::dynamic_bitset< Block, Allocator >::operator<< ( size_type shift) const
nodiscardconstexpr

Performs binary shift right of shift bits.

Zeroes are shifted in. Does nothing if shift == 0.
Equivalent to:

bitset <<= shift;
Parameters
[in]shiftNumber of positions to shift the bits
Returns
A new sul::dynamic_bitset containing the shifted bits
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<<=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator<<= ( size_type shift)
constexpr

Performs binary shift left of shift bits.

Zeroes are shifted in, does nothing if shift == 0.

Parameters
[in]shiftNumber of positions to shift the bits
Returns
A reference to the sul::dynamic_bitset *this
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator=() [1/2]

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator= ( const dynamic_bitset< Block, Allocator > & other)
constexprdefault

Copy assignment operator.

Since
1.0.0

◆ operator=() [2/2]

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator= ( dynamic_bitset< Block, Allocator > && other)
constexprdefaultnoexcept

Move assignment operator.

Since
1.0.0

◆ operator>>()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > sul::dynamic_bitset< Block, Allocator >::operator>> ( size_type shift) const
nodiscardconstexpr

Performs binary shift left of shift bits.

Zeroes are shifted in. Does nothing if shift == 0.
Equivalent to:

bitset >>= shift;
Parameters
[in]shiftNumber of positions to shift the bits
Returns
A new sul::dynamic_bitset containing the shifted bits
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>>=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator>>= ( size_type shift)
constexpr

Performs binary shift right of shift bits.

Zeroes are shifted in, does nothing if shift == 0.

Parameters
[in]shiftNumber of positions to shift the bits
Returns
A reference to the sul::dynamic_bitset *this
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator[]() [1/2]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::reference sul::dynamic_bitset< Block, Allocator >::operator[] ( size_type pos)
nodiscardconstexpr

Accesses the bit at position pos.

Parameters
[in]posPosition of the bit to access
Returns
A reference object which allows writing to the requested bit
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ operator[]() [2/2]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::const_reference sul::dynamic_bitset< Block, Allocator >::operator[] ( size_type pos) const
nodiscardconstexpr

Accesses the bit at position pos.

Parameters
[in]posPosition of the bit to access
Returns
The value of the requested bit
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ operator^=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator^= ( const dynamic_bitset< Block, Allocator > & rhs)
constexpr

Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsRight hand side sul::dynamic_bitset of the operator
Returns
A reference to the sul::dynamic_bitset *this
Precondition
size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator|=()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::operator|= ( const dynamic_bitset< Block, Allocator > & rhs)
constexpr

Sets the bits to the result of binary OR on corresponding pairs of bits of *this and rhs.

Parameters
[in]rhsRight hand side sul::dynamic_bitset of the operator
Returns
A reference to the sul::dynamic_bitset *this
Precondition
size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator~()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > sul::dynamic_bitset< Block, Allocator >::operator~ ( ) const
nodiscardconstexpr

Performs a unary NOT on all bits.

Equivalent to:

bitset.flip();
Returns
A copy of *this with all bits flipped
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ pop_back()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::pop_back ( )
constexpr

Remove the last bit of the sul::dynamic_bitset.

Decrease the size of the sul::dynamic_bitset by one, does nothing if the dynamic_bitset is empty.

Complexity
Constant.
Since
1.0.0

◆ push_back()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::push_back ( bool value)
constexpr

Add a new bit with the value value at the end of the sul::dynamic_bitset.

Increase the size of the bitset by one, the added bit becomes the most-significant bit.

Parameters
[in]valueValue of the bit to add
Complexity
Amortized constant.
Since
1.0.0

◆ reserve()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::reserve ( size_type num_bits)
constexpr

Increase the capacity of the sul::dynamic_bitset to a value that's greater or equal to num_bits.

If num_bits is greater than the current capacity, new storage is allocated and all reference on bits of the sul::dynamic_bitset are invalidated, otherwise the method does nothing.

Parameters
[in]num_bitsNew capacity of the sul::dynamic_bitset
Complexity
At most linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ reset() [1/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::reset ( )
constexpr

Reset all the bits of the sul::dynamic_bitset to false.

Returns
A reference to the sul::dynamic_bitset *this
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ reset() [2/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::reset ( size_type pos)
constexpr

Reset the bit at the position pos to false.

Parameters
[in]posPosition of the bit to reset
Returns
A reference to the sul::dynamic_bitset *this
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ reset() [3/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::reset ( size_type pos,
size_type len )
constexpr

Reset the bits of the range [pos, pos + len[ to false.

Parameters
[in]posPosition of the first bit of the range
[in]lenLength of the range
Returns
A reference to the sul::dynamic_bitset *this
Precondition
(pos < size()) && ((len == 0) || (pos + len - 1 < size()))
Complexity
Linear in len.
Since
1.0.0

◆ resize()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::resize ( size_type nbits,
bool value = false )
constexpr

Resize the sul::dynamic_bitset to contain nbits bits.

Bits keep the value they had before the resize and, if nbits is greater than the current size, new bit are initialized to value.

Parameters
[in]nbitsNew size of the sul::dynamic_bitset
[in]valueValue of the new bits
Complexity
Linear in the difference between the current size and nbits. Additional complexity possible due to reallocation if capacity is less than nbits.
Since
1.0.0

◆ set() [1/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::set ( )
constexpr

Set all the bits of the sul::dynamic_bitset to true.

Returns
A reference to the sul::dynamic_bitset *this
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ set() [2/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::set ( size_type pos,
bool value = true )
constexpr

Set the bit at the position pos to true or value value.

Parameters
[in]posPosition of the bit to set
[in]valueValue to set the bit to
Returns
A reference to the sul::dynamic_bitset *this
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ set() [3/3]

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > & sul::dynamic_bitset< Block, Allocator >::set ( size_type pos,
size_type len,
bool value )
constexpr

Set the bits of the range [pos, pos + len[ to value value.

Does nothing if len == 0.

Parameters
[in]posPosition of the first bit of the range
[in]lenLength of the range
[in]valueValue to set the bits to
Returns
A reference to the sul::dynamic_bitset *this
Precondition
(pos < size()) && ((len == 0) || (pos + len - 1 < size()))
Complexity
Linear in len.
Since
1.0.0

◆ shrink_to_fit()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::shrink_to_fit ( )
constexpr

Requests the removal of unused capacity.

It is a non-binding request to reduce the capacity to the size. It depends on the implementation of std::vector whether the request is fulfilled.
If reallocation occurs, all reference on bits of the sul::dynamic_bitset are invalidated.

Complexity
At most linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ size()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator >::size_type sul::dynamic_bitset< Block, Allocator >::size ( ) const
nodiscardconstexprnoexcept

Give the number of bits of the sul::dynamic_bitset.

Returns
The number of bits of the sul::dynamic_bitset
Complexity
Constant.
Since
1.0.0

◆ swap()

template<typename Block , typename Allocator >
void sul::dynamic_bitset< Block, Allocator >::swap ( dynamic_bitset< Block, Allocator > & other)
constexprnoexcept

Exchanges the bits of this sul::dynamic_bitset with those of other.

All reference on bits of the sul::dynamic_bitset are invalidated.

Parameters
othersul::dynamic_bitset to exchange bits with
Complexity
Constant.
Since
1.0.0

◆ test()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::test ( size_type pos) const
nodiscardconstexpr

Test the value of the bit at position pos.

Parameters
[in]posPosition of the bit to test
Returns
The tested bit value
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ test_set()

template<typename Block , typename Allocator >
bool sul::dynamic_bitset< Block, Allocator >::test_set ( size_type pos,
bool value = true )
nodiscardconstexpr

Test the value of the bit at position pos and set it to true or value value.

Parameters
[in]posPosition of the bit to test and set
[in]valueValue to set the bit to
Returns
The tested bit value
Precondition
pos < size()
Complexity
Constant.
Since
1.0.0

◆ to_string()

template<typename Block , typename Allocator >
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc > sul::dynamic_bitset< Block, Allocator >::to_string ( _CharT zero = _CharT('0'),
_CharT one = _CharT('1') ) const
nodiscardconstexpr

Generate a string representation of the sul::dynamic_bitset.

Uses zero to represent bits with value of false and one to represent bits with value of true. The resulting string contains size() characters with the first character corresponds to the last (size() - 1th) bit and the last character corresponding to the first bit.

Parameters
[in]zeroCharacter to use to represent false
[in]oneCharacter to use to represent true
Template Parameters
_CharTCharacter type of the string
_TraitsTraits class specifying the operations on the character type of the string
_AllocAllocator type used to allocate internal storage of the string
Returns
The string representing the sul::dynamic_bitset content
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ to_ullong()

template<typename Block , typename Allocator >
unsigned long long sul::dynamic_bitset< Block, Allocator >::to_ullong ( ) const
nodiscardconstexpr

Converts the contents of the bitset to an unsigned long long integer.

The first bit of the bitset corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit.

Returns
The numeric value corresponding to the bitset contents.
Exceptions
std::overflow_errorif the value is too large to be represented in an unsigned long long
Complexity
Constant.
Since
1.3.0

◆ to_ulong()

template<typename Block , typename Allocator >
unsigned long sul::dynamic_bitset< Block, Allocator >::to_ulong ( ) const
nodiscardconstexpr

Converts the contents of the bitset to an unsigned long integer.

The first bit of the bitset corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit.

Returns
The numeric value corresponding to the bitset contents.
Exceptions
std::overflow_errorif the value is too large to be represented in an unsigned long
Complexity
Constant.
Since
1.3.0

Friends And Related Symbol Documentation

◆ operator!=()

template<typename Block , typename Allocator >
bool operator!= ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Test if two sul::dynamic_bitset content are different.

Defined as:

return !(lhs == rhs);

see sul::dynamic_bitset::operator==() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if they does not contain the same bits, false otherwise
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator&()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > operator& ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Performs binary AND on corresponding pairs of bits of lhs and rhs.

Defined as:

return result &= rhs;

see sul::dynamic_bitset::operator&=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary AND between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator-()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > operator- ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Performs binary difference between bits of lhs and rhs.

Defined as:

return result -= rhs;

see sul::dynamic_bitset::operator-=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of the binary difference between the corresponding bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
template<typename Block_ , typename Allocator_ >
bool operator< ( const dynamic_bitset< Block_, Allocator_ > & lhs,
const dynamic_bitset< Block_, Allocator_ > & rhs )
friend

Test if lhs is "less than" rhs. The comparison of the two dynamic_bitset is first on numbers their content represent and then on their size.

The size comparison is necessary for the comparison operators to keep their properties. For example without the size comparison the "<=" operator (defined for "A <= B" by "!(B < A)") would no longer be antisymmetric (if A <= B and B <= A, then A == B) because operator==() compare the sul::dynamic_bitset as a container and not a number. For example with bitsets A(0011) and B(011), without the size comparison B < A would be false, A <= B would be true, B <= A would be true, but A == B would be false, breaking the antisymmetric property of the operator. Thus, to respect the properties of the operators, the size is used as a secondary criteria for the comparison of sul::dynamic_bitset which content represent the same number. Therefore, for the previous example with bitsets A(0011) and B(011), B < A is true, A <= B is false, B <= A is true and A == B is false.

If comparing bitsets A and B with the content of A representing the number a, and the content of B representing the number b, this operator would work as follow:

if(a == b)
{
return A.size() < B.size();
}
else
{
return a < b;
}
Remarks
The empty sul::dynamic_bitset is the "lowest" of all bitset and for 0-only bitsets comparison, the shortest is the lowest.
Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
Block_Block type used by lhs and rhs for storing the bits
Allocator_Allocator type used by lhs and rhs for memory management
Returns
true if lhs is "less than" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<<()

template<typename _CharT , typename _Traits , typename Block , typename Allocator >
std::basic_ostream< _CharT, _Traits > & operator<< ( std::basic_ostream< _CharT, _Traits > & os,
const dynamic_bitset< Block, Allocator > & bitset )
related

Insert a string representation of this sul::dynamic_bitset to a character stream.

The string representation written is the same as if generated with sul::dynamic_bitset::to_string() with default parameter, using '1' for true bits and '0' for false bits.

Parameters
osCharacter stream to write to
[in]bitsetsul::dynamic_bitset to write
Template Parameters
_CharTCharacter type of the character stream
_TraitsTraits class specifying the operations on the character type of the character stream
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Returns
os
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<=()

template<typename Block , typename Allocator >
bool operator<= ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Test if lhs is "less than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return !(rhs < lhs);

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "less than or equal to" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator==

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
template<typename Block_ , typename Allocator_ >
bool operator== ( const dynamic_bitset< Block_, Allocator_ > & lhs,
const dynamic_bitset< Block_, Allocator_ > & rhs )
friend

Test if two sul::dynamic_bitset have the same content.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
Block_Block type used by lhs and rhs for storing the bits
Allocator_Allocator type used by lhs and rhs for memory management
Returns
true if they contain the same bits, false otherwise
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>()

template<typename Block , typename Allocator >
bool operator> ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Test if lhs is "greater than" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return rhs < lhs;

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "greater than" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>=()

template<typename Block , typename Allocator >
bool operator>= ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Test if lhs is "greater than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return !(lhs < rhs);

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "greater than or equal to" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>>()

template<typename _CharT , typename _Traits , typename Block , typename Allocator >
std::basic_istream< _CharT, _Traits > & operator>> ( std::basic_istream< _CharT, _Traits > & is,
dynamic_bitset< Block, Allocator > & bitset )
related

Extract a sul::dynamic_bitset from a character stream using its string representation.

The string representation expected is the same as if generated with sul::dynamic_bitset::to_string() with default parameter, using '1' for true bits and '0' for false bits. On success the content of bitset is cleared before writing to it. The extraction starts by skipping leading whitespace then take the characters one by one and stop if is.good() return false or the next character is neither _CharT('0') nor _CharT('1').

Parameters
isCharacter stream to read from
bitsetsul::dynamic_bitset to write to
Template Parameters
_CharTCharacter type of the character stream
_TraitsTraits class specifying the operations on the character type of the character stream
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Returns
is
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator^()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > operator^ ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Performs binary XOR on corresponding pairs of bits of lhs and rhs.

Defined as:

return result ^= rhs;

see sul::dynamic_bitset::operator^=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary XOR between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator|()

template<typename Block , typename Allocator >
dynamic_bitset< Block, Allocator > operator| ( const dynamic_bitset< Block, Allocator > & lhs,
const dynamic_bitset< Block, Allocator > & rhs )
related

Performs binary OR on corresponding pairs of bits of lhs and rhs.

Defined as:

return result |= rhs;

see sul::dynamic_bitset::operator|=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary OR between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ swap()

template<typename Block , typename Allocator >
void swap ( dynamic_bitset< Block, Allocator > & bitset1,
dynamic_bitset< Block, Allocator > & bitset2 )
related

Exchange the content of bitset1 and bitset2.

Defined as:

bitset1.swap(bitset2);

see sul::dynamic_bitset::swap() for more informations.

Parameters
bitset1sul::dynamic_bitset to be swapped
bitset2sul::dynamic_bitset to be swapped
Template Parameters
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Complexity
Constant.
Since
1.0.0

Member Data Documentation

◆ bits_per_block

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
size_type sul::dynamic_bitset< Block, Allocator >::bits_per_block = std::numeric_limits<block_type>::digits
staticconstexpr

Number of bits that can be stored in a block.

Since
1.0.0

◆ npos

template<typename Block = unsigned long long, typename Allocator = std::allocator<Block>>
size_type sul::dynamic_bitset< Block, Allocator >::npos = std::numeric_limits<size_type>::max()
staticconstexpr

Maximum value of size_type, returned for invalid positions.

Since
1.0.0

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