Skip to main content

ReedSolomon

Struct ReedSolomon 

Source
pub struct ReedSolomon<F: Field> { /* private fields */ }

Implementations§

Source§

impl<F: Field> ReedSolomon<F>

Source

pub fn new( data_shards: usize, parity_shards: usize, ) -> Result<ReedSolomon<F>, Error>

Create a new codec with default options.

Returns Error::TooFewDataShards or Error::TooFewParityShards if either count is zero, or Error::TooManyShards if the total exceeds the field order.

Source

pub fn with_options( data_shards: usize, parity_shards: usize, options: CodecOptions, ) -> Result<ReedSolomon<F>, Error>

Create a new codec with explicit CodecOptions.

Source

pub fn data_shard_count(&self) -> usize

Returns the number of data shards.

Source

pub fn parity_shard_count(&self) -> usize

Returns the number of parity shards.

Source

pub fn total_shard_count(&self) -> usize

Returns the total number of shards (data + parity).

Source

pub fn codec_family(&self) -> CodecFamily

Returns the codec family (Classic, LeopardGF8, or LeopardGF16).

Source

pub fn leopard_setup_matrix_shape(&self) -> Option<(usize, usize)>

Returns the Leopard GF8 setup matrix shape (rows, cols), or None if not using LeopardGF8.

Source

pub fn inversion_cache_capacity(&self) -> usize

Returns the inversion cache capacity.

Source

pub fn recommended_inversion_cache_capacity( data_shards: usize, parity_shards: usize, ) -> usize

Returns the recommended inversion cache capacity for the given shard counts.

Source

pub fn reconstruction_cache_stats(&self) -> ReconstructionCacheStats

Returns a snapshot of reconstruction cache hit/miss statistics.

Source

pub fn runtime_profile_stats(&self) -> RuntimeProfileStats

Returns a snapshot of runtime profiling metrics.

Source

pub fn reset_runtime_profile_stats(&self)

Resets all runtime profiling counters to zero.

Source

pub fn split(&self, data: &[F::Elem]) -> Result<Vec<Vec<F::Elem>>, Error>

Split a contiguous data buffer into data_shard_count equal-length shards.

The last shard is zero-padded if data.len() is not evenly divisible.

Source

pub fn join<T: AsRef<[F::Elem]>>( &self, shards: &[T], out_len: usize, ) -> Result<Vec<F::Elem>, Error>

Join data shards back into a single contiguous buffer.

Truncates to out_len bytes. Requires exactly data_shard_count shards.

Source

pub fn with_custom_matrix( data_shards: usize, parity_shards: usize, custom_matrix: &[Vec<F::Elem>], options: CodecOptions, ) -> Result<ReedSolomon<F>, Error>

Create a codec with a user-provided encoding matrix.

Source§

impl<F: Field> ReedSolomon<F>

Source

pub fn encode_single<T, U>(&self, i_data: usize, shards: T) -> Result<(), Error>
where T: AsRef<[U]> + AsMut<[U]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,

Encode one data shard into all parity shards.

Not supported for Leopard codec families.

Source

pub fn encode_single_sep<U: AsRef<[F::Elem]> + AsMut<[F::Elem]>>( &self, i_data: usize, single_data: &[F::Elem], parity: &mut [U], ) -> Result<(), Error>

Encode one data shard into separate parity slices.

Source

pub fn encode<T, U>(&self, shards: T) -> Result<(), Error>
where T: AsRef<[U]> + AsMut<[U]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,

Encode data shards in-place, filling parity shards.

The first data_shard_count slices are data (read-only), the rest are parity (written).

Source

pub fn encode_sep<T: AsRef<[F::Elem]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>>( &self, data: &[T], parity: &mut [U], ) -> Result<(), Error>

Encode from separate data and parity slices.

Source

pub fn update<T, U>( &self, old_data: &[T], new_data: &[Option<T>], parity: &mut [U], ) -> Result<(), Error>
where T: AsRef<[F::Elem]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,

Incrementally update parity shards when some data shards change.

old_data contains the previous data shards; new_data contains Some(new) for changed shards and None for unchanged ones. Not supported for Leopard families.

Source

pub fn encode_sep_par<T, U>( &self, data: &[T], parity: &mut [U], ) -> Result<(), Error>
where F::Elem: Send + Sync, T: AsRef<[F::Elem]> + Sync, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send,

Parallel version of encode_sep.

Source

pub fn encode_single_sep_par<U>( &self, i_data: usize, single_data: &[F::Elem], parity: &mut [U], ) -> Result<(), Error>
where F::Elem: Send + Sync, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send,

Parallel version of encode_single_sep.

Source

