Skip to content

Commit

Permalink
Delete addPath and AddPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Oct 28, 2022
1 parent efdc8ad commit 5c84d10
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions deepsubtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c84d10

Please sign in to comment.