Struct miden_processor::crypto::NodeIndex
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 7The root is represented by the pair $(0, 0)$, its left child is $(1, 0)$ and its right child $(1, 1)$.
Implementations§
§impl NodeIndex
impl NodeIndex
pub const fn new(depth: u8, value: u64) -> Result<NodeIndex, MerkleError>
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
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>
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:
depthdoesn’t fit in au8.valueis greater than or equal to 2^{depth}.
pub const fn left_child(self) -> NodeIndex
pub const fn left_child(self) -> NodeIndex
Returns left child index of the current node.
pub const fn right_child(self) -> NodeIndex
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]
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
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 is_value_odd(&self) -> bool
pub const fn is_value_odd(&self) -> bool
Returns true if the current instance points to a right sibling node.
pub fn move_up(&mut self)
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)
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 Deserializable for NodeIndex
impl Deserializable for NodeIndex
§fn read_from<R>(source: &mut R) -> Result<NodeIndex, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<NodeIndex, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read more§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
§impl Ord for NodeIndex
impl Ord for NodeIndex
§impl PartialOrd for NodeIndex
impl PartialOrd for NodeIndex
§fn partial_cmp(&self, other: &NodeIndex) -> Option<Ordering>
fn partial_cmp(&self, other: &NodeIndex) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more§impl Serializable for NodeIndex
impl Serializable for NodeIndex
§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.