pub fn encode_single_sep_opt<U>( &self, i_data: usize, single_data: &[F::Elem], parity: &mut [U], ) -> Result<(), Error>
where F::Elem: Send + Sync, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send,

Auto-parallelizing version of encode_single_sep.

Uses the parallel policy to choose between serial and parallel execution.

Source

pub fn encode_single_opt<T, U>( &self, i_data: usize, shards: T, ) -> Result<(), Error>
where F::Elem: Send + Sync, T: AsRef<[U]> + AsMut<[U]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send,

Auto-parallelizing version of encode_single.

Source

pub fn encode_par<T, U>(&self, shards: T) -> Result<(), Error>
where F::Elem: Send + Sync, T: AsRef<[U]> + AsMut<[U]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send + Sync,

Parallel version of encode.

Source§

impl<F: Field> ReedSolomon<F>

Source

pub fn parallel_policy( &self, shard_len: usize, output_shards: usize, ) -> ParallelDecision

Compute the parallel execution decision for the current codec and shard size.

Source

pub fn parallel_policy_version(&self) -> u32

Returns the parallel policy version number.

Source

pub fn effective_parallel_policy(&self) -> ParallelPolicy

Returns the effective parallel policy (including cache-aware adjustments).

Source§

impl<F: Field> ReedSolomon<F>

Source

pub fn reconstruct<T: ReconstructShard<F>>( &self, slices: &mut [T], ) -> Result<(), Error>

Reconstruct all missing shards (data and parity).

Missing shards should be zero-length; present shards must have valid data.

Source

pub fn reconstruct_data<T: ReconstructShard<F>>( &self, slices: &mut [T], ) -> Result<(), Error>

Reconstruct only missing data shards (parity shards are not recovered).

Source

pub fn reconstruct_some<T: ReconstructShard<F>>( &self, shards: &mut [T], required: &[bool], ) -> Result<(), Error>

Reconstruct only shards marked true in the required mask.

Source§

impl ReedSolomon<Field>

Source

pub fn encode_stream( &self, data: &mut [impl Read + Send], parity: &mut [impl Write + Send], options: &StreamOptions, ) -> Result<(), StreamError>

Stream-encode data from readers into parity writers.

Reads data shards in blocks of options.block_size bytes, encodes each block, and writes the resulting parity blocks. This avoids loading the entire dataset into memory.

All data streams should supply the same number of bytes. When they do not, shorter streams are zero-padded to the longest stream’s length for each block, and no original-length metadata is persisted. The generated parity therefore only round-trips within this streaming API; interop with the in-memory API (which rejects unequal lengths with crate::Error::IncorrectShardSize) or with other Reed-Solomon implementations requires the caller to track the original shard lengths out of band.

§Errors

Returns StreamError on I/O failure or codec error.

§Limitations

Only the classic Reed-Solomon family is supported. Leopard-family codecs return crate::Error::UnsupportedCodecFamily (wrapped in a StreamError), because their FFT engines require whole-shard, 64-byte-aligned processing that the block-wise streaming path cannot satisfy.

Source

pub fn verify_stream( &self, shards: &mut [impl Read + Send], options: &StreamOptions, ) -> Result<bool, StreamError>

Stream-verify data + parity from readers.

Reads all shards in blocks, verifying each block independently. Returns Ok(true) if every block is valid, Ok(false) if any block fails verification.

§Limitations

Only the classic Reed-Solomon family is supported; Leopard-family codecs return crate::Error::UnsupportedCodecFamily.

Source

pub fn reconstruct_stream( &self, shards: &mut [Cursor<Vec<u8>>], options: &StreamOptions, ) -> Result<(), StreamError>

Stream-reconstruct missing shards.

shards has one entry per total shard. Present shards contain their data in a Cursor<Vec<u8>>; missing shards use an empty cursor (Cursor::new(Vec::new())). Recovered data is written into the missing shards’ cursors.

Present cursors are read from the beginning: their position is reset to 0 before reading, so it is safe to pass cursors that were just written to (whose position sits at the end).

The function reads blocks from present shards, reconstructs missing blocks, and writes recovered data into the missing cursors. The set of missing shard indices must be consistent across all blocks.

§Limitations

Only the classic Reed-Solomon family is supported; Leopard-family codecs return crate::Error::UnsupportedCodecFamily rather than silently producing incorrect results.

Source§

impl<F: Field> ReedSolomon<F>

Source

pub fn verify<T: AsRef<[F::Elem]>>(&self, slices: &[T]) -> Result<bool, Error>

Verify that parity shards are consistent with data shards.

Returns true if valid, false if corrupted.

Source

