CCSDS 124.0-B-1 C++ 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
mask.hpp
Go to the documentation of this file.
1
27#ifndef CCSDS124_MASK_HPP
28#define CCSDS124_MASK_HPP
29
30#include "bitvector.hpp"
31#include "config.hpp"
32#include "error.hpp"
33
34namespace ccsds124 {
35
52template <std::size_t N>
53void update_build(BitVector<N>& build, const BitVector<N>& input, const BitVector<N>& prev_input,
54 bool new_mask_flag, std::size_t t) noexcept {
55 if (t == 0 || new_mask_flag) {
56 // Case 1: t=0 or new_mask_flag set -> reset build to 0
57 build.zero();
58 } else {
59 // Case 2: Normal operation (t > 0 and new_mask_flag = 0)
60 // B_t = (I_t XOR I_{t-1}) OR B_{t-1}
61 // Optimized: compute in-place without temporary allocation
62 for (std::size_t w = 0; w < BitVector<N>::NUM_WORDS; ++w) {
63 build.data()[w] |= (input.data()[w] ^ prev_input.data()[w]);
64 }
65 }
66}
67
83template <std::size_t N>
84void update_mask(BitVector<N>& mask, const BitVector<N>& input, const BitVector<N>& prev_input,
85 const BitVector<N>& build_prev, bool new_mask_flag) noexcept {
86 // Optimized: compute in-place without temporary allocation
87 if (new_mask_flag) {
88 // Case 1: new_mask_flag set -> M_t = (I_t XOR I_{t-1}) OR B_{t-1}
89 for (std::size_t w = 0; w < BitVector<N>::NUM_WORDS; ++w) {
90 mask.data()[w] = (input.data()[w] ^ prev_input.data()[w]) | build_prev.data()[w];
91 }
92 } else {
93 // Case 2: Normal operation -> M_t = (I_t XOR I_{t-1}) OR M_{t-1}
94 for (std::size_t w = 0; w < BitVector<N>::NUM_WORDS; ++w) {
95 mask.data()[w] |= (input.data()[w] ^ prev_input.data()[w]);
96 }
97 }
98}
99
114template <std::size_t N>
115void compute_change(BitVector<N>& change, const BitVector<N>& mask, const BitVector<N>& prev_mask,
116 std::size_t t) noexcept {
117 if (t == 0) {
118 // CCSDS Eq. 8: D_0 = 0 — no change at initialization; both encoder
119 // and decoder start from the same user-specified M_0
120 change.zero();
121 } else {
122 // D_t = M_t XOR M_{t-1}
123 change.xor_with(mask, prev_mask);
124 }
125}
126
127} // namespace ccsds124
128
129#endif // CCSDS124_MASK_HPP
Fixed-length bit vector with static allocation.
Fixed-length bit vector with compile-time size.
Definition bitvector.hpp:90
CCSDS 124.0-B-1 compile-time configuration.
CCSDS 124.0-B-1 error handling.
void compute_change(BitVector< N > &change, const BitVector< N > &mask, const BitVector< N > &prev_mask, std::size_t t) noexcept
Compute change vector (CCSDS Equation 8).
Definition mask.hpp:115
void update_mask(BitVector< N > &mask, const BitVector< N > &input, const BitVector< N > &prev_input, const BitVector< N > &build_prev, bool new_mask_flag) noexcept
Update mask vector (CCSDS Equation 7).
Definition mask.hpp:84
void update_build(BitVector< N > &build, const BitVector< N > &input, const BitVector< N > &prev_input, bool new_mask_flag, std::size_t t) noexcept
Update build vector (CCSDS Equation 6).
Definition mask.hpp:53