pub struct ReedSolomon { /* private fields */ }Expand description
A systematic Reed-Solomon erasure code with k data shards and m = n − k parity
shards. Cheap to clone (holds only the n×k generator matrix); construct once with
ReedSolomon::new and reuse across many messages of the same shape.
Implementations§
Source§impl ReedSolomon
impl ReedSolomon
Sourcepub fn new(data_shards: usize, parity_shards: usize) -> Option<Self>
pub fn new(data_shards: usize, parity_shards: usize) -> Option<Self>
Build a code with data_shards data shards and parity_shards parity shards.
Returns None if the parameters are out of range: both counts must be at least
one and the total n = data + parity must fit the field’s distinct nodes
(n ≤ 256). The construction is deterministic — same parameters, same code.
Sourcepub fn data_shards(&self) -> usize
pub fn data_shards(&self) -> usize
The number of data shards k.
Sourcepub fn parity_shards(&self) -> usize
pub fn parity_shards(&self) -> usize
The number of parity shards m = n − k.
Sourcepub fn total_shards(&self) -> usize
pub fn total_shards(&self) -> usize
The total number of shards n = k + m.
Sourcepub fn encode(&self, data: &[Vec<u8>]) -> Option<Vec<Vec<u8>>>
pub fn encode(&self, data: &[Vec<u8>]) -> Option<Vec<Vec<u8>>>
Encode k equal-length data shards into n shards. The first k outputs are the
data shards unchanged (the code is systematic); the remaining m are parity.
Returns None unless exactly k shards of equal length are supplied.
Sourcepub fn reconstruct(&self, shards: &[Option<Vec<u8>>]) -> Option<Vec<Vec<u8>>>
pub fn reconstruct(&self, shards: &[Option<Vec<u8>>]) -> Option<Vec<Vec<u8>>>
Reconstruct all n shards from a slice of n slots, each Some(shard) if the
shard survived or None if it was erased. Succeeds when at least k shards
survive (and share a length); returns None otherwise. The result is the full,
byte-exact set of n shards — recovered data in 0..k, regenerated parity after.
Trait Implementations§
Source§impl Clone for ReedSolomon
impl Clone for ReedSolomon
Source§fn clone(&self) -> ReedSolomon
fn clone(&self) -> ReedSolomon
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more