pub fn decode_bf(&self, input: &[u8], output: &mut [u8],
                     working: &mut [u8], maxiters: usize)
        -> (bool, usize)
    {
        assert_eq!(input.len(), self.n()/8, "input.len() != n/8");
        assert_eq!(output.len(), self.output_len(), "output.len != (n+p)/8");
        assert_eq!(working.len(), self.decode_bf_working_len(), "working.len() incorrect");

        output[..self.n()/8].copy_from_slice(input);

        // For punctured codes we must first try and fix all the punctured bits.
        // We run them through an erasure decoding algorithm and record how many iterations
        // it took (so we can return the total).
        let erasure_iters = if self.punctured_bits() > 0 {
            let (_, iters) = self.decode_erasures(output, working, maxiters);
            iters
        } else { 0 };

        // Working area: we use the top bit of the first k bytes to store that parity check,
        // and the remaining 7 bits of the first n+p bytes to store violation count for that var.

        for iter in 0..maxiters {
            // Zero out violation counts
            for v in &mut working[..] { *v = 0 }

            // Calculate the parity of each parity check
            for (check, var) in self.iter_paritychecks() {
                if output[var/8] >> (7-(var%8)) & 1 == 1 {
                    working[check] ^= 0x80;
                }
            }

            // Count how many parity violations each variable is associated with
            let mut max_violations = 0;
            for (check, var) in self.iter_paritychecks() {
                if working[check] & 0x80 == 0x80 {
                    // Unless we have more than 127 checks for a single variable, this
                    // can't overflow into the parity bit. And we don't have that.
                    working[var] += 1;
                    if working[var] & 0x7F > max_violations {
                        max_violations = working[var] & 0x7F;
                    }
                }
            }

            if max_violations == 0 {
                return (true, iter + erasure_iters);
            } else {
                // Flip all the bits that have the maximum number of violations
                for (var, violations) in working.iter().enumerate() {
                    if *violations & 0x7F == max_violations {
                        output[var/8] ^= 1<<(7-(var%8));
                    }
                }
            }
        }

        (false, maxiters + erasure_iters)
    }
/// Bit flipping decoder.
///
/// This algorithm is quick but only operates on hard information and consequently leaves a
/// lot of error-correcting capability behind. It is around 1-2dB worse than the min-sum
/// decoder. However, it requires much less memory and is a lot quicker.
///
/// Requires:
///
/// * `input` must be `n/8` long, where each bit is the received hard information
/// * `output` must be `(n+punctured_bits)/8` (=`self.output_len()`) bytes long and is written
///   with the decoded codeword, so the user data is present in the first `k/8` bytes.
/// * `working` must be `n+punctured_bits` (=`self.decode_bf_working_len()`) bytes long.
///
/// Runs for at most `maxiters` iterations, both when attempting to fix punctured erasures on
/// applicable codes, and in the main bit flipping decoder.
///
/// Returns `(decoding success, iters)`. For punctured codes, `iters` includes iterations
/// of the erasure decoding algorithm which is run first.
Bit flipping decoder.
This algorithm is quick but only operates on hard information and consequently leaves a
lot of error-correcting capability behind. It is around 1-2dB worse than the min-sum
decoder. However, it requires much less memory and is a lot quicker.





Runs for at most `maxiters` iterations, both when attempting to fix punctured erasures on
applicable codes, and in the main bit flipping decoder.

