/// Computes the hash of the merkle tree with `self` as root.
Computes the hash of the merkle tree with `self` as root.
Computes the hash of the merkle tree with ` self ` as root .
pub(crate) fn hash(&self) -> [u8; 32] {
        let mut computed_children_nodes = vec![];
        enum StackPushType {
            /// Children of the node not yet pushed onto `stack`
            First,
            /// Second time on the stack
            ChildrenAlreadyPushed,
        }
        let mut stack = vec![(self.clone(), StackPushType::First)];
        while let Some((n, push_type)) = stack.pop() {
            match n {
                MerkleTreeNode::Internal {
                    ref left,
                    ref right,
                } => {
                    match push_type {
                        StackPushType::First => {
                            stack.push((n.clone(), StackPushType::ChildrenAlreadyPushed));
                            stack.push((*left.clone(), StackPushType::First));
                            stack.push((*right.clone(), StackPushType::First));
                        }
                        StackPushType::ChildrenAlreadyPushed => {
                            // Note we pop off left child first
                            let computed_left_child = computed_children_nodes.pop().unwrap();
                            if let Some(computed_right_child) = computed_children_nodes.pop() {
                                let concat =
                                    concatenate_hashes(&computed_left_child, &computed_right_child);
                                let hash = prefixed_hash(NodePrefix::Internal as u8, &concat);
                                if stack.is_empty() {
                                    return *hash;
                                } else {
                                    computed_children_nodes.push(*hash);
                                }
                            } else {
                                let internal_hash =
                                    prefixed_hash(NodePrefix::Internal as u8, &computed_left_child);
                                if stack.is_empty() {
                                    return *internal_hash;
                                } else {
                                    computed_children_nodes.push(*internal_hash);
                                }
                            }
                        }
                    }
                }
                MerkleTreeNode::Leaf(data) => match push_type {
                    StackPushType::First => {
                        let hash = prefixed_hash(NodePrefix::Leaf as u8, &data);
                        computed_children_nodes.push(*hash);
                    }
                    StackPushType::ChildrenAlreadyPushed => {
                        unreachable!()
                    }
                },
                MerkleTreeNode::Empty => (),
                MerkleTreeNode::EmptyTree => {
                    return *blake2b256_hash(&[]).0;
                }
            }
        }
        unreachable!()
    }
pub ( crate ) fn hash ( & self ) -> [ u8 ; 32 ] { let mut computed_children_nodes = vec ! [ ] ; enum StackPushType { /// Children of the node not yet pushed onto `stack` First , /// Second time on the stack ChildrenAlreadyPushed , } let mut stack = vec ! [ ( self clone ( ) StackPushType First ) ] ; while let Some ( ( n , push_type ) ) = stack . pop ( ) { match n { MerkleTreeNode :: Internal { ref left , ref right , } => { match push_type { StackPushType :: First => { stack . push ( ( n . clone ( ) , StackPushType :: ChildrenAlreadyPushed ) ) ; stack . push ( ( * left . clone ( ) , StackPushType :: First ) ) ; stack . push ( ( * right . clone ( ) , StackPushType :: First ) ) ; } StackPushType :: ChildrenAlreadyPushed => { // Note we pop off left child first let computed_left_child = computed_children_nodes . pop ( ) . unwrap ( ) ; if let Some ( computed_right_child ) = computed_children_nodes . pop ( ) { let concat = concatenate_hashes ( & computed_left_child , & computed_right_child ) ; let hash = prefixed_hash ( NodePrefix :: Internal as u8 , & concat ) ; if stack . is_empty ( ) { return * hash ; } else { computed_children_nodes . push ( * hash ) ; } } else { let internal_hash = prefixed_hash ( NodePrefix :: Internal as u8 , & computed_left_child ) ; if stack . is_empty ( ) { return * internal_hash ; } else { computed_children_nodes . push ( * internal_hash ) ; } } } } } MerkleTreeNode :: Leaf ( data ) => match push_type { StackPushType :: First => { let hash = prefixed_hash ( NodePrefix :: Leaf as u8 , & data ) ; computed_children_nodes . push ( * hash ) ; } StackPushType :: ChildrenAlreadyPushed => { unreachable ! ( ) } } , MerkleTreeNode :: Empty => ( ) , MerkleTreeNode :: EmptyTree => { return * blake2b256_hash ( & [ ] ) . 0 ; } } } unreachable ! ( ) }
Computes the hash of the merkle tree with `self` as root.
Computes the hash of the merkle tree with ` self ` as root .
&self