Skip to main content

ShardByShard

Struct ShardByShard 

Source
pub struct ShardByShard<'a, F: 'a + Field> { /* private fields */ }
Expand description

Bookkeeper for shard by shard encoding.

This is useful for avoiding incorrect use of encode_single and encode_single_sep

§Use cases

Shard by shard encoding is useful for streamed data encoding where you do not have all the needed data shards immediately, but you want to spread out the encoding workload rather than doing the encoding after everything is ready.

A concrete example would be network packets encoding, where encoding packet by packet as you receive them may be more efficient than waiting for N packets then encode them all at once.

§Example

use rustfs_erasure_codec::galois_8::Field;
let r: ReedSolomon<Field> = ReedSolomon::new(3, 2).unwrap();

let mut sbs = ShardByShard::new(&r);

let mut shards = shards!([0u8,  1,  2,  3,  4],
                         [5,  6,  7,  8,  9],
                         // say we don't have the 3rd data shard yet
                         // and we want to fill it in later
                         [0,  0,  0,  0,  0],
                         [0,  0,  0,  0,  0],
                         [0,  0,  0,  0,  0]);

// encode 1st and 2nd data shard
sbs.encode(&mut shards).unwrap();
sbs.encode(&mut shards).unwrap();

// fill in 3rd data shard
shards[2][0] = 10.into();
shards[2][1] = 11.into();
shards[2][2] = 12.into();
shards[2][3] = 13.into();
shards[2][4] = 14.into();

// now do the encoding
sbs.encode(&mut shards).unwrap();

assert!(r.verify(&shards).unwrap());

Implementations§

Source§

impl<'a, F: 'a + Field> ShardByShard<'a, F>

Source

pub fn new(codec: &'a ReedSolomon<F>) -> ShardByShard<'a, F>

Create a new shard-by-shard encoder.

Source

pub fn parity_ready(&self) -> bool

Returns true if all data shards have been encoded and parity is ready.

Source

pub fn reset(&mut self) -> Result<(), SBSError>

Reset to accept a new batch of data shards.

Returns SBSError::LeftoverShards if the previous batch was incomplete.

Source

pub fn reset_force(&mut self)

Force-reset without checking for leftover shards.

Source

pub fn cur_input_index(&self) -> usize

Returns the index of the next data shard expected.

Source

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

Encode the next data shard in the batch.

Source

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

Encode the next data shard using separate data and parity slices.

Trait Implementations§

Source§

impl<'a, F: Debug + 'a + Field> Debug for ShardByShard<'a, F>

Source§

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

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

impl<'a, F: PartialEq + 'a + Field> PartialEq for ShardByShard<'a, F>

Source§

fn eq(&self, other: &ShardByShard<'a, F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, F: PartialEq + 'a + Field> StructuralPartialEq for ShardByShard<'a, F>

Auto Trait Implementations§

§

impl<'a, F> !RefUnwindSafe for ShardByShard<'a, F>

§

impl<'a, F> !UnwindSafe for ShardByShard<'a, F>

§

impl<'a, F> Freeze for ShardByShard<'a, F>

§

impl<'a, F> Send for ShardByShard<'a, F>
where F: Sync, <F as Field>::Elem: Sync + Send,

§

impl<'a, F> Sync for ShardByShard<'a, F>
where F: Sync, <F as Field>::Elem: Sync + Send,

§

impl<'a, F> Unpin for ShardByShard<'a, F>

§

impl<'a, F> UnsafeUnpin for ShardByShard<'a, 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> 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, 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.