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§

§

impl NodeIndex

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

Creates a new node index.

§Errors

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

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

Creates a new node index without checking its validity.

pub fn from_elements( depth: &BaseElement, value: &BaseElement ) -> Result<NodeIndex, 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}.

pub const fn root() -> NodeIndex

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

pub const fn sibling(self) -> NodeIndex

Computes sibling index of the current node.

pub const fn left_child(self) -> NodeIndex

Returns left child index of the current node.

pub const fn right_child(self) -> NodeIndex

Returns right child index of the current node.

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.

pub const fn to_scalar_index(&self) -> u64

Returns the scalar representation of the depth/value pair.

It is computed as 2^depth + value.

pub const fn depth(&self) -> u8

Returns the depth of the current instance.

pub const fn value(&self) -> u64

Returns the value of this index.

pub const fn is_value_odd(&self) -> bool

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

pub const fn is_root(&self) -> bool

Returns true if the depth is 0.

pub fn move_up(&mut self)

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

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§

§

impl Clone for NodeIndex

§

fn clone(&self) -> NodeIndex

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
§

impl Debug for NodeIndex

§

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

Formats the value using the given formatter. Read more
§

impl Default for NodeIndex

§

fn default() -> NodeIndex

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

impl Deserializable for NodeIndex

§

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

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

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

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

impl Display for NodeIndex

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Converts to this type from the input type.
§

impl Hash for NodeIndex

§

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

Feeds this value into the given Hasher. Read more
1.3.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
§

impl Ord for NodeIndex

§

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 + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl PartialEq for NodeIndex

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl PartialOrd for NodeIndex

§

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

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

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

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

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

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

impl Serializable for NodeIndex

§

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

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

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

Serializes self into a vector of bytes.
§

fn get_size_hint(&self) -> usize

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

impl Copy for NodeIndex

§

impl Eq for NodeIndex

§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more