Skip to main content

ErasureCode

Struct ErasureCode 

Source
pub struct ErasureCode { /* private fields */ }
Expand description

The ErasureCode struct is used to encode and decode data using erasure codes.

It is a wrapper around the Jerasure library, which provides efficient implementations of various erasure coding techniques.

Implementations§

Source§

impl ErasureCode

Source

pub fn k(&self) -> i32

Return the number of data devices.

Source

pub fn m(&self) -> i32

Return the number of parity devices.

Source

pub fn w(&self) -> CodeWord

Return the code word size.

Source

pub fn tech(&self) -> Technique

Return the coding method.

Source

pub fn encode<T: AsRef<[u8]>, U: AsMut<[u8]>>( &self, data: impl AsRef<[T]>, code: impl AsMut<[U]>, ) -> Result<(), Error>

Encode the data and generate coding parity.

§Arguments
  • data - The data to encode, which must be a slice of k buffers of the same length.
  • code - The buffer to store the coding parity, which must be a slice of m buffers of the same length.
§Requires
  • All the buffers must be aligned to the machine long size, and be the same length.
Source

pub fn decode<T: AsMut<[u8]>>( &self, data: impl AsMut<[T]>, code: impl AsMut<[T]>, erased: &[i32], ) -> Result<(), Error>

Decode the data and recover the erased data.

§Arguments
  • data - The data devices, which must be a slice of k buffers of the same length.
  • code - The coding devices, which must be a slice of m buffers of the same length.
  • erased - The indices of the erased data devices, which must be a slice of integers. The k data devices are indexed 0..k, and the m coding devices are indexed k..k+m.
§Requires
  • All the buffers must be aligned to the machine long size, and be the same length.
  • The erased indices must be in the range of 0..k+m.
  • The number of erased indices must be less than or equal to m.
  • The erased indices must be unique.
§Note

The erased devices may not be recovered even if the number of erased devices is less than or equal to m. This is because the coding matrix may not be full rank with large k and m. In this case, the function will return an error.

Auto Trait Implementations§

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> 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, 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.