Skip to main content

Crate simd_rs63

Crate simd_rs63 

Source
Expand description

Reed-Solomon erasure coding over GF(2⁸).

This crate implements a systematic RS(9, 6) code: stripes of N = 9 equal-sized blocks, of which K = 6 carry data and M = 3 are parity. Any combination of up to M lost blocks can be recovered from the remaining K blocks.

§Quick start

use reed_solomon::{encode, recover, K, M, BLOCK_ALIGNMENT};

let block_size = 4 * BLOCK_ALIGNMENT;

// Build K data blocks.
let data: Vec<Vec<u8>> = (0..K).map(|i| vec![i as u8; block_size]).collect();

// Encode: compute M parity blocks.
let mut parity: Vec<Vec<u8>> = vec![vec![0u8; block_size]; M];
encode(
    std::array::from_fn(|i| data[i].as_slice()),
    std::array::from_fn(|i| parity[i].as_mut_slice()),
).unwrap();

// Simulate losing data blocks 3, 4 and 5.
let mut r3 = vec![0u8; block_size];
let mut r4 = vec![0u8; block_size];
let mut r5 = vec![0u8; block_size];

// Recover them from the surviving blocks.
recover(
    [(0, data[0].as_slice()), (1, data[1].as_slice()), (2, data[2].as_slice()),
     (6, parity[0].as_slice()), (7, parity[1].as_slice()), (8, parity[2].as_slice())],
    [(3, &mut r3), (4, &mut r4), (5, &mut r5)],
).unwrap();

assert_eq!(r3, data[3]);
assert_eq!(r4, data[4]);
assert_eq!(r5, data[5]);

§Block sizes

All blocks in a call must be the same size, and that size must be a positive multiple of BLOCK_ALIGNMENT. On this platform BLOCK_ALIGNMENT is chosen to match the widest SIMD shuffle instruction available, so it varies by CPU (16 on NEON/SSSE3, 32 on AVX2, 64 on AVX-512 VBMI).

Enums§

Error
Errors returned by [encode] and [recover].

Constants§

BLOCK_ALIGNMENT
Required alignment for block sizes.
K
Number of data blocks per stripe.
M
Number of parity blocks per stripe.
N
Total number of blocks per stripe (data + parity).

Functions§

encode
Computes the M parity blocks from K data blocks.
recover
Recovers up to M missing blocks from any K known blocks.