NDEVR
API Documentation
BitAlignedBuffer

A buffer that stores elements using a configurable number of bits per element. More...

Public Member Functions

 BitAlignedBuffer (uint04 bits_per_element)
 Constructs a BitAlignedBuffer with the specified number of bits per element.
void add (uint08 value)
 Appends a value to the end of the buffer.
uint04 bitSize () const
 Returns the number of bits used per element.
void clear ()
 Removes all elements and frees storage.
void ensureCapacity (uint04 newSize)
 Ensures the internal storage can hold at least the specified number of elements.
uint08 getValueAtBitOffset (uint04 bit_pos) const
 Retrieves the value stored at a specific bit offset within the buffer.
void loadFromBytes (const uint8_t *data, uint04 byteCount)
 Loads raw byte data into the buffer, replacing existing contents.
uint08 operator[] (uint04 index) const
 Accesses the element at the given index (read-only).
void set (uint04 index, uint08 value)
 Sets the value of the element at the given index.
void setSize (uint04 size)
 Sets the number of elements in the buffer, allocating storage as needed.
uint04 size () const
 Returns the number of elements currently stored in the buffer.

Detailed Description

A buffer that stores elements using a configurable number of bits per element.


Provides a compact storage mechanism where each element occupies a fixed number of bits (less than 64), packed tightly into 64-bit words. Handles bit alignment and word boundary spillover automatically.

Definition at line 13 of file BitAlignedBuffer.h.

Constructor & Destructor Documentation

◆ BitAlignedBuffer()

BitAlignedBuffer::BitAlignedBuffer ( uint04 bits_per_element)
inline

Constructs a BitAlignedBuffer with the specified number of bits per element.

Parameters
[in]bits_per_elementThe number of bits used to store each element. Must be > 0 and < 64.

Definition at line 20 of file BitAlignedBuffer.h.

Member Function Documentation

◆ add()

void BitAlignedBuffer::add ( uint08 value)
inline

Appends a value to the end of the buffer.

Parameters
[in]valueThe value to append. Must fit within the configured bits per element.

Definition at line 63 of file BitAlignedBuffer.h.

References ensureCapacity().

◆ bitSize()

uint04 BitAlignedBuffer::bitSize ( ) const
inline

Returns the number of bits used per element.

Returns
The bits-per-element value configured at construction.

Definition at line 158 of file BitAlignedBuffer.h.

◆ ensureCapacity()

void BitAlignedBuffer::ensureCapacity ( uint04 newSize)
inline

Ensures the internal storage can hold at least the specified number of elements.

Parameters
[in]newSizeThe minimum number of elements the buffer should be able to hold.

Definition at line 174 of file BitAlignedBuffer.h.

Referenced by add(), and setSize().

◆ getValueAtBitOffset()

uint08 BitAlignedBuffer::getValueAtBitOffset ( uint04 bit_pos) const
inline

Retrieves the value stored at a specific bit offset within the buffer.

Parameters
[in]bit_posThe bit position from which to read the value.
Returns
The value extracted from the specified bit position.

Definition at line 91 of file BitAlignedBuffer.h.

Referenced by operator[]().

◆ loadFromBytes()

void BitAlignedBuffer::loadFromBytes ( const uint8_t * data,
uint04 byteCount )
inline

Loads raw byte data into the buffer, replacing existing contents.

Parameters
[in]dataPointer to the source byte array.
[in]byteCountThe number of bytes to load from the source array.

Definition at line 39 of file BitAlignedBuffer.h.

◆ operator[]()

uint08 BitAlignedBuffer::operator[] ( uint04 index) const
inline

Accesses the element at the given index (read-only).

Parameters
[in]indexThe zero-based element index.
Returns
The value stored at the specified index.

Definition at line 122 of file BitAlignedBuffer.h.

References getValueAtBitOffset().

◆ set()

void BitAlignedBuffer::set ( uint04 index,
uint08 value )
inline

Sets the value of the element at the given index.

Parameters
[in]indexThe zero-based element index.
[in]valueThe value to store. Must fit within the configured bits per element.

Definition at line 133 of file BitAlignedBuffer.h.

◆ setSize()

void BitAlignedBuffer::setSize ( uint04 size)
inline

Sets the number of elements in the buffer, allocating storage as needed.

Parameters
[in]sizeThe desired number of elements.

Definition at line 29 of file BitAlignedBuffer.h.

References ensureCapacity(), and size().

◆ size()

uint04 BitAlignedBuffer::size ( ) const
inline

Returns the number of elements currently stored in the buffer.

Returns
The element count.

Definition at line 166 of file BitAlignedBuffer.h.

Referenced by setSize().


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