pub fn append(&mut self, node: MerkleNode) -> Result<(), ()> {
        if self.is_full() {
            return Err(());
        }

        match (self.left, self.right) {
            (None, _) => self.left = Some(node),
            (_, None) => self.right = Some(node),
            (Some(left), Some(right)) => {
                let mut parent = MerkleNode::combine(self.tree_type, 0, &left, &right);
                self.left = Some(node);
                self.right = None;

                for i in 0..self.depth {
                    if i < self.parents.len() {
                        if let Some(old_parent) = self.parents[i] {
                            parent =
                                MerkleNode::combine(self.tree_type, i + 1, &old_parent, &parent);
                            self.parents[i] = None;
                        } else {
                            self.parents[i] = Some(parent);
                            break;
                        }
                    } else {
                        self.parents.push(Some(parent));
                        break;
                    }
                }
            }
        }
        if self.last_filled_position != 0 || self.right.is_some() {
            self.last_filled_position += 1;
        }

        Ok(())
    }
/// Append a leaf node to the tree, or return error if tree is full
Append a leaf node to the tree, or return error if tree is full
Append a leaf node to the tree or return error if tree is full
pub fn append(&mut self, node: MerkleNode) -> Result<(), ()> {
        if self.is_full() {
            return Err(());
        }
        match (self.left, self.right) {
            (None, _) => self.left = Some(node),
            (_, None) => self.right = Some(node),
            (Some(left), Some(right)) => {
                let mut parent = MerkleNode::combine(self.tree_type, 0, &left, &right);
                self.left = Some(node);
                self.right = None;
                for i in 0..self.depth {
                    if i < self.parents.len() {
                        if let Some(old_parent) = self.parents[i] {
                            parent =
                                MerkleNode::combine(self.tree_type, i + 1, &old_parent, &parent);
                            self.parents[i] = None;
                        } else {
                            self.parents[i] = Some(parent);
                            break;
                        }
                    } else {
                        self.parents.push(Some(parent));
                        break;
                    }
                }
            }
        }
        if self.last_filled_position != 0 || self.right.is_some() {
            self.last_filled_position += 1;
        }
        Ok(())
    }
pub fn append ( & mut self , node : MerkleNode ) -> Result < ( ) , ( ) > { if self . is_full ( ) { return Err ( ( ) ) ; } match ( self . left , self . right ) { ( None , _ ) => self . left = Some ( node ) , ( _ , None ) => self . right = Some ( node ) , ( Some ( left ) , Some ( right ) ) => { let mut parent = MerkleNode :: combine ( self . tree_type , 0 , & left , & right ) ; self . left = Some ( node ) ; self . right = None ; for i in 0 .. self . depth { if i < self . parents . len ( ) { if let Some ( old_parent ) = self . parents [ i ] { parent = MerkleNode :: combine ( self . tree_type , i + 1 , & old_parent , & parent ) ; self . parents [ i ] = None ; } else { self . parents [ i ] = Some ( parent ) ; break ; } } else { self . parents . push ( Some ( parent ) ) ; break ; } } } } if self . last_filled_position != 0 || self . right . is_some ( ) { self . last_filled_position += 1 ; } Ok ( ( ) ) }
Append a leaf node to the tree, or return error if tree is full
Append a leaf node to the tree or return error if tree is full
&mut self
node
MerkleNode
&mut self
node
MerkleNode