Struct Segment

Source
pub struct Segment<T> { /* private fields */ }
Expand description

Segment of a PMMR: unpruned leaves and the necessary data to verify segment membership in the original MMR.

Implementations§

Source§

impl<T> Segment<T>

Source

pub fn segment_pos_range(&self, mmr_size: u64) -> (u64, u64)

Inclusive range of MMR positions for this segment

Source

pub fn identifier(&self) -> SegmentIdentifier

Get the identifier associated with this segment

Source

pub fn parts( self, ) -> (SegmentIdentifier, Vec<u64>, Vec<Hash>, Vec<u64>, Vec<T>, SegmentProof)

Consume the segment and return its parts

Source

pub fn from_parts( identifier: SegmentIdentifier, hash_pos: Vec<u64>, hashes: Vec<Hash>, leaf_pos: Vec<u64>, leaf_data: Vec<T>, proof: SegmentProof, ) -> Self

Construct a segment from its parts

Source

pub fn leaf_iter(&self) -> impl Iterator<Item = (u64, &T)> + '_

Iterator of all the leaves in the segment

Source

pub fn hash_iter(&self) -> impl Iterator<Item = (u64, Hash)> + '_

Iterator of all the hashes in the segment

Source

pub fn proof(&self) -> &SegmentProof

Segment proof

Source

pub fn id(&self) -> SegmentIdentifier

Segment identifier

Source§

impl<T> Segment<T>
where T: Readable + Writeable + Debug,

Source

pub fn from_pmmr<U, B>( segment_id: SegmentIdentifier, pmmr: &ReadonlyPMMR<'_, U, B>, prunable: bool, ) -> Result<Self, SegmentError>
where U: PMMRable<E = T>, B: Backend<U>,

Generate a segment from a PMMR

Source§

impl<T> Segment<T>

Source

pub fn root( &self, mmr_size: u64, bitmap: Option<&Bitmap>, ) -> Result<Option<Hash>, SegmentError>

Calculate root hash of this segment Returns None iff the segment is full and completely pruned

Source

pub fn first_unpruned_parent( &self, mmr_size: u64, bitmap: Option<&Bitmap>, ) -> Result<(Hash, u64), SegmentError>

Get the first 1-based (sucks) unpruned parent hash of this segment

Source

pub fn validate( &self, mmr_size: u64, bitmap: Option<&Bitmap>, mmr_root: Hash, ) -> Result<(), SegmentError>

Check validity of the segment by calculating its root and validating the merkle proof

Source

pub fn validate_with( &self, mmr_size: u64, bitmap: Option<&Bitmap>, mmr_root: Hash, hash_last_pos: u64, other_root: Hash, other_is_left: bool, ) -> Result<(), SegmentError>

Check validity of the segment by calculating its root and validating the merkle proof This function assumes a final hashing step together with other_root

Trait Implementations§

Source§

impl<T: Clone> Clone for Segment<T>

Source§

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

Returns a copy 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> Debug for Segment<T>

Source§

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

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

impl<T: PartialEq> PartialEq for Segment<T>

Source§

fn eq(&self, other: &Segment<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<T: Readable> Readable for Segment<T>

Source§

fn read<R: Reader>(reader: &mut R) -> Result<Self, Error>

Reads the data necessary to this Readable from the provided reader
Source§

impl<T: Writeable> Writeable for Segment<T>

Source§

fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>

Write the data held by this Writeable to the provided writer
Source§

impl<T: Eq> Eq for Segment<T>

Source§

impl<T> StructuralPartialEq for Segment<T>

Auto Trait Implementations§

§

impl<T> Freeze for Segment<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Segment<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> CloneAny for T
where T: Any + Clone + Send + Sync,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> UnsafeAny for T
where T: Any,