pub struct ReedSolomon<F: Field> { /* private fields */ }Implementations§
Source§impl<F: Field> ReedSolomon<F>
impl<F: Field> ReedSolomon<F>
Sourcepub fn new(
data_shards: usize,
parity_shards: usize,
) -> Result<ReedSolomon<F>, Error>
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.
Sourcepub fn with_options(
data_shards: usize,
parity_shards: usize,
options: CodecOptions,
) -> Result<ReedSolomon<F>, Error>
pub fn with_options( data_shards: usize, parity_shards: usize, options: CodecOptions, ) -> Result<ReedSolomon<F>, Error>
Create a new codec with explicit CodecOptions.
Sourcepub fn data_shard_count(&self) -> usize
pub fn data_shard_count(&self) -> usize
Returns the number of data shards.
Sourcepub fn parity_shard_count(&self) -> usize
pub fn parity_shard_count(&self) -> usize
Returns the number of parity shards.
Sourcepub fn total_shard_count(&self) -> usize
pub fn total_shard_count(&self) -> usize
Returns the total number of shards (data + parity).
Sourcepub fn codec_family(&self) -> CodecFamily
pub fn codec_family(&self) -> CodecFamily
Returns the codec family (Classic, LeopardGF8, or LeopardGF16).
Sourcepub fn leopard_setup_matrix_shape(&self) -> Option<(usize, usize)>
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.
Sourcepub fn inversion_cache_capacity(&self) -> usize
pub fn inversion_cache_capacity(&self) -> usize
Returns the inversion cache capacity.
Sourcepub fn recommended_inversion_cache_capacity(
data_shards: usize,
parity_shards: usize,
) -> usize
pub fn recommended_inversion_cache_capacity( data_shards: usize, parity_shards: usize, ) -> usize
Returns the recommended inversion cache capacity for the given shard counts.
Sourcepub fn reconstruction_cache_stats(&self) -> ReconstructionCacheStats
pub fn reconstruction_cache_stats(&self) -> ReconstructionCacheStats
Returns a snapshot of reconstruction cache hit/miss statistics.
Sourcepub fn runtime_profile_stats(&self) -> RuntimeProfileStats
pub fn runtime_profile_stats(&self) -> RuntimeProfileStats
Returns a snapshot of runtime profiling metrics.
Sourcepub fn reset_runtime_profile_stats(&self)
pub fn reset_runtime_profile_stats(&self)
Resets all runtime profiling counters to zero.
Sourcepub fn split(&self, data: &[F::Elem]) -> Result<Vec<Vec<F::Elem>>, Error>
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.
Sourcepub fn join<T: AsRef<[F::Elem]>>(
&self,
shards: &[T],
out_len: usize,
) -> Result<Vec<F::Elem>, Error>
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.
Sourcepub fn with_custom_matrix(
data_shards: usize,
parity_shards: usize,
custom_matrix: &[Vec<F::Elem>],
options: CodecOptions,
) -> Result<ReedSolomon<F>, Error>
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>
impl<F: Field> ReedSolomon<F>
Sourcepub fn encode_single<T, U>(&self, i_data: usize, shards: T) -> Result<(), Error>
pub fn encode_single<T, U>(&self, i_data: usize, shards: T) -> Result<(), Error>
Encode one data shard into all parity shards.
Not supported for Leopard codec families.
Sourcepub fn encode_single_sep<U: AsRef<[F::Elem]> + AsMut<[F::Elem]>>(
&self,
i_data: usize,
single_data: &[F::Elem],
parity: &mut [U],
) -> Result<(), Error>
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.
Sourcepub fn encode<T, U>(&self, shards: T) -> Result<(), Error>
pub fn encode<T, U>(&self, shards: T) -> Result<(), Error>
Encode data shards in-place, filling parity shards.
The first data_shard_count slices are data (read-only), the rest are parity (written).
Sourcepub fn encode_sep<T: AsRef<[F::Elem]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>>(
&self,
data: &[T],
parity: &mut [U],
) -> Result<(), Error>
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.
Sourcepub fn update<T, U>(
&self,
old_data: &[T],
new_data: &[Option<T>],
parity: &mut [U],
) -> Result<(), Error>
pub fn update<T, U>( &self, old_data: &[T], new_data: &[Option<T>], parity: &mut [U], ) -> Result<(), Error>
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.
Sourcepub fn encode_sep_par<T, U>(
&self,
data: &[T],
parity: &mut [U],
) -> Result<(), Error>
pub fn encode_sep_par<T, U>( &self, data: &[T], parity: &mut [U], ) -> Result<(), Error>
Parallel version of encode_sep.
Sourcepub fn encode_single_sep_par<U>(
&self,
i_data: usize,
single_data: &[F::Elem],
parity: &mut [U],
) -> Result<(), Error>
pub fn encode_single_sep_par<U>( &self, i_data: usize, single_data: &[F::Elem], parity: &mut [U], ) -> Result<(), Error>
Parallel version of encode_single_sep.
Sourcepub fn encode_single_sep_opt<U>(
&self,
i_data: usize,
single_data: &[F::Elem],
parity: &mut [U],
) -> Result<(), Error>
pub fn encode_single_sep_opt<U>( &self, i_data: usize, single_data: &[F::Elem], parity: &mut [U], ) -> Result<(), Error>
Auto-parallelizing version of encode_single_sep.
Uses the parallel policy to choose between serial and parallel execution.
Sourcepub fn encode_single_opt<T, U>(
&self,
i_data: usize,
shards: T,
) -> Result<(), Error>
pub fn encode_single_opt<T, U>( &self, i_data: usize, shards: T, ) -> Result<(), Error>
Auto-parallelizing version of encode_single.
Source§impl<F: Field> ReedSolomon<F>
impl<F: Field> ReedSolomon<F>
Sourcepub fn parallel_policy(
&self,
shard_len: usize,
output_shards: usize,
) -> ParallelDecision
pub fn parallel_policy( &self, shard_len: usize, output_shards: usize, ) -> ParallelDecision
Compute the parallel execution decision for the current codec and shard size.
Sourcepub fn parallel_policy_version(&self) -> u32
pub fn parallel_policy_version(&self) -> u32
Returns the parallel policy version number.
Sourcepub fn effective_parallel_policy(&self) -> ParallelPolicy
pub fn effective_parallel_policy(&self) -> ParallelPolicy
Returns the effective parallel policy (including cache-aware adjustments).
Source§impl<F: Field> ReedSolomon<F>
impl<F: Field> ReedSolomon<F>
Sourcepub fn reconstruct<T: ReconstructShard<F>>(
&self,
slices: &mut [T],
) -> Result<(), Error>
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.
Sourcepub fn reconstruct_data<T: ReconstructShard<F>>(
&self,
slices: &mut [T],
) -> Result<(), Error>
pub fn reconstruct_data<T: ReconstructShard<F>>( &self, slices: &mut [T], ) -> Result<(), Error>
Reconstruct only missing data shards (parity shards are not recovered).
Sourcepub fn reconstruct_some<T: ReconstructShard<F>>(
&self,
shards: &mut [T],
required: &[bool],
) -> Result<(), Error>
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>
impl ReedSolomon<Field>
Sourcepub fn encode_stream(
&self,
data: &mut [impl Read + Send],
parity: &mut [impl Write + Send],
options: &StreamOptions,
) -> Result<(), StreamError>
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.
Sourcepub fn verify_stream(
&self,
shards: &mut [impl Read + Send],
options: &StreamOptions,
) -> Result<bool, StreamError>
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.
Sourcepub fn reconstruct_stream(
&self,
shards: &mut [Cursor<Vec<u8>>],
options: &StreamOptions,
) -> Result<(), StreamError>
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>
impl<F: Field> ReedSolomon<F>
Sourcepub fn verify<T: AsRef<[F::Elem]>>(&self, slices: &[T]) -> Result<bool, Error>
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.
Sourcepub fn verify_with_workspace<T>(
&self,
slices: &[T],
workspace: &mut VerifyWorkspace<F>,
) -> Result<bool, Error>
pub fn verify_with_workspace<T>( &self, slices: &[T], workspace: &mut VerifyWorkspace<F>, ) -> Result<bool, Error>
Verify using a pre-allocated VerifyWorkspace to avoid repeated allocation.
Sourcepub fn verify_with_buffer<T, U>(
&self,
slices: &[T],
buffer: &mut [U],
) -> Result<bool, Error>
pub fn verify_with_buffer<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
Verify using a caller-provided scratch buffer.
Sourcepub fn verify_with_buffer_par<T, U>(
&self,
slices: &[T],
buffer: &mut [U],
) -> Result<bool, Error>
pub fn verify_with_buffer_par<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
Parallel version of verify_with_buffer.
Source§impl ReedSolomon<Field>
impl ReedSolomon<Field>
Sourcepub fn alloc_aligned(&self, shard_len: usize) -> Vec<AlignedShard>
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.
pub fn alloc_shard_slots(&self, shard_len: usize) -> Vec<ShardSlot<Vec<u8>>>
Source§impl ReedSolomon<Field>
impl ReedSolomon<Field>
Sourcepub fn prepare_reconstruct_opt_workspace(
&self,
shards: &[Option<Vec<u8>>],
) -> Result<OptionVecReconstructWorkspace, Error>
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.
Sourcepub fn reconstruct_opt_with_workspace(
&self,
shards: &mut [Option<Vec<u8>>],
workspace: &OptionVecReconstructWorkspace,
) -> Result<(), Error>
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.
pub fn encode_opt<T, U>(&self, shards: T) -> Result<(), Error>
pub fn encode_sep_opt<T, U>( &self, data: &[T], parity: &mut [U], ) -> Result<(), Error>
pub fn verify_opt<T>(&self, slices: &[T]) -> Result<bool, Error>
pub fn verify_with_buffer_opt<T, U>( &self, slices: &[T], buffer: &mut [U], ) -> Result<bool, Error>
pub fn verify_with_workspace_opt( &self, slices: &[Vec<u8>], workspace: &mut VerifyWorkspace<Field>, ) -> Result<bool, Error>
pub fn reconstruct_opt( &self, shards: &mut [Option<Vec<u8>>], ) -> Result<(), Error>
pub fn reconstruct_data_opt( &self, shards: &mut [Option<Vec<u8>>], ) -> Result<(), Error>
pub fn reconstruct_some_opt( &self, shards: &mut [Option<Vec<u8>>], required: &[bool], ) -> Result<(), Error>
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>
impl<F: Field> Clone for ReedSolomon<F>
Source§fn clone(&self) -> ReedSolomon<F>
fn clone(&self) -> ReedSolomon<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<F> !Freeze for ReedSolomon<F>
impl<F> !RefUnwindSafe for ReedSolomon<F>
impl<F> Send for ReedSolomon<F>
impl<F> Sync for ReedSolomon<F>
impl<F> Unpin for ReedSolomon<F>
impl<F> UnsafeUnpin for ReedSolomon<F>
impl<F> UnwindSafe for ReedSolomon<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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