pub fn verify_with_workspace<T>( &self, slices: &[T], workspace: &mut VerifyWorkspace<F>, ) -> Result<bool, Error>
where T: AsRef<[F::Elem]>,

Verify using a pre-allocated VerifyWorkspace to avoid repeated allocation.

Source

pub fn verify_with_buffer<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
where T: AsRef<[F::Elem]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,

Verify using a caller-provided scratch buffer.

Source

pub fn verify_with_buffer_par<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
where F::Elem: Send + Sync, T: AsRef<[F::Elem]> + Sync, U: AsRef<[F::Elem]> + AsMut<[F::Elem]> + Send,

Parallel version of verify_with_buffer.

Source

pub fn verify_par<T>(&self, slices: &[T]) -> Result<bool, Error>
where F::Elem: Send + Sync, T: AsRef<[F::Elem]> + Sync,

Parallel version of verify.

Source§

impl ReedSolomon<Field>

Source

pub fn alloc_aligned(&self, shard_len: usize) -> Vec<AlignedShard>

Allocates one 64-byte-aligned shard per shard slot (data + parity), each shard_len bytes.

The buffers work with either Leopard family. Size shard_len with leopard_aligned_shard_len so the length is a non-zero multiple of 64 as Leopard requires.

Source

pub fn alloc_shard_slots(&self, shard_len: usize) -> Vec<ShardSlot<Vec<u8>>>

Source§

impl ReedSolomon<Field>

Source

pub fn prepare_reconstruct_opt_workspace( &self, shards: &[Option<Vec<u8>>], ) -> Result<OptionVecReconstructWorkspace, Error>

Prepare a reusable reconstruct workspace for an Option<Vec<u8>> shard layout.

The workspace is only valid for subsequent calls that keep the same missing-shard pattern and shard length.

Source

pub fn reconstruct_opt_with_workspace( &self, shards: &mut [Option<Vec<u8>>], workspace: &OptionVecReconstructWorkspace, ) -> Result<(), Error>

Execute reconstruct using a previously prepared workspace.

This skips the per-call option-vec planning pass, but the caller must provide shards with the same missing-index layout and shard length as the one used to prepare workspace.

Source

pub fn encode_opt<T, U>(&self, shards: T) -> Result<(), Error>
where T: AsRef<[U]> + AsMut<[U]>, U: AsRef<[u8]> + AsMut<[u8]> + Send + Sync,

Source

pub fn encode_sep_opt<T, U>( &self, data: &[T], parity: &mut [U], ) -> Result<(), Error>
where T: AsRef<[u8]> + Sync, U: AsRef<[u8]> + AsMut<[u8]> + Send,

Source

pub fn verify_opt<T>(&self, slices: &[T]) -> Result<bool, Error>
where T: AsRef<[u8]> + Sync,

Source

pub fn verify_with_buffer_opt<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
where T: AsRef<[u8]> + Sync, U: AsRef<[u8]> + AsMut<[u8]> + Send,

Source

pub fn verify_with_workspace_opt( &self, slices: &[Vec<u8>], workspace: &mut VerifyWorkspace<Field>, ) -> Result<bool, Error>

Source

pub fn reconstruct_opt( &self, shards: &mut [Option<Vec<u8>>], ) -> Result<(), Error>

Source

pub fn reconstruct_data_opt( &self, shards: &mut [Option<Vec<u8>>], ) -> Result<(), Error>

Source

pub fn reconstruct_some_opt( &self, shards: &mut [Option<Vec<u8>>], required: &[bool], ) -> Result<(), Error>

Source

pub fn decode_idx( &self, dst: &mut [Option<Vec<u8>>], expect_input: Option<&[bool]>, input: &[Option<Vec<u8>>], ) -> Result<(), Error>

Trait Implementations§

Source§

impl<F: Field> Clone for ReedSolomon<F>

Source§

fn clone(&self) -> ReedSolomon<F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Field> Debug for ReedSolomon<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Field> PartialEq for ReedSolomon<F>

Source§

fn eq(&self, rhs: &ReedSolomon<F>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<F> !Freeze for ReedSolomon<F>

§

impl<F> !RefUnwindSafe for ReedSolomon<F>

§

impl<F> Send for ReedSolomon<F>
where <F as Field>::Elem: Send + Sync, F: Send,

§

impl<F> Sync for ReedSolomon<F>
where F: Sync, <F as Field>::Elem: Sync + Send,

§

impl<F> Unpin for ReedSolomon<F>
where F: Unpin, <F as Field>::Elem: Unpin,

§

impl<F> UnsafeUnpin for ReedSolomon<F>
where <F as Field>::Elem: UnsafeUnpin,

§

impl<F> UnwindSafe for ReedSolomon<F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.