fn updated_path(
            &self,
            index: usize,
            new_leaf_hash: &Vec<u8>,
        ) -> Result<(Vec<u8>, Vec<Vec<u8>>), Error> {
            // leaf is expected to be already hashed

            // calculate leaf sibling hash and locate its position (left or right)
            let (leaf_left, leaf_right) = if index & 1 == 0 {
                // leaf on left
                (new_leaf_hash.clone(), self.leaf_nodes[index + 1].clone())
            } else {
                (self.leaf_nodes[index - 1].clone(), new_leaf_hash.clone())
            };

            // calculate the updated hash at bottom non-leaf-level
            let mut path_bottom_to_top = Vec::with_capacity(self.height - 1);
            {
                path_bottom_to_top
                    .push(hash_64_to_vec([&leaf_left[..], &leaf_right[..]].concat()).to_vec());
            }

            // then calculate the updated hash from bottom to root
            let leaf_index_in_tree = convert_index_to_last_level(index, self.height);
            let mut prev_index = parent(leaf_index_in_tree).unwrap();
            while !is_root(prev_index) {
                let (left_hash_bytes, right_hash_bytes) = if is_left_child(prev_index) {
                    (
                        ark_ff::to_bytes!(path_bottom_to_top.last().unwrap())?,
                        ark_ff::to_bytes!(&self.non_leaf_nodes[sibling(prev_index).unwrap()])?,
                    )
                } else {
                    (
                        ark_ff::to_bytes!(&self.non_leaf_nodes[sibling(prev_index).unwrap()])?,
                        ark_ff::to_bytes!(path_bottom_to_top.last().unwrap())?,
                    )
                };
                path_bottom_to_top.push(
                    hash_64_to_vec([&left_hash_bytes[..], &right_hash_bytes[..]].concat()).to_vec(),
                );

                prev_index = parent(prev_index).unwrap();
            }

            debug_assert_eq!(path_bottom_to_top.len(), self.height - 1);
            let path_top_to_bottom: Vec<_> = path_bottom_to_top.into_iter().rev().collect();
            Ok((new_leaf_hash.to_vec(), path_top_to_bottom))
        }
/// Given the index and new leaf, return the hash of leaf and an updated path in order from root to bottom non-leaf level.
/// This does not mutate the underlying tree.
Given the index and new leaf, return the hash of leaf and an updated path in order from root to bottom non-leaf level.
This does not mutate the underlying tree.
Given the index and new leaf return the hash of leaf and an updated path in order from root to bottom non - leaf level . This does not mutate the underlying tree .
fn updated_path(
            &self,
            index: usize,
            new_leaf_hash: &Vec<u8>,
        ) -> Result<(Vec<u8>, Vec<Vec<u8>>), Error> {
            // leaf is expected to be already hashed
            // calculate leaf sibling hash and locate its position (left or right)
            let (leaf_left, leaf_right) = if index & 1 == 0 {
                // leaf on left
                (new_leaf_hash.clone(), self.leaf_nodes[index + 1].clone())
            } else {
                (self.leaf_nodes[index - 1].clone(), new_leaf_hash.clone())
            };
            // calculate the updated hash at bottom non-leaf-level
            let mut path_bottom_to_top = Vec::with_capacity(self.height - 1);
            {
                path_bottom_to_top
                    .push(hash_64_to_vec([&leaf_left[..], &leaf_right[..]].concat()).to_vec());
            }
            // then calculate the updated hash from bottom to root
            let leaf_index_in_tree = convert_index_to_last_level(index, self.height);
            let mut prev_index = parent(leaf_index_in_tree).unwrap();
            while !is_root(prev_index) {
                let (left_hash_bytes, right_hash_bytes) = if is_left_child(prev_index) {
                    (
                        ark_ff::to_bytes!(path_bottom_to_top.last().unwrap())?,
                        ark_ff::to_bytes!(&self.non_leaf_nodes[sibling(prev_index).unwrap()])?,
                    )
                } else {
                    (
                        ark_ff::to_bytes!(&self.non_leaf_nodes[sibling(prev_index).unwrap()])?,
                        ark_ff::to_bytes!(path_bottom_to_top.last().unwrap())?,
                    )
                };
                path_bottom_to_top.push(
                    hash_64_to_vec([&left_hash_bytes[..], &right_hash_bytes[..]].concat()).to_vec(),
                );
                prev_index = parent(prev_index).unwrap();
            }
            debug_assert_eq!(path_bottom_to_top.len(), self.height - 1);
            let path_top_to_bottom: Vec<_> = path_bottom_to_top.into_iter().rev().collect();
            Ok((new_leaf_hash.to_vec(), path_top_to_bottom))
        }
fn updated_path ( & self , index : usize , new_leaf_hash : & Vec < u8 > , ) -> Result < ( Vec < u8 > , Vec < Vec < u8 > > ) , Error > { // leaf is expected to be already hashed // calculate leaf sibling hash and locate its position (left or right) let ( leaf_left , leaf_right ) = if index & 1 == 0 { // leaf on left ( new_leaf_hash . clone ( ) , self . leaf_nodes [ index + 1 ] . clone ( ) ) } else { ( self . leaf_nodes [ index - 1 ] . clone ( ) , new_leaf_hash . clone ( ) ) } ; // calculate the updated hash at bottom non-leaf-level let mut path_bottom_to_top = Vec :: with_capacity ( self . height - 1 ) ; { path_bottom_to_top . push ( hash_64_to_vec ( [ & leaf_left [ .. ] , & leaf_right [ .. ] ] . concat ( ) ) . to_vec ( ) ) ; } // then calculate the updated hash from bottom to root let leaf_index_in_tree = convert_index_to_last_level ( index , self . height ) ; let mut prev_index = parent ( leaf_index_in_tree ) . unwrap ( ) ; while ! is_root ( prev_index ) { let ( left_hash_bytes , right_hash_bytes ) = if is_left_child ( prev_index ) { ( ark_ff :: to_bytes ! ( path_bottom_to_top last ( ) unwrap ( ) ) ? , ark_ff :: to_bytes ! ( self non_leaf_nodes [ sibling ( prev_index ) unwrap ( ) ] ) ? , ) } else { ( ark_ff :: to_bytes ! ( self non_leaf_nodes [ sibling ( prev_index ) unwrap ( ) ] ) ? , ark_ff :: to_bytes ! ( path_bottom_to_top last ( ) unwrap ( ) ) ? , ) } ; path_bottom_to_top . push ( hash_64_to_vec ( [ & left_hash_bytes [ .. ] , & right_hash_bytes [ .. ] ] . concat ( ) ) . to_vec ( ) , ) ; prev_index = parent ( prev_index ) . unwrap ( ) ; } debug_assert_eq ! ( path_bottom_to_top len ( ) self height 1 ) ; let path_top_to_bottom : Vec < _ > = path_bottom_to_top . into_iter ( ) . rev ( ) . collect ( ) ; Ok ( ( new_leaf_hash . to_vec ( ) , path_top_to_bottom ) ) }
Given the index and new leaf, return the hash of leaf and an updated path in order from root to bottom non-leaf level.
Given the index and new leaf return the hash of leaf and an updated path in order from root to bottom non - leaf level .
&self
index
usize
new_leaf_hash
&Vec<u8>