sparrow 0.9.0
|
Base class providing core functionality for dynamic bitset implementations. More...
#include <dynamic_bitset_base.hpp>
Public Types | |
using | self_type = dynamic_bitset_base<B> |
This class type. | |
using | storage_type = B |
Underlying storage container type. | |
using | storage_type_without_cvrefpointer |
Storage type without CV/ref/pointer qualifiers. | |
using | block_type = typename storage_type_without_cvrefpointer::value_type |
Type of each storage block (integral type) | |
using | value_type = bool |
Type of individual bit values. | |
using | reference = bitset_reference<self_type> |
Mutable reference to a bit. | |
using | const_reference = bool |
Immutable reference to a bit (plain bool) | |
using | size_type = typename storage_type_without_cvrefpointer::size_type |
Type for sizes and indices. | |
using | difference_type = typename storage_type_without_cvrefpointer::difference_type |
Type for iterator differences. | |
using | iterator = bitset_iterator<self_type, false> |
Mutable iterator type. | |
using | const_iterator = bitset_iterator<self_type, true> |
Immutable iterator type. | |
Public Member Functions | |
constexpr size_type | size () const noexcept |
Returns the number of bits in the bitset. | |
constexpr bool | empty () const noexcept |
Checks if the bitset contains no bits. | |
constexpr size_type | null_count () const noexcept |
Returns the number of bits set to false (null/invalid). | |
constexpr bool | test (size_type pos) const |
Tests the value of a bit at the specified position. | |
constexpr void | set (size_type pos, value_type value) |
Sets the value of a bit at the specified position. | |
constexpr const_reference | at (size_type pos) const |
Accesses a bit with bounds checking. | |
constexpr reference | at (size_type pos) |
Accesses a bit with bounds checking. | |
constexpr reference | operator[] (size_type i) |
Accesses a bit without bounds checking. | |
constexpr const_reference | operator[] (size_type i) const |
Accesses a bit without bounds checking. | |
constexpr block_type * | data () noexcept |
Returns a pointer to the underlying block storage. | |
constexpr const block_type * | data () const noexcept |
Returns a pointer to the underlying block storage. | |
constexpr size_type | block_count () const noexcept |
Returns the number of storage blocks. | |
constexpr void | swap (self_type &rhs) noexcept |
Swaps the contents with another bitset. | |
constexpr iterator | begin () |
Returns a mutable iterator to the first bit. | |
constexpr iterator | end () |
Returns a mutable iterator past the last bit. | |
constexpr const_iterator | begin () const |
Returns an immutable iterator to the first bit. | |
constexpr const_iterator | end () const |
Returns an immutable iterator past the last bit. | |
constexpr const_iterator | cbegin () const |
Returns an immutable iterator to the first bit. | |
constexpr const_iterator | cend () const |
Returns an immutable iterator past the last bit. | |
constexpr reference | front () |
Accesses the first bit. | |
constexpr const_reference | front () const |
Accesses the first bit. | |
constexpr reference | back () |
Accesses the last bit. | |
constexpr const_reference | back () const |
Accesses the last bit. | |
constexpr const storage_type_without_cvrefpointer & | buffer () const noexcept |
Returns an immutable reference to the underlying buffer. | |
constexpr storage_type_without_cvrefpointer & | buffer () noexcept |
Returns a mutable reference to the underlying buffer. | |
storage_type | extract_storage () noexcept |
Extracts the underlying storage (move operation). | |
Static Public Member Functions | |
static constexpr size_type | compute_block_count (size_type bits_count) noexcept |
Computes the number of blocks needed to store the specified number of bits. | |
Protected Member Functions | |
constexpr | dynamic_bitset_base (storage_type buffer, size_type size) |
Constructs a bitset with the given storage and size. | |
constexpr | dynamic_bitset_base (storage_type buffer, size_type size, size_type null_count) |
Constructs a bitset with the given storage, size, and null count. | |
constexpr | ~dynamic_bitset_base ()=default |
constexpr | dynamic_bitset_base (const dynamic_bitset_base &)=default |
constexpr | dynamic_bitset_base (dynamic_bitset_base &&) noexcept=default |
constexpr dynamic_bitset_base & | operator= (const dynamic_bitset_base &)=default |
constexpr dynamic_bitset_base & | operator= (dynamic_bitset_base &&) noexcept=default |
constexpr void | resize (size_type n, value_type b=false) |
Resizes the bitset to contain n bits. | |
constexpr void | clear () noexcept |
Removes all bits from the bitset. | |
constexpr iterator | insert (const_iterator pos, value_type value) |
Inserts a single bit at the specified position. | |
constexpr iterator | insert (const_iterator pos, size_type count, value_type value) |
Inserts multiple bits with the same value at the specified position. | |
template<std::input_iterator InputIt> requires std::ranges::random_access_range<std::remove_pointer_t<B>> | |
constexpr iterator | insert (const_iterator pos, InputIt first, InputIt last) |
Inserts bits from an iterator range at the specified position. | |
constexpr iterator | insert (const_iterator pos, std::initializer_list< value_type > ilist) |
Inserts bits from an initializer list at the specified position. | |
constexpr iterator | emplace (const_iterator pos, value_type value) |
Constructs a bit in-place at the specified position. | |
constexpr iterator | erase (const_iterator pos) |
Removes a single bit at the specified position. | |
constexpr iterator | erase (const_iterator first, const_iterator last) |
Removes bits in the specified range. | |
constexpr void | push_back (value_type value) |
Adds a bit to the end of the bitset. | |
constexpr void | pop_back () |
Removes the last bit from the bitset. | |
constexpr void | zero_unused_bits () |
Clears any unused bits in the last storage block. | |
size_type | count_non_null () const noexcept |
Counts the number of bits set to true. | |
Friends | |
class | bitset_iterator< self_type, true > |
Const iterator needs access to internals. | |
class | bitset_iterator< self_type, false > |
Mutable iterator needs access to internals. | |
class | bitset_reference< self_type > |
Bit reference needs access to internals. | |
Base class providing core functionality for dynamic bitset implementations.
This template class serves as the foundation for both dynamic_bitset and dynamic_bitset_view, providing a comprehensive API for manipulating sequences of bits stored in memory blocks. The key difference between derived classes is memory ownership: dynamic_bitset owns and manages its storage, while dynamic_bitset_view provides a non-owning view.
The class efficiently stores bits using blocks of integral types, with specialized algorithms for bit manipulation, counting, and iteration. It supports all standard container operations including insertion, deletion, resizing, and element access.
B | The underlying storage type, which must be a random access range. Typically buffer<T> for owning storage or buffer_view<T> for non-owning views. The value_type of B must be an integral type used as storage blocks. |
Example usage through derived classes:
Definition at line 68 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::block_type = typename storage_type_without_cvrefpointer::value_type |
Type of each storage block (integral type)
Definition at line 76 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::const_iterator = bitset_iterator<self_type, true> |
Immutable iterator type.
Definition at line 87 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::const_reference = bool |
Immutable reference to a bit (plain bool)
Definition at line 80 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::difference_type = typename storage_type_without_cvrefpointer::difference_type |
Type for iterator differences.
Definition at line 83 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::iterator = bitset_iterator<self_type, false> |
Mutable iterator type.
Definition at line 86 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::reference = bitset_reference<self_type> |
Mutable reference to a bit.
Definition at line 79 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::self_type = dynamic_bitset_base<B> |
This class type.
Definition at line 72 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::size_type = typename storage_type_without_cvrefpointer::size_type |
Type for sizes and indices.
Definition at line 81 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::storage_type = B |
Underlying storage container type.
Definition at line 73 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::storage_type_without_cvrefpointer |
Storage type without CV/ref/pointer qualifiers.
Definition at line 74 of file dynamic_bitset_base.hpp.
using sparrow::dynamic_bitset_base< B >::value_type = bool |
Type of individual bit values.
Definition at line 78 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Constructs a bitset with the given storage and size.
buffer | The storage buffer to use |
size | The number of bits in the bitset |
Definition at line 793 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Constructs a bitset with the given storage, size, and null count.
buffer | The storage buffer to use |
size | The number of bits in the bitset |
null_count | The number of unset bits |
Definition at line 802 of file dynamic_bitset_base.hpp.
|
constexprprotecteddefault |
|
constexprprotecteddefault |
|
constexprprotecteddefaultnoexcept |
|
nodiscardconstexpr |
Accesses a bit with bounds checking.
pos | The position of the bit to access |
std::out_of_range | if pos >= size() |
Definition at line 725 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses a bit with bounds checking.
pos | The position of the bit to access |
std::out_of_range | if pos >= size() |
Definition at line 739 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses the last bit.
Definition at line 773 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses the last bit.
Definition at line 781 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns a mutable iterator to the first bit.
Definition at line 683 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns an immutable iterator to the first bit.
Definition at line 697 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Returns the number of storage blocks.
Definition at line 666 of file dynamic_bitset_base.hpp.
|
inlinenodiscardconstexprnoexcept |
Returns an immutable reference to the underlying buffer.
Definition at line 286 of file dynamic_bitset_base.hpp.
|
inlinenodiscardconstexprnoexcept |
Returns a mutable reference to the underlying buffer.
Definition at line 303 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns an immutable iterator to the first bit.
Definition at line 711 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns an immutable iterator past the last bit.
Definition at line 718 of file dynamic_bitset_base.hpp.
|
constexprprotectednoexcept |
Removes all bits from the bitset.
Definition at line 948 of file dynamic_bitset_base.hpp.
|
staticnodiscardconstexprnoexcept |
Computes the number of blocks needed to store the specified number of bits.
bits_count | The number of bits to store |
Definition at line 811 of file dynamic_bitset_base.hpp.
|
nodiscardprotectednoexcept |
Counts the number of bits set to true.
Definition at line 840 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Returns a pointer to the underlying block storage.
Definition at line 659 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Returns a pointer to the underlying block storage.
Definition at line 645 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Constructs a bit in-place at the specified position.
pos | Iterator pointing to the insertion position |
value | The value of the bit to emplace |
Definition at line 1047 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Checks if the bitset contains no bits.
Definition at line 558 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns a mutable iterator past the last bit.
Definition at line 690 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Returns an immutable iterator past the last bit.
Definition at line 704 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Removes bits in the specified range.
first | Iterator pointing to the first bit to remove |
last | Iterator pointing past the last bit to remove |
Definition at line 1065 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Removes a single bit at the specified position.
pos | Iterator pointing to the bit to remove |
Definition at line 1054 of file dynamic_bitset_base.hpp.
|
inlinenodiscardnoexcept |
Extracts the underlying storage (move operation).
Definition at line 331 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses the first bit.
Definition at line 753 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses the first bit.
Definition at line 761 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Inserts bits from an iterator range at the specified position.
InputIt | Input iterator type |
pos | Iterator pointing to the insertion position |
first | Iterator pointing to the first bit to insert |
last | Iterator pointing past the last bit to insert |
Definition at line 1002 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Inserts multiple bits with the same value at the specified position.
pos | Iterator pointing to the insertion position |
count | The number of bits to insert |
value | The value of the bits to insert |
Definition at line 966 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Inserts bits from an initializer list at the specified position.
pos | Iterator pointing to the insertion position |
ilist | Initializer list containing the bits to insert |
|
constexprprotected |
Inserts a single bit at the specified position.
pos | Iterator pointing to the insertion position |
value | The value of the bit to insert |
Definition at line 958 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Returns the number of bits set to false (null/invalid).
Definition at line 565 of file dynamic_bitset_base.hpp.
|
constexprprotecteddefault |
|
constexprprotecteddefaultnoexcept |
|
nodiscardconstexpr |
Accesses a bit without bounds checking.
i | The position of the bit to access |
Definition at line 572 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Accesses a bit without bounds checking.
i | The position of the bit to access |
Definition at line 580 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Removes the last bit from the bitset.
Definition at line 1109 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Adds a bit to the end of the bitset.
value | The value of the bit to add |
Definition at line 1102 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Resizes the bitset to contain n bits.
n | The new size in bits |
b | The value to initialize new bits with (default false) |
Definition at line 909 of file dynamic_bitset_base.hpp.
|
constexpr |
Sets the value of a bit at the specified position.
pos | The position of the bit to set |
value | The value to set (true or false) |
std::runtime_error | if trying to set false on a non-resizable null buffer |
Definition at line 606 of file dynamic_bitset_base.hpp.
|
nodiscardconstexprnoexcept |
Returns the number of bits in the bitset.
Definition at line 551 of file dynamic_bitset_base.hpp.
|
constexprnoexcept |
Swaps the contents with another bitset.
rhs | The other bitset to swap with |
Definition at line 673 of file dynamic_bitset_base.hpp.
|
nodiscardconstexpr |
Tests the value of a bit at the specified position.
pos | The position of the bit to test |
Definition at line 587 of file dynamic_bitset_base.hpp.
|
constexprprotected |
Clears any unused bits in the last storage block.
Definition at line 880 of file dynamic_bitset_base.hpp.
|
friend |
Mutable iterator needs access to internals.
Definition at line 542 of file dynamic_bitset_base.hpp.
|
friend |
Const iterator needs access to internals.
Definition at line 542 of file dynamic_bitset_base.hpp.
|
friend |
Bit reference needs access to internals.
Definition at line 542 of file dynamic_bitset_base.hpp.