CCSDS 124.0-B-1 C 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
Bit Vector API

Fixed-length binary vector operations. More...

Data Structures

struct  bitvector
 Fixed-length bit vector structure. More...
 

Functions

int bitvector_init (bitvector_t *bv, size_t num_bits)
 Initialize a bit vector with specified length.
 
void bitvector_zero (bitvector_t *bv)
 Set all bits to zero.
 
void bitvector_copy (bitvector_t *dest, const bitvector_t *src)
 Copy bit vector contents.
 
static int bitvector_get_bit (const bitvector_t *bv, size_t pos)
 Get bit value at position (inline for performance).
 
static void bitvector_set_bit (bitvector_t *bv, size_t pos, int value)
 Set bit value at position (inline for performance).
 
void bitvector_xor (bitvector_t *result, const bitvector_t *a, const bitvector_t *b)
 Bitwise XOR operation.
 
void bitvector_or (bitvector_t *result, const bitvector_t *a, const bitvector_t *b)
 Bitwise OR operation.
 
void bitvector_and (bitvector_t *result, const bitvector_t *a, const bitvector_t *b)
 Bitwise AND operation.
 
void bitvector_not (bitvector_t *result, const bitvector_t *a)
 Bitwise NOT operation.
 
void bitvector_left_shift (bitvector_t *result, const bitvector_t *a)
 Left shift by one bit.
 
void bitvector_reverse (bitvector_t *result, const bitvector_t *a)
 Reverse bit order.
 
size_t bitvector_hamming_weight (const bitvector_t *bv)
 Count number of set bits (Hamming weight).
 
int bitvector_equals (const bitvector_t *a, const bitvector_t *b)
 Compare two bit vectors for equality.
 
int bitvector_from_bytes (bitvector_t *bv, const uint8_t *data, size_t num_bytes)
 Load bit vector from byte array.
 
int bitvector_to_bytes (const bitvector_t *bv, uint8_t *data, size_t num_bytes)
 Store bit vector to byte array.
 

Detailed Description

Fixed-length binary vector operations.

Bit vectors are the fundamental data structure for CCSDS 124.0-B-1 compression. They represent fixed-length binary sequences with operations for bitwise logic, shifting, and counting.

Note
Uses 32-bit words with big-endian byte packing to match ESA reference.

Function Documentation

◆ bitvector_and()

void bitvector_and ( bitvector_t result,
const bitvector_t a,
const bitvector_t b 
)

Bitwise AND operation.

Parameters
[out]resultResult vector (result = a AND b)
[in]aFirst operand
[in]bSecond operand

Definition at line 127 of file bitvector.c.

References data, length, and num_words.

◆ bitvector_copy()

void bitvector_copy ( bitvector_t dest,
const bitvector_t src 
)

Copy bit vector contents.

Parameters
[out]destDestination bit vector
[in]srcSource bit vector

Definition at line 72 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_compress_packet(), ccsds124_compressor_init(), ccsds124_compressor_reset(), ccsds124_compute_robustness_window(), ccsds124_decompress_packet_internal(), ccsds124_decompressor_init(), and ccsds124_decompressor_reset().

◆ bitvector_equals()

int bitvector_equals ( const bitvector_t a,
const bitvector_t b 
)

Compare two bit vectors for equality.

Parameters
[in]aFirst bit vector
[in]bSecond bit vector
Returns
1 if equal, 0 if different

Definition at line 247 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_decompress_packet_internal().

◆ bitvector_from_bytes()

int bitvector_from_bytes ( bitvector_t bv,
const uint8_t *  data,
size_t  num_bytes 
)

Load bit vector from byte array.

Loads bytes in big-endian order (first byte contains MSB bits).

Parameters
[out]bvBit vector to load into
[in]dataSource byte array
[in]num_bytesNumber of bytes to load
Returns
CCSDS124_OK on success

Definition at line 269 of file bitvector.c.

References CCSDS124_ERROR_INVALID_ARG, CCSDS124_ERROR_OVERFLOW, CCSDS124_OK, data, length, and num_words.

Referenced by ccsds124_compress().

◆ bitvector_get_bit()

static int bitvector_get_bit ( const bitvector_t bv,
size_t  pos 
)
inlinestatic

Get bit value at position (inline for performance).

Parameters
[in]bvBit vector
[in]posBit position (0 = LSB, length-1 = MSB)
Returns
Bit value (0 or 1)

Definition at line 169 of file ccsds124.h.

References data.

Referenced by bitbuffer_append_bitvector(), bitvector_reverse(), and ccsds124_decompress_packet_internal().

