diff --git a/deepsubtree.go b/deepsubtree.go index a716f5d28..47b88a2f8 100644 --- a/deepsubtree.go +++ b/deepsubtree.go @@ -16,79 +16,6 @@ type DeepSubTree struct { *MutableTree } -// Adds the node with the given key in the Deep Subtree -// using the given full IAVL tree along with -// the path of that node -func (dst *DeepSubTree) AddPath(tree *ImmutableTree, key []byte) error { - path, val, err := tree.root.PathToLeaf(tree, key) - if err != nil { - return err - } - - err = dst.addPath(path, val) - if err != nil { - return err - } - - return nil -} - -// Helper method to add given leaf node in the Deep Subtree -// using the given PathToLeaf -func (dst *DeepSubTree) addPath(pl PathToLeaf, leaf *Node) error { - hash, err := leaf._hash() - if err != nil { - return err - } - - n := NewNode(leaf.key, leaf.value, leaf.version) - prevHash, err := n._hash() - if err != nil { - return err - } - err = dst.ndb.SaveNode(n) - if err != nil { - return err - } - - // Iterates from bottom most inner node to top - for i := len(pl) - 1; i >= 0; i-- { - pin := pl[i] - hash, err = pin.Hash(hash) - if err != nil { - return err - } - if pin.Left == nil { - pin.Left = prevHash - } else if pin.Right == nil { - pin.Right = prevHash - } - n := &Node{ - subtreeHeight: pin.Height, - size: pin.Size, - version: pin.Version, - leftHash: pin.Left, - rightHash: pin.Right, - hash: hash, - } - prevHash = hash - - // Only save the node to the deep subtree if it doesn't already exist there - has, err := dst.ndb.Has(n.hash) - if err != nil { - return err - } - if !has { - err = dst.ndb.SaveNode(n) - if err != nil { - return err - } - } - } - - return dst.ndb.Commit() -} - // Traverses in the nodes in the NodeDB in the Deep Subtree // and links them together using the populated left and right // hashes and sets the root to be the node with the given rootHash