sparrow 2.2.1
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
sparrow::dynamic_bitset_view< T, NCP > Class Template Reference

A non-owning view to a dynamic size sequence of bits stored in external memory. More...

#include <dynamic_bitset_view.hpp>

Inheritance diagram for sparrow::dynamic_bitset_view< T, NCP >:
[legend]
Collaboration diagram for sparrow::dynamic_bitset_view< T, NCP >:
[legend]

Public Types

using base_type = dynamic_bitset_base<buffer_view<T>, NCP>
 Base class type providing bit operations.
 
using storage_type = typename base_type::storage_type
 Underlying buffer view type (non-owning)
 
using block_type = typename base_type::block_type
 Type of each storage block (same as T)
 
using size_type = typename base_type::size_type
 Type used for sizes and indices.
 
- Public Types inherited from sparrow::dynamic_bitset_base< buffer_view< T >, tracking_null_count<> >
using self_type
 This class type.
 
using null_count_policy_type
 Null count tracking policy type.
 
using storage_type
 Underlying storage container type.
 
using storage_type_without_cvrefpointer
 Storage type without CV/ref/pointer qualifiers.
 
using block_type
 Type of each storage block (integral type)
 
using value_type
 Type of individual bit values.
 
using reference
 Mutable reference to a bit.
 
using const_reference
 Immutable reference to a bit (plain bool)
 
using size_type
 Type for sizes and indices.
 
using difference_type
 Type for iterator differences.
 
using iterator
 Mutable iterator type.
 
using const_iterator
 Immutable iterator type.
 

Public Member Functions

constexpr dynamic_bitset_view (block_type *p, size_type n)
 Constructs a bitset view from external memory.
 
constexpr dynamic_bitset_view (block_type *p, size_type n, size_type offset)
 Constructs a bitset view from external memory with null count tracking.
 
constexpr dynamic_bitset_view (block_type *p, size_type n, size_type offset, size_type null_count)
 Constructs a bitset view from external memory with null count and offset.
 
constexpr ~dynamic_bitset_view ()=default
 
constexpr dynamic_bitset_view (const dynamic_bitset_view &)=default
 
constexpr dynamic_bitset_view (dynamic_bitset_view &&) noexcept=default
 
constexpr dynamic_bitset_viewoperator= (const dynamic_bitset_view &)=default
 
constexpr dynamic_bitset_viewoperator= (dynamic_bitset_view &&) noexcept=default
 
constexpr dynamic_bitset_view slice_view (size_type start, size_type length) const
 Creates a view over a subset of bits.
 
constexpr dynamic_bitset_view slice_view (size_type start) const
 Creates a view over a subset of bits from start to end of bitset.
 
- Public Member Functions inherited from sparrow::dynamic_bitset_base< buffer_view< T >, tracking_null_count<> >
constexpr size_type size () const noexcept
 Returns the number of bits in the bitset.
 
constexpr void set_size (size_type new_size) noexcept
 
constexpr size_type offset () const noexcept
 Returns the bit offset within the buffer.
 
constexpr void set_offset (size_type offset) noexcept
 Sets the bit offset within the buffer.
 
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_typedata () noexcept
 Returns a pointer to the underlying block storage.
 
constexpr const block_typedata () 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 const_iterator begin () const
 Returns an immutable iterator to the first bit.
 
constexpr iterator end ()
 Returns a mutable iterator past the last 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_cvrefpointerbuffer () const noexcept
 Returns an immutable reference to the underlying buffer.
 
constexpr storage_type_without_cvrefpointerbuffer () noexcept
 Returns a mutable reference to the underlying buffer.
 
storage_type extract_storage () noexcept
 Extracts the underlying storage (move operation).
 

Additional Inherited Members

- Static Public Member Functions inherited from sparrow::dynamic_bitset_base< buffer_view< T >, tracking_null_count<> >
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 inherited from sparrow::dynamic_bitset_base< buffer_view< T >, tracking_null_count<> >
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 offset)
 Constructs a bitset with the given storage, size, and null count.
 
constexpr dynamic_bitset_base (storage_type buffer, size_type size, size_type offset, size_type null_count)
 Constructs a bitset with the given storage, size, offset, and null count.
 
constexpr dynamic_bitset_base (const dynamic_bitset_base &)=default
 
constexpr dynamic_bitset_base (dynamic_bitset_base &&) noexcept=default
 
constexpr ~dynamic_bitset_base ()=default
 
constexpr dynamic_bitset_baseoperator= (const dynamic_bitset_base &)=default
 