◆ bitvector_hamming_weight()

size_t bitvector_hamming_weight ( const bitvector_t bv)

Count number of set bits (Hamming weight).

Parameters
[in]bvBit vector
Returns
Number of bits set to 1

Definition at line 222 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_bit_insert(), ccsds124_compress_packet(), ccsds124_compute_effective_robustness(), and ccsds124_decompress_packet_internal().

◆ bitvector_init()

int bitvector_init ( bitvector_t bv,
size_t  num_bits 
)

Initialize a bit vector with specified length.

Allocates internal storage and sets all bits to zero.

Parameters
[out]bvBit vector to initialize (caller-allocated)
[in]num_bitsNumber of bits (1 to CCSDS124_MAX_PACKET_LENGTH)
Returns
CCSDS124_OK on success, CCSDS124_ERROR_INVALID_ARG if out of range

Definition at line 44 of file bitvector.c.

References CCSDS124_ERROR_INVALID_ARG, CCSDS124_MAX_PACKET_LENGTH, CCSDS124_OK, data, length, and num_words.

Referenced by ccsds124_compress(), ccsds124_compressor_init(), ccsds124_decompress_packet_internal(), ccsds124_decompressor_init(), ccsds124_rle_decode(), ccsds124_update_build(), and ccsds124_update_mask().

◆ bitvector_left_shift()

void bitvector_left_shift ( bitvector_t result,
const bitvector_t a 
)

Left shift by one bit.

Shifts all bits left, inserting 0 at LSB position.

Parameters
[out]resultResult vector (result = a << 1)
[in]aOperand

Definition at line 178 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_compress_packet().

◆ bitvector_not()

void bitvector_not ( bitvector_t result,
const bitvector_t a 
)

Bitwise NOT operation.

Parameters
[out]resultResult vector (result = NOT a)
[in]aOperand

Definition at line 144 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_compress_packet().

◆ bitvector_or()

void bitvector_or ( bitvector_t result,
const bitvector_t a,
const bitvector_t b 
)

Bitwise OR operation.

Parameters
[out]resultResult vector (result = a OR b)
[in]aFirst operand
[in]bSecond operand

Definition at line 110 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_compress_packet(), ccsds124_decompress_packet_internal(), ccsds124_update_build(), and ccsds124_update_mask().

◆ bitvector_reverse()

void bitvector_reverse ( bitvector_t result,
const bitvector_t a 
)

Reverse bit order.

Reverses the bit order: MSB becomes LSB and vice versa. CCSDS notation: result =

Parameters
[out]resultResult vector with reversed bits
[in]aOperand

Definition at line 200 of file bitvector.c.

References bitvector_get_bit(), bitvector_set_bit(), bitvector_zero(), length, and num_words.

◆ bitvector_set_bit()

static void bitvector_set_bit ( bitvector_t bv,
size_t  pos,
int  value 
)
inlinestatic

Set bit value at position (inline for performance).

Parameters
[out]bvBit vector to modify
[in]posBit position (0 = LSB, length-1 = MSB)
[in]valueBit value (0 or 1)

Definition at line 188 of file ccsds124.h.

References data.

Referenced by bitvector_reverse(), ccsds124_bit_insert(), ccsds124_decompress_packet_internal(), and ccsds124_rle_decode().

◆ bitvector_to_bytes()

int bitvector_to_bytes ( const bitvector_t bv,
uint8_t *  data,
size_t  num_bytes 
)

Store bit vector to byte array.

Stores bytes in big-endian order (first byte contains MSB bits).

Parameters
[in]bvBit vector to store
[out]dataDestination byte array
[in]num_bytesNumber of bytes to store
Returns
CCSDS124_OK on success

Definition at line 311 of file bitvector.c.

References CCSDS124_ERROR_INVALID_ARG, CCSDS124_ERROR_UNDERFLOW, CCSDS124_OK, data, length, and num_words.

Referenced by ccsds124_decompress().

◆ bitvector_xor()

void bitvector_xor ( bitvector_t result,
const bitvector_t a,
const bitvector_t b 
)

Bitwise XOR operation.

Parameters
[out]resultResult vector (result = a XOR b)
[in]aFirst operand
[in]bSecond operand

Definition at line 93 of file bitvector.c.

References data, length, and num_words.

Referenced by ccsds124_compress_packet(), ccsds124_compute_change(), ccsds124_update_build(), and ccsds124_update_mask().

◆ bitvector_zero()

void bitvector_zero ( bitvector_t bv)