Returns `(decoding success, iters)`. For punctured codes, `iters` includes iterations
of the erasure decoding algorithm which is run first.
Bit flipping decoder . This algorithm is quick but only operates on hard information and consequently leaves a lot of error - correcting capability behind . It is around 1 - 2dB worse than the min - sum decoder . However it requires much less memory and is a lot quicker . Runs for at most ` maxiters ` iterations both when attempting to fix punctured erasures on applicable codes and in the main bit flipping decoder . Returns ` ( decoding success iters ) ` . For punctured codes ` iters ` includes iterations of the erasure decoding algorithm which is run first .
pub fn decode_bf(&self, input: &[u8], output: &mut [u8],
                     working: &mut [u8], maxiters: usize)
        -> (bool, usize)
    {
        assert_eq!(input.len(), self.n()/8, "input.len() != n/8");
        assert_eq!(output.len(), self.output_len(), "output.len != (n+p)/8");
        assert_eq!(working.len(), self.decode_bf_working_len(), "working.len() incorrect");
        output[..self.n()/8].copy_from_slice(input);
        // For punctured codes we must first try and fix all the punctured bits.
        // We run them through an erasure decoding algorithm and record how many iterations
        // it took (so we can return the total).
        let erasure_iters = if self.punctured_bits() > 0 {
            let (_, iters) = self.decode_erasures(output, working, maxiters);
            iters
        } else { 0 };
        // Working area: we use the top bit of the first k bytes to store that parity check,
        // and the remaining 7 bits of the first n+p bytes to store violation count for that var.
        for iter in 0..maxiters {
            // Zero out violation counts
            for v in &mut working[..] { *v = 0 }
            // Calculate the parity of each parity check
            for (check, var) in self.iter_paritychecks() {
                if output[var/8] >> (7-(var%8)) & 1 == 1 {
                    working[check] ^= 0x80;
                }
            }
            // Count how many parity violations each variable is associated with
            let mut max_violations = 0;
            for (check, var) in self.iter_paritychecks() {
                if working[check] & 0x80 == 0x80 {
                    // Unless we have more than 127 checks for a single variable, this
                    // can't overflow into the parity bit. And we don't have that.
                    working[var] += 1;
                    if working[var] & 0x7F > max_violations {
                        max_violations = working[var] & 0x7F;
                    }
                }
            }
            if max_violations == 0 {
                return (true, iter + erasure_iters);
            } else {
                // Flip all the bits that have the maximum number of violations
                for (var, violations) in working.iter().enumerate() {
                    if *violations & 0x7F == max_violations {
                        output[var/8] ^= 1<<(7-(var%8));
                    }
                }
            }
        }
        (false, maxiters + erasure_iters)
    }
pub fn decode_bf ( & self , input : & [ u8 ] , output : & mut [ u8 ] , working : & mut [ u8 ] , maxiters : usize ) -> ( bool , usize ) { assert_eq ! ( input len ( ) self n ( ) 8 " " ) ; assert_eq ! ( output len ( ) self output_len ( ) " " ) ; assert_eq ! ( working len ( ) self decode_bf_working_len ( ) " " ) ; output [ .. self . n ( ) / 8 ] . copy_from_slice ( input ) ; // For punctured codes we must first try and fix all the punctured bits. // We run them through an erasure decoding algorithm and record how many iterations // it took (so we can return the total). let erasure_iters = if self . punctured_bits ( ) > 0 { let ( _ , iters ) = self . decode_erasures ( output , working , maxiters ) ; iters } else { 0 } ; // Working area: we use the top bit of the first k bytes to store that parity check, // and the remaining 7 bits of the first n+p bytes to store violation count for that var. for iter in 0 .. maxiters { // Zero out violation counts for v in & mut working [ .. ] { * v = 0 } // Calculate the parity of each parity check for ( check , var ) in self . iter_paritychecks ( ) { if output [ var / 8 ] >> ( 7 - ( var % 8 ) ) & 1 == 1 { working [ check ] ^= 0x80 ; } } // Count how many parity violations each variable is associated with let mut max_violations = 0 ; for ( check , var ) in self . iter_paritychecks ( ) { if working [ check ] & 0x80 == 0x80 { // Unless we have more than 127 checks for a single variable, this // can't overflow into the parity bit. And we don't have that. working [ var ] += 1 ; if working [ var ] & 0x7F > max_violations { max_violations = working [ var ] & 0x7F ; } } } if max_violations == 0 { return ( true , iter + erasure_iters ) ; } else { // Flip all the bits that have the maximum number of violations for ( var , violations ) in working . iter ( ) . enumerate ( ) { if * violations & 0x7F == max_violations { output [ var / 8 ] ^= 1 << ( 7 - ( var % 8 ) ) ; } } } } ( false , maxiters + erasure_iters ) }
Bit flipping decoder.
Bit flipping decoder .
&self
input
&[u8]
output
&mut [u8]
working
&mut [u8]
maxiters
usize