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
impl NodeIndex
sourcepub const fn new(depth: u8, value: u64) -> Result<Self, MerkleError>
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}.
sourcepub const fn new_unchecked(depth: u8, value: u64) -> Self
pub const fn new_unchecked(depth: u8, value: u64) -> Self
Creates a new node index without checking its validity.
sourcepub fn from_elements(depth: &Felt, value: &Felt) -> Result<Self, MerkleError>
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 au8
.value
is greater than or equal to 2^{depth}.
sourcepub const fn left_child(self) -> Self
pub const fn left_child(self) -> Self
Returns left child index of the current node.
sourcepub const fn right_child(self) -> Self
pub const fn right_child(self) -> Self
Returns right child index of the current node.
sourcepub 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.
sourcepub 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
.
sourcepub 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.
sourcepub 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§
source§impl Deserializable for NodeIndex
impl Deserializable for NodeIndex
source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl Ord for NodeIndex
impl Ord for NodeIndex
source§impl PartialOrd for NodeIndex
impl PartialOrd for NodeIndex
source§impl Serializable for NodeIndex
impl Serializable for NodeIndex
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self
into bytes and writes these bytes into the target
.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Copy for NodeIndex
impl Eq for NodeIndex
impl StructuralPartialEq for NodeIndex
Auto Trait Implementations§
impl Freeze for NodeIndex
impl RefUnwindSafe for NodeIndex
impl Send for NodeIndex
impl Sync for NodeIndex
impl Unpin for NodeIndex
impl UnwindSafe for NodeIndex
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)