CCSDS 124.0-B-1 C++ 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
ccsds124::BitVector< N > Class Template Reference

Fixed-length bit vector with compile-time size. More...

#include <bitvector.hpp>

Public Member Functions

constexpr BitVector () noexcept
 Default constructor - initializes all bits to zero.
 
constexpr std::size_t length () const noexcept
 Get the number of bits.
 
constexpr std::size_t num_words () const noexcept
 Get the number of 32-bit words.
 
void zero () noexcept
 Set all bits to zero.
 
int get_bit (std::size_t pos) const noexcept
 Get bit value at position.
 
int get_bit_unchecked (std::size_t pos) const noexcept
 Get bit value at position without bounds checking.
 
void set_bit (std::size_t pos, int value) noexcept
 Set bit value at position.
 
void set_bit_unchecked (std::size_t pos, int value) noexcept
 Set bit value at position without bounds checking.
 
void copy_from (const BitVector &src) noexcept
 Copy from another BitVector.
 
void xor_of (const BitVector &a, const BitVector &b) noexcept
 Compute XOR of two vectors.
 
void or_of (const BitVector &a, const BitVector &b) noexcept
 Compute OR of two vectors.
 
void and_of (const BitVector &a, const BitVector &b) noexcept
 Compute AND of two vectors.
 
void not_of (const BitVector &a) noexcept
 Compute NOT of a vector.
 
void left_shift_of (const BitVector &a) noexcept
 Compute left shift by 1 of a vector.
 
void reverse_of (const BitVector &a) noexcept
 Compute bit reversal of a vector.
 
void xor_with (const BitVector &other) noexcept
 XOR in-place with another vector.
 
void xor_with (const BitVector &a, const BitVector &b) noexcept
 Compute XOR of two vectors (result = a ^ b).
 
void or_with (const BitVector &other) noexcept
 OR in-place with another vector.
 
void or_with (const BitVector &a, const BitVector &b) noexcept
 Compute OR of two vectors (result = a | b).
 
void or_in_place (const BitVector &other) noexcept
 OR in-place with another vector (alias for or_with).
 
void and_with (const BitVector &other) noexcept
 AND in-place with another vector.
 
void invert () noexcept
 Invert all bits in-place.
 
void left_shift () noexcept
 Left shift by 1 in-place.
 
void left_shift (const BitVector &src) noexcept
 Compute left shift of another vector (result = src << 1).
 
std::size_t hamming_weight () const noexcept
 Count number of set bits (Hamming weight).
 
bool operator== (const BitVector &other) const noexcept
 Compare for equality.
 
bool operator!= (const BitVector &other) const noexcept
 Compare for inequality.
 
void from_bytes (const std::uint8_t *bytes, std::size_t num_bytes) noexcept
 Load from byte array (big-endian).
 
void to_bytes (std::uint8_t *bytes, std::size_t num_bytes) const noexcept
 Store to byte array (big-endian).
 
word_tdata () noexcept
 Get raw data pointer (for advanced use).
 
const word_tdata () const noexcept
 Get raw data pointer (const version).
 

Static Public Attributes

static constexpr std::size_t NUM_WORDS = (N + 31) / 32
 Number of 32-bit words needed.
 
static constexpr std::size_t NUM_BYTES = (N + 7) / 8
 Number of bytes needed.
 

Detailed Description

template<std::size_t N>
class ccsds124::BitVector< N >

Fixed-length bit vector with compile-time size.

Template Parameters
NNumber of bits in the vector

Uses static allocation only - no heap allocation. Suitable for embedded systems with -fno-exceptions -fno-rtti.

Definition at line 90 of file bitvector.hpp.

Constructor & Destructor Documentation

◆ BitVector()

template<std::size_t N>
constexpr ccsds124::BitVector< N >::BitVector ( )
inlineconstexprnoexcept

Default constructor - initializes all bits to zero.

Definition at line 101 of file bitvector.hpp.

Member Function Documentation

◆ and_of()

template<std::size_t N>
void ccsds124::BitVector< N >::and_of ( const BitVector< N > &  a,
const BitVector< N > &  b 
)
inlinenoexcept

Compute AND of two vectors.

Parameters
aFirst operand
bSecond operand

Definition at line 216 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ and_with()

template<std::size_t N>
void ccsds124::BitVector< N >::and_with ( const BitVector< N > &  other)
inlinenoexcept

AND in-place with another vector.

Parameters
otherOperand

Definition at line 323 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ copy_from()

template<std::size_t N>
void ccsds124::BitVector< N >::copy_from ( const BitVector< N > &  src)
inlinenoexcept

Copy from another BitVector.

Parameters
srcSource vector

