CodedSymbol

Struct CodedSymbol 

Source
pub struct CodedSymbol<T: Symbol> {
    pub sum: Vec<u8>,
    pub hash: u64,
    pub count: i64,
    /* private fields */
}
Expand description

A RIBLT is an infinite sequence of CodedSymbols

The ‘sum’ field is the XOR of the symbols encoded into this CodedSymbol

The ‘hash’ field is the XOR of the hashes of the symbols encoded into this CodedSymbol

The ‘count’ field is the number of local symbols minus the number of remote symbols

The ‘_marker’ phantom field is used to allow us to associate the CodedSymbol with a specific Symbol type. The type T is used by implemented methods to know what type of Symbol is encoded in the CodedSymbol.

A CodedSymbol can be peeled when the count is 1 or -1 and the hash matches

Fields§

§sum: Vec<u8>§hash: u64§count: i64

Implementations§

Source§

impl<T: Symbol> CodedSymbol<T>

Source

pub fn new() -> Self

Source

pub fn apply(&mut self, s: &T, direction: Direction)

apply() adds or removes a symbol from the CodedSymbol

Adding a local, or removing a remote, symbol increases the count by 1

Removing a local, or adding a remote, symbol decreases the count by 1

Source

pub fn combine(&self, b: &CodedSymbol<T>) -> CodedSymbol<T>

Used by the encoder to join two vectors of codedSymbols together produced from two distinct sets. The results are only valid if there were no duplicates between the original sets.

Source

pub fn collapse(&self, b: &CodedSymbol<T>) -> CodedSymbol<T>

Used by the encoder to ‘subtract’ a remote set of codedSymbols from a local set.

Source

pub fn is_peelable(&self) -> bool

Checks if the CodedSymbol contains only one symbol and therefore can be peeled

A count of 1 does not necessarily mean that the ‘sum’ field is the xor of only one encoded symbol. It could be the xor of two local and one remote symbols. This is why we also check the hash.

Source

pub fn peel(&mut self) -> PeelableResult<T>

Peel extracts a symbol from the CodedSymbol (if possible) and returns it in a PeelableResult A PeelableResult is used to keep track of if the symbol was local or remote (or was not able to be peeled).

Source

pub fn peel_peek(&self) -> PeelableResult<T>

same as peel, but does not modify the CodedSymbol

Source

pub fn is_empty(&self) -> bool

Checks if the CodedSymbol contains no symbols

Trait Implementations§

Source§

impl<T: Clone + Symbol> Clone for CodedSymbol<T>

Source§

fn clone(&self) -> CodedSymbol<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Symbol> Debug for CodedSymbol<T>

Source§

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

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

impl<'de, T: Symbol> Deserialize<'de> for CodedSymbol<T>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Symbol> Serialize for CodedSymbol<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CodedSymbol<T>

§

impl<T> RefUnwindSafe for CodedSymbol<T>
where T: RefUnwindSafe,

§

impl<T> Send for CodedSymbol<T>
where T: Send,

§

impl<T> Sync for CodedSymbol<T>
where T: Sync,

§

impl<T> Unpin for CodedSymbol<T>
where T: Unpin,

§

impl<T> UnwindSafe for CodedSymbol<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,