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 simd_rs63::{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![0u8; block_size], vec![0u8; block_size], vec![0u8; block_size]];
let [p0, p1, p2] = &mut parity;
encode(
std::array::from_fn(|i| data[i].as_slice()),
[p0.as_mut_slice(), p1.as_mut_slice(), p2.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).