pub struct Coder { /* private fields */ }Expand description
An erasure coder for one (matrix) configuration: k source shards in,
p parity shards out, recovery from any k survivors.
Construction expands the parity coefficients into ISA-L-layout tables once; encode/update/recover then run with zero allocations on the data path (recover allocates only its small decode-matrix scratch).
Implementations§
Source§impl Coder
impl Coder
Sourcepub fn new(matrix: Matrix) -> Result<Coder, MatrixError>
pub fn new(matrix: Matrix) -> Result<Coder, MatrixError>
Build a coder from an encode matrix (rows = k + p, cols = k, top
block identity — what Matrix::reed_solomon / Matrix::cauchy
produce). A matrix with no parity rows is a dimension error.
This constructor uses the scalar kernel set — core carries no
detection machinery. The rusty_erasure facade’s coder() picks the
best SIMD set for the running CPU via Coder::with_kernels; prefer
it in applications.
Sourcepub fn with_kernels(
matrix: Matrix,
kernels: Kernels,
) -> Result<Coder, MatrixError>
pub fn with_kernels( matrix: Matrix, kernels: Kernels, ) -> Result<Coder, MatrixError>
Build a coder driving an explicit kernel set (see Kernels).
Sourcepub fn kernels(&self) -> &Kernels
pub fn kernels(&self) -> &Kernels
The kernel set this coder drives (name is useful for reporting).
Sourcepub fn gftbls(&self) -> &[u8] ⓘ
pub fn gftbls(&self) -> &[u8] ⓘ
The expanded parity tables, in THIS coder’s kernel-set format
(kernels().table_bytes per coefficient — ISA-L nibble layout for the
scalar/PSHUFB sets, affine matrices for GFNI). Exposed for the compat
layer and the conformance tests.
Sourcepub fn encode(
&self,
data: &[&[u8]],
parity: &mut [&mut [u8]],
) -> Result<(), CodeError>
pub fn encode( &self, data: &[&[u8]], parity: &mut [&mut [u8]], ) -> Result<(), CodeError>
Encode: k equal-length source shards in, p parity shards out
(overwritten). Byte-identical to ISA-L ec_encode_data.
Sourcepub fn update(
&self,
shard_index: usize,
data: &[u8],
parity: &mut [&mut [u8]],
) -> Result<(), CodeError>
pub fn update( &self, shard_index: usize, data: &[u8], parity: &mut [&mut [u8]], ) -> Result<(), CodeError>
Incremental encode: fold ONE source shard (index shard_index) into
all parity shards. Starting from zeroed parity buffers and calling this
once per source (any order) yields byte-identical output to
Coder::encode — ISA-L ec_encode_data_update semantics.
Sourcepub fn verify(
&self,
data: &[&[u8]],
parity: &[&[u8]],
) -> Result<bool, CodeError>
pub fn verify( &self, data: &[&[u8]], parity: &[&[u8]], ) -> Result<bool, CodeError>
Check that parity is consistent with data. Ok(true) means every
parity shard matches a fresh encode.
Sourcepub fn decode_plan(
&self,
present: &[bool],
rebuild: &[usize],
) -> Result<DecodePlan, RecoverError>
pub fn decode_plan( &self, present: &[bool], rebuild: &[usize], ) -> Result<DecodePlan, RecoverError>
Prepare a reusable decode plan for one loss pattern: which shards are
present (present[i]), and which indices to rebuild. The expensive,
data-independent work — survivor selection, submatrix inversion,
coefficient composition, table expansion — happens ONCE here;
Coder::recover_with then rebuilds any number of stripes with that
pattern at pure kernel cost (repair jobs and steady-state degraded
reads reuse one plan across every stripe).
Sourcepub fn recover_with(
&self,
plan: &DecodePlan,
shards: &[Option<&[u8]>],
out: &mut [&mut [u8]],
) -> Result<(), RecoverError>
pub fn recover_with( &self, plan: &DecodePlan, shards: &[Option<&[u8]>], out: &mut [&mut [u8]], ) -> Result<(), RecoverError>
Rebuild one stripe with a prepared DecodePlan — pure kernel cost,
no matrix work, no table expansion, one small scratch collection.
Sourcepub fn recover(
&self,
shards: &[Option<&[u8]>],
rebuild: &[usize],
out: &mut [&mut [u8]],
) -> Result<(), RecoverError>
pub fn recover( &self, shards: &[Option<&[u8]>], rebuild: &[usize], out: &mut [&mut [u8]], ) -> Result<(), RecoverError>
Rebuild shards from survivors.
shards is the full stripe in index order — k sources then p
parity — with None for anything lost. rebuild names the shard
indices to reconstruct (source or parity), and out supplies one
equal-length buffer per rebuild target. Any k present shards suffice;
fewer is RecoverError::TooManyMissing.
For many stripes with one loss pattern, build a Coder::decode_plan
once and use Coder::recover_with — this one-shot form re-derives
the decode matrix every call.