Skip to main content

ClayCode

Struct ClayCode 

Source
pub struct ClayCode {
    pub k: usize,
    pub m: usize,
    pub n: usize,
    pub d: usize,
    pub q: usize,
    pub t: usize,
    pub nu: usize,
    pub sub_chunk_no: usize,
    pub beta: usize,
    /* private fields */
}
Expand description

Clay (Coupled-Layer) erasure code

Fields§

§k: usize

Number of data chunks

§m: usize

Number of parity chunks

§n: usize

Total nodes (k + m)

§d: usize

Number of helper nodes for repair (k <= d <= n-1)

§q: usize

Coupling factor: q = d - k + 1

§t: usize

Number of y-sections: t = (n + nu) / q

§nu: usize

Shortening parameter: makes (k + m + nu) divisible by q

§sub_chunk_no: usize

Sub-packetization level: α = q^t (sub-chunks per chunk)

§beta: usize

Sub-chunks needed from each helper during repair: β = α / q

Implementations§

Source§

impl ClayCode

Source

pub fn new(k: usize, m: usize, d: usize) -> Result<Self, ClayError>

Create a new Clay code with parameters (k, m, d)

§Parameters
  • k: Number of data chunks (systematic nodes)
  • m: Number of parity chunks
  • d: Number of helper nodes for repair
§Returns

Result with ClayCode or error if parameters are invalid

Source

pub fn new_default(k: usize, m: usize) -> Result<Self, ClayError>

Create with default d = k + m - 1 (maximum helpers)

Source

pub fn encode(&self, data: &[u8]) -> Vec<Vec<u8>>

Encode data into n chunks

§Parameters
  • data: Raw data bytes to encode
§Returns

Vector of n chunks, each containing α sub-chunks

Source

pub fn decode( &self, available: &HashMap<usize, Vec<u8>>, erasures: &[usize], ) -> Result<Vec<u8>, ClayError>

Decode data from available chunks

§Parameters
  • available: Map from chunk index to chunk data
  • erasures: Set of erased chunk indices
§Returns

Recovered original data, or error if decoding fails

Source

pub fn minimum_to_repair( &self, lost_node: usize, available: &[usize], ) -> Result<Vec<(usize, Vec<usize>)>, ClayError>

Determine minimum sub-chunks needed to repair a lost node

§Parameters
  • lost_node: Index of the lost node (0 to n-1)
  • available: Available node indices
§Returns

Vector of (helper_node_idx, sub_chunk_indices) where sub_chunk_indices is a vector of the specific sub-chunk indices needed from that helper. The repair() function expects helper data to contain these sub-chunks concatenated in the ORDER they appear in sub_chunk_indices.

Source

pub fn repair( &self, lost_node: usize, helper_data: &HashMap<usize, Vec<u8>>, chunk_size: usize, ) -> Result<Vec<u8>, ClayError>

Repair a lost chunk using partial data from helper nodes

§Parameters
  • lost_node: Index of the lost node (0 to n-1)
  • helper_data: Map from helper node index to partial chunk data. Each helper’s data must be the concatenation of sub-chunks at the indices returned by minimum_to_repair(), in that exact order.
  • chunk_size: Full chunk size
§Returns

The recovered full chunk, or error if repair fails

Source

pub fn normalized_repair_bandwidth(&self) -> f64

Calculate normalized repair bandwidth

This is the ratio of data downloaded for repair to the size of the repaired chunk. For Clay codes, this is d / (k * q).

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