Definition at line 185 of file bitvector.hpp.

◆ data() [1/2]

template<std::size_t N>
const word_t * ccsds124::BitVector< N >::data ( ) const
inlinenoexcept

Get raw data pointer (const version).

Returns
Pointer to word array

Definition at line 462 of file bitvector.hpp.

◆ data() [2/2]

template<std::size_t N>
word_t * ccsds124::BitVector< N >::data ( )
inlinenoexcept

Get raw data pointer (for advanced use).

Returns
Pointer to word array

Definition at line 454 of file bitvector.hpp.

Referenced by ccsds124::Decompressor< N >::decompress_packet().

◆ from_bytes()

template<std::size_t N>
void ccsds124::BitVector< N >::from_bytes ( const std::uint8_t *  bytes,
std::size_t  num_bytes 
)
inlinenoexcept

Load from byte array (big-endian).

Parameters
bytesSource byte array
num_bytesNumber of bytes to load

Definition at line 404 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_BYTES, and ccsds124::BitVector< N >::zero().

Referenced by ccsds124::compress().

◆ get_bit()

template<std::size_t N>
int ccsds124::BitVector< N >::get_bit ( std::size_t  pos) const
inlinenoexcept

Get bit value at position.

Parameters
posBit position (0 = MSB, N-1 = LSB)
Returns
Bit value (0 or 1)

Definition at line 132 of file bitvector.hpp.

References ccsds124::BitVector< N >::get_bit_unchecked().

Referenced by ccsds124::Decompressor< N >::decompress_packet().

◆ get_bit_unchecked()

template<std::size_t N>
int ccsds124::BitVector< N >::get_bit_unchecked ( std::size_t  pos) const
inlinenoexcept

Get bit value at position without bounds checking.

Warning
Caller must ensure pos < N. Undefined behavior if pos >= N.
Parameters
posBit position (0 = MSB, N-1 = LSB)
Returns
Bit value (0 or 1)

Definition at line 145 of file bitvector.hpp.

Referenced by ccsds124::BitVector< N >::get_bit().

◆ hamming_weight()

template<std::size_t N>
std::size_t ccsds124::BitVector< N >::hamming_weight ( ) const
inlinenoexcept

Count number of set bits (Hamming weight).

Returns
Number of bits set to 1

Definition at line 363 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::Decompressor< N >::decompress_packet().

◆ invert()

template<std::size_t N>
void ccsds124::BitVector< N >::invert ( )
inlinenoexcept

Invert all bits in-place.

Definition at line 332 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ left_shift() [1/2]

template<std::size_t N>
void ccsds124::BitVector< N >::left_shift ( )
inlinenoexcept

Left shift by 1 in-place.

Definition at line 342 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ left_shift() [2/2]

template<std::size_t N>
void ccsds124::BitVector< N >::left_shift ( const BitVector< N > &  src)
inlinenoexcept

Compute left shift of another vector (result = src << 1).

Parameters
srcSource operand

Definition at line 355 of file bitvector.hpp.

References ccsds124::BitVector< N >::left_shift_of().

◆ left_shift_of()

template<std::size_t N>
void ccsds124::BitVector< N >::left_shift_of ( const BitVector< N > &  a)
inlinenoexcept

Compute left shift by 1 of a vector.

Parameters
aOperand

Definition at line 237 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::BitVector< N >::left_shift().

◆ length()

template<std::size_t N>
constexpr std::size_t ccsds124::BitVector< N >::length ( ) const
inlineconstexprnoexcept

Get the number of bits.

Returns
Number of bits in the vector

Definition at line 107 of file bitvector.hpp.

◆ not_of()

template<std::size_t N>
void ccsds124::BitVector< N >::not_of ( const BitVector< N > &  a)
inlinenoexcept

Compute NOT of a vector.

Parameters
aOperand

Definition at line 226 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ num_words()

template<std::size_t N>
constexpr std::size_t ccsds124::BitVector< N >::num_words ( ) const
inlineconstexprnoexcept

Get the number of 32-bit words.

Returns
Number of words used for storage

Definition at line 115 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ operator!=()

template<std::size_t N>
bool ccsds124::BitVector< N >::operator!= ( const BitVector< N > &  other) const
inlinenoexcept

Compare for inequality.

Parameters
otherOther vector
Returns
true if not equal

Definition at line 394 of file bitvector.hpp.

◆ operator==()

template<std::size_t N>
bool ccsds124::BitVector< N >::operator== ( const BitVector< N > &  other) const
inlinenoexcept

Compare for equality.

Parameters
otherOther vector
Returns
true if equal

Definition at line 385 of file bitvector.hpp.

◆ or_in_place()

