miden_crypto::merkle

Struct NodeIndex

source
pub struct NodeIndex { /* private fields */ }
Expand description

Address to an arbitrary node in a binary tree using level order form.

The position is represented by the pair (depth, pos), where for a given depth d elements are numbered from $0..(2^d)-1$. Example:

depth
0             0
1         0        1
2      0    1    2    3
3     0 1  2 3  4 5  6 7

The root is represented by the pair $(0, 0)$, its left child is $(1, 0)$ and its right child $(1, 1)$.

Implementations§

source§

impl NodeIndex

source

pub const fn new(depth: u8, value: u64) -> Result<Self, MerkleError>

Creates a new node index.

§Errors

Returns an error if the value is greater than or equal to 2^{depth}.

source

pub const fn new_unchecked(depth: u8, value: u64) -> Self

Creates a new node index without checking its validity.

source

pub fn from_elements(depth: &Felt, value: &Felt) -> Result<Self, MerkleError>

Creates a node index from a pair of field elements representing the depth and value.

§Errors

Returns an error if:

  • depth doesn’t fit in a u8.
  • value is greater than or equal to 2^{depth}.
source

pub const fn root() -> Self

Creates a new node index pointing to the root of the tree.

source

pub const fn sibling(self) -> Self

Computes sibling index of the current node.

source

pub const fn left_child(self) -> Self

Returns left child index of the current node.

source

pub const fn right_child(self) -> Self

Returns right child index of the current node.

source

pub const fn build_node( &self, slf: RpoDigest, sibling: RpoDigest, ) -> [RpoDigest; 2]

Builds a node to be used as input of a hash function when computing a Merkle path.

Will evaluate the parity of the current instance to define the result.

source

pub const fn to_scalar_index(&self) -> u64

Returns the scalar representation of the depth/value pair.

It is computed as 2^depth + value.

source

pub const fn depth(&self) -> u8

Returns the depth of the current instance.

source

pub const fn value(&self) -> u64

Returns the value of this index.

source

pub const fn is_value_odd(&self) -> bool

Returns true if the current instance points to a right sibling node.

source

pub const fn is_root(&self) -> bool

Returns true if the depth is 0.

source

pub fn move_up(&mut self)

Traverses one level towards the root, decrementing the depth by 1.

source

pub fn move_up_to(&mut self, depth: u8)

Traverses towards the root until the specified depth is reached.

Assumes that the specified depth is smaller than the current depth.

Trait Implementations§

source§

impl Clone for NodeIndex

source§

fn clone(&self) -> NodeIndex

Returns a copy of the value. Read more
1.6.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for NodeIndex

source§

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

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

impl Default for NodeIndex

source§

fn default() -> NodeIndex

Returns the “default value” for a type. Read more
source§

impl Deserializable for NodeIndex

source§

fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
source§

impl Display for NodeIndex

source§

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

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

impl<const DEPTH: u8> From<LeafIndex<DEPTH>> for NodeIndex

source§

fn from(value: LeafIndex<DEPTH>) -> Self

Converts to this type from the input type.
source§

impl Hash for NodeIndex

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.6.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for NodeIndex

source§

fn cmp(&self, other: &NodeIndex) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for NodeIndex

source§

fn eq(&self, other: &NodeIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.6.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 PartialOrd for NodeIndex

source§

fn partial_cmp(&self, other: &NodeIndex) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.6.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.6.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.6.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.6.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serializable for NodeIndex

source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
source§

impl<const DEPTH: u8> TryFrom<NodeIndex> for LeafIndex<DEPTH>

source§

type Error = MerkleError

The type returned in the event of a conversion error.
source§

fn try_from(node_index: NodeIndex) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for NodeIndex

source§

impl Eq for NodeIndex

source§

impl StructuralPartialEq for NodeIndex

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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