pub struct Repair { /* private fields */ }Expand description
Incremental, I/O-free PAR2 repair over slices held in memory.
Load recovery rows, feed every present input slice once,
then solve for the missing ones. Each feed XOR-accumulates
c_i^exp_e × D_i into every recovery row e, so the slices can arrive in
any order and need not be kept after they are fed.
A fed slice cannot be removed. Feeding a corrupt slice makes every solved
slice wrong, so verify slices first (see
SliceHasher and
Par2File::slice_matches).
Slice indices are global: they run across the set’s files in the Main
packet’s file order. BlockMap converts between global indices and file
positions.
Implementations§
Source§impl Repair
impl Repair
Sourcepub fn new(
recovery: &[RecoveryBlock],
slice_size: usize,
total_input_slices: usize,
) -> Result<Self, RepairError>
pub fn new( recovery: &[RecoveryBlock], slice_size: usize, total_input_slices: usize, ) -> Result<Self, RepairError>
Build from borrowed recovery blocks (their data is copied).
Sourcepub fn new_owning(
recovery: Vec<RecoveryBlock>,
slice_size: usize,
total_input_slices: usize,
) -> Result<Self, RepairError>
pub fn new_owning( recovery: Vec<RecoveryBlock>, slice_size: usize, total_input_slices: usize, ) -> Result<Self, RepairError>
Build from owned recovery blocks, reusing their buffers as the row accumulators.
Rows are sorted by exponent and duplicate exponents dropped. Every block
must be exactly slice_size bytes.
Sourcepub fn rows(&self) -> usize
pub fn rows(&self) -> usize
Number of recovery rows loaded: the most missing slices solve can
rebuild.
Sourcepub fn slice_size(&self) -> usize
pub fn slice_size(&self) -> usize
Slice size in bytes.
Sourcepub fn total_slices(&self) -> usize
pub fn total_slices(&self) -> usize
Total number of input slices in the set.
Sourcepub fn truncate_rows(&mut self, n: usize)
pub fn truncate_rows(&mut self, n: usize)
Keep only the first n rows (lowest exponents), freeing the rest.
Safe at any point: each row is an independent equation. solve only
uses as many rows as there are missing slices, so once that number is
known the others are dead weight.
Sourcepub fn feed(&mut self, index: usize, data: &[u8]) -> Result<(), RepairError>
pub fn feed(&mut self, index: usize, data: &[u8]) -> Result<(), RepairError>
Feed one present input slice.
data is the slice as stored: slice_size bytes, or fewer for the last
slice of a file, which is treated as zero-padded.
Sourcepub fn feed_batch(
&mut self,
slices: &[(usize, &[u8])],
) -> Result<(), RepairError>
pub fn feed_batch( &mut self, slices: &[(usize, &[u8])], ) -> Result<(), RepairError>
Feed several present slices at once.
Each row is updated against the whole batch while it is hot in cache, using the pair-batched SIMD path, so batches of a few dozen slices are much faster than the same slices fed one by one. The batch is validated before anything is accumulated: on error, nothing from it was fed.
Sourcepub fn solve(
&self,
missing: &[usize],
) -> Result<HashMap<usize, Vec<u8>>, RepairError>
pub fn solve( &self, missing: &[usize], ) -> Result<HashMap<usize, Vec<u8>>, RepairError>
Rebuild the missing slices.
Every slice must be either fed or listed in missing. Returns each
missing index mapped to its full slice_size bytes; the last slice of a
file comes back zero-padded, and the caller writes only its real length
(see BlockMap::global_to_file).
Uses the first missing.len() rows. Errors with
RepairError::InsufficientRecovery if there are fewer rows than
missing slices, and RepairError::SingularMatrix if the chosen rows
are linearly dependent.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Repair
impl RefUnwindSafe for Repair
impl Send for Repair
impl Sync for Repair
impl Unpin for Repair
impl UnsafeUnpin for Repair
impl UnwindSafe for Repair
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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