template<std::size_t N>
void ccsds124::BitVector< N >::or_in_place ( const BitVector< N > &  other)
inlinenoexcept

OR in-place with another vector (alias for or_with).

Parameters
otherOperand

Definition at line 315 of file bitvector.hpp.

References ccsds124::BitVector< N >::or_with().

◆ or_of()

template<std::size_t N>
void ccsds124::BitVector< N >::or_of ( const BitVector< N > &  a,
const BitVector< N > &  b 
)
inlinenoexcept

Compute OR of two vectors.

Parameters
aFirst operand
bSecond operand

Definition at line 205 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::Decompressor< N >::decompress_packet(), and ccsds124::BitVector< N >::or_with().

◆ or_with() [1/2]

template<std::size_t N>
void ccsds124::BitVector< N >::or_with ( const BitVector< N > &  a,
const BitVector< N > &  b 
)
inlinenoexcept

Compute OR of two vectors (result = a | b).

Parameters
aFirst operand
bSecond operand

Definition at line 307 of file bitvector.hpp.

References ccsds124::BitVector< N >::or_of().

◆ or_with() [2/2]

template<std::size_t N>
void ccsds124::BitVector< N >::or_with ( const BitVector< N > &  other)
inlinenoexcept

OR in-place with another vector.

Parameters
otherOperand

Definition at line 296 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::BitVector< N >::or_in_place().

◆ reverse_of()

template<std::size_t N>
void ccsds124::BitVector< N >::reverse_of ( const BitVector< N > &  a)
inlinenoexcept

Compute bit reversal of a vector.

Parameters
aOperand

Definition at line 250 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ set_bit()

template<std::size_t N>
void ccsds124::BitVector< N >::set_bit ( std::size_t  pos,
int  value 
)
inlinenoexcept

Set bit value at position.

Parameters
posBit position (0 = MSB, N-1 = LSB)
valueBit value (0 or 1)

Definition at line 157 of file bitvector.hpp.

References ccsds124::BitVector< N >::set_bit_unchecked().

◆ set_bit_unchecked()

template<std::size_t N>
void ccsds124::BitVector< N >::set_bit_unchecked ( std::size_t  pos,
int  value 
)
inlinenoexcept

Set bit value at position without bounds checking.

Warning
Caller must ensure pos < N. Undefined behavior if pos >= N.
Parameters
posBit position (0 = MSB, N-1 = LSB)
valueBit value (0 or 1)

Definition at line 170 of file bitvector.hpp.

Referenced by ccsds124::BitVector< N >::set_bit().

◆ to_bytes()

template<std::size_t N>
void ccsds124::BitVector< N >::to_bytes ( std::uint8_t *  bytes,
std::size_t  num_bytes 
) const
inlinenoexcept

Store to byte array (big-endian).

Parameters
bytesDestination byte array
num_bytesNumber of bytes to store

Definition at line 436 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_BYTES, and ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::decompress().

◆ xor_of()

template<std::size_t N>
void ccsds124::BitVector< N >::xor_of ( const BitVector< N > &  a,
const BitVector< N > &  b 
)
inlinenoexcept

Compute XOR of two vectors.

Parameters
aFirst operand
bSecond operand

Definition at line 194 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

Referenced by ccsds124::BitVector< N >::xor_with().

◆ xor_with() [1/2]

template<std::size_t N>
void ccsds124::BitVector< N >::xor_with ( const BitVector< N > &  a,
const BitVector< N > &  b 
)
inlinenoexcept

Compute XOR of two vectors (result = a ^ b).

Parameters
aFirst operand
bSecond operand

Definition at line 288 of file bitvector.hpp.

References ccsds124::BitVector< N >::xor_of().

◆ xor_with() [2/2]

template<std::size_t N>
void ccsds124::BitVector< N >::xor_with ( const BitVector< N > &  other)
inlinenoexcept

XOR in-place with another vector.

Parameters
otherOperand

Definition at line 277 of file bitvector.hpp.

References ccsds124::BitVector< N >::NUM_WORDS.

◆ zero()

template<std::size_t N>
void ccsds124::BitVector< N >::zero ( )
inlinenoexcept

Set all bits to zero.

Definition at line 122 of file bitvector.hpp.

Referenced by ccsds124::BitVector< N >::from_bytes().

Member Data Documentation

◆ NUM_BYTES

template<std::size_t N>
constexpr std::size_t ccsds124::BitVector< N >::NUM_BYTES = (N + 7) / 8
staticconstexpr

Number of bytes needed.

Definition at line 96 of file bitvector.hpp.

Referenced by ccsds124::BitVector< N >::from_bytes(), and ccsds124::BitVector< N >::to_bytes().

◆ NUM_WORDS


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