constexpr dynamic_bitset_baseoperator= (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.
 
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.
 

Detailed Description

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
class sparrow::dynamic_bitset_view< T, NCP >

A non-owning view to a dynamic size sequence of bits stored in external memory.

This class provides a lightweight, non-owning interface to manipulate sequences of boolean values stored in external memory buffers. Unlike dynamic_bitset, this class does not manage memory allocation or deallocation - it only provides a view into existing bit data.

The view is designed for scenarios where you need to work with bit sequences that are managed elsewhere (e.g., memory-mapped files, shared memory, or buffers owned by other objects) while still benefiting from the rich bit manipulation API.

Template Parameters
TThe integer type used to store the bits. Must satisfy std::integral. Common choices are std::uint8_t, std::uint32_t, or std::uint64_t. The choice affects memory layout and performance characteristics.
Note
This class inherits from dynamic_bitset_base which provides the core bit manipulation functionality. The view does not support operations that would change the size of the underlying storage (no resize, push_back, etc.).
Warning
The user is responsible for ensuring that the viewed memory remains valid for the lifetime of the view object. Accessing a view after the underlying memory has been deallocated results in undefined behavior.

Example usage:

//External buffer containing bit data
std::vector<std::uint8_t> external_buffer = {0b10101010, 0b11110000};
//Create a view of the first 12 bits
dynamic_bitset_view<std::uint8_t> view(external_buffer.data(), 12);
//Read and modify bits through the view
bool bit_value = view.test(5);
view.set(7, true);
//The changes are reflected in the original buffer
assert(external_buffer[0] == view.block(0));
A non-owning view to a dynamic size sequence of bits stored in external memory.

Definition at line 65 of file dynamic_bitset_view.hpp.

Member Typedef Documentation

◆ base_type

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
using sparrow::dynamic_bitset_view< T, NCP >::base_type = dynamic_bitset_base<buffer_view<T>, NCP>

Base class type providing bit operations.

Definition at line 69 of file dynamic_bitset_view.hpp.

◆ block_type

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
using sparrow::dynamic_bitset_view< T, NCP >::block_type = typename base_type::block_type

Type of each storage block (same as T)

Definition at line 72 of file dynamic_bitset_view.hpp.

◆ size_type

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
using sparrow::dynamic_bitset_view< T, NCP >::size_type = typename base_type::size_type

Type used for sizes and indices.

Definition at line 73 of file dynamic_bitset_view.hpp.

◆ storage_type

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
using sparrow::dynamic_bitset_view< T, NCP >::storage_type = typename base_type::storage_type

Underlying buffer view type (non-owning)

Definition at line 71 of file dynamic_bitset_view.hpp.

Constructor & Destructor Documentation

◆ dynamic_bitset_view() [1/5]

template<std::integral T, null_count_policy NCP>
sparrow::dynamic_bitset_view< T, NCP >::dynamic_bitset_view ( block_type * p,
size_type n )
constexpr

Constructs a bitset view from external memory.

Creates a non-owning view over the provided memory buffer. The view will interpret the memory as a sequence of bits using the specified block type. All bits are initially assumed to be valid (non-null).

Parameters
pPointer to the external memory buffer containing bit data
nThe number of bits represented in the buffer
Precondition
p must point to a valid memory buffer of at least compute_block_count(n) * sizeof(block_type) bytes, or be nullptr if n is 0
n must accurately represent the number of bits available in the buffer
The memory pointed to by p must remain valid for the lifetime of this view
Postcondition
size() == n
offset() == 0
null_count() == 0 (all bits assumed valid initially)
The view provides access to n bits starting from memory location p
Note
If p is nullptr, n should be 0, and the view will be empty
No memory allocation occurs - this is a pure view operation

Example:

std::array<std::uint32_t, 2> buffer = {0xFFFFFFFF, 0x0000FFFF};
assert(view.size() == 48);
assert(view.test(0) == true); // First bit is set
Object that owns a piece of contiguous memory.
Definition buffer.hpp:131
constexpr U * data() noexcept
Definition buffer.hpp:653
constexpr const storage_type_without_cvrefpointer & buffer() const noexcept

Definition at line 203 of file dynamic_bitset_view.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamic_bitset_view() [2/5]

template<std::integral T, null_count_policy NCP>
sparrow::dynamic_bitset_view< T, NCP >::dynamic_bitset_view ( block_type * p,
size_type n,
size_type offset )
constexpr

Constructs a bitset view from external memory with null count tracking.

Creates a non-owning view over the provided memory buffer with explicit tracking of how many bits are null (invalid/unset). This constructor is useful when you already know the null count and want to avoid recomputing it.

Parameters
pPointer to the external memory buffer containing bit data
nThe number of bits represented in the buffer
offsetThe offset in bits from the start of the buffer
Precondition
p must point to a valid memory buffer of at least compute_block_count(n) * sizeof(block_type) bytes, or be nullptr if n is 0
n must accurately represent the number of bits available in the buffer
offset <= n
null_count must accurately reflect the actual number of unset bits in the buffer
The memory pointed to by p must remain valid for the lifetime of this view
Postcondition
size() == n
offset() == offset
null_count() == null_count
The view provides access to n bits starting from memory location p
Note
This constructor is more efficient when the null count is already known, as it avoids scanning the buffer to count null bits
An internal assertion verifies that the provided null_count matches the actual count of null bits in debug builds

Example:

std::array<std::uint8_t, 2> buffer = {0b10101010, 0b11110000};
//We know there are 6 unset bits in the pattern above
assert(view.size() == 16);
assert(view.null_count() == 6);

Definition at line 209 of file dynamic_bitset_view.hpp.

Here is the call graph for this function:

◆ dynamic_bitset_view() [3/5]

template<std::integral T, null_count_policy NCP>
sparrow::dynamic_bitset_view< T, NCP >::dynamic_bitset_view ( block_type * p,
size_type n,
size_type offset,
size_type null_count )
constexpr

Constructs a bitset view from external memory with null count and offset.

Creates a non-ownning view over the provided memory buffer starting at the specified bit offset with explicit null count tracking.

Parameters
pPointer to the external memory buffer containing bit data
nThe number of bits represented in the buffer
offsetThe offset in bits from the start of the buffer
null_countThe number of bits that are set to false/null in the buffer
Precondition
p must point to a valid memory buffer
null_count <= n
The memory pointed to by p must remain valid for the lifetime of this view
Postcondition
size() == n
offset() == offset
null_count() == null_count

Definition at line 215 of file dynamic_bitset_view.hpp.

Here is the call graph for this function:

◆ ~dynamic_bitset_view()

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
sparrow::dynamic_bitset_view< T, NCP >::~dynamic_bitset_view ( )
constexprdefault

◆ dynamic_bitset_view() [4/5]

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
sparrow::dynamic_bitset_view< T, NCP >::dynamic_bitset_view ( const dynamic_bitset_view< T, NCP > & )
constexprdefault

◆ dynamic_bitset_view() [5/5]

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
sparrow::dynamic_bitset_view< T, NCP >::dynamic_bitset_view ( dynamic_bitset_view< T, NCP > && )
constexprdefaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
dynamic_bitset_view & sparrow::dynamic_bitset_view< T, NCP >::operator= ( const dynamic_bitset_view< T, NCP > & )
constexprdefault

◆ operator=() [2/2]

template<std::integral T, null_count_policy NCP = tracking_null_count<>>
dynamic_bitset_view & sparrow::dynamic_bitset_view< T, NCP >::operator= ( dynamic_bitset_view< T, NCP > && )
constexprdefaultnoexcept

◆ slice_view() [1/2]

template<std::integral T, null_count_policy NCP>
auto sparrow::dynamic_bitset_view< T, NCP >::slice_view ( size_type start) const
nodiscardconstexpr

Creates a view over a subset of bits from start to end of bitset.

Parameters
startThe starting position of the slice
Returns
A new bitset view providing a view over bits from start to the end
Precondition
start <= size()
Postcondition
The returned view has size() == size() - start
The returned view provides a view over bits [start, size())
Exceptions
std::out_of_rangeif start > size()
Note
The returned view shares the same underlying storage

Definition at line 256 of file dynamic_bitset_view.hpp.

Here is the call graph for this function:

◆ slice_view() [2/2]

template<std::integral T, null_count_policy NCP>
auto sparrow::dynamic_bitset_view< T, NCP >::slice_view ( size_type start,
size_type length ) const
nodiscardconstexpr

Creates a view over a subset of bits.

Parameters
startThe starting position of the slice
lengthThe number of bits in the slice
Returns
A new bitset view providing a view over the specified range
Precondition
start + length <= size()
Postcondition
The returned view has size() == length
The returned view provides a view over bits [start, start+length)
Exceptions
std::out_of_rangeif start + length > size()
Note
The returned view shares the same underlying storage

Definition at line 226 of file dynamic_bitset_view.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

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