mirror of
https://github.com/arnaucube/arbo.git
synced 2026-01-17 02:31:28 +01:00
Add AddBatch CaseD
CASE D: Already populated Tree
==============================
- Use A, B, C, D as subtree
- Sort the Keys in Buckets that share the initial part of the path
- For each subtree add there the new leafs
R
/ \
/ \
/ \
* *
/ | / \
/ | / \
/ | / \
L: A B C D
/\ /\ / \ / \
... ... ... ... ... ...
This commit is contained in:
10
tree.go
10
tree.go
@@ -206,7 +206,7 @@ func (t *Tree) add(fromLvl int, k, v []byte) error {
|
||||
t.root = leafKey
|
||||
return nil
|
||||
}
|
||||
root, err := t.up(leafKey, siblings, path, len(siblings)-1)
|
||||
root, err := t.up(leafKey, siblings, path, len(siblings)-1, fromLvl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -307,10 +307,10 @@ func (t *Tree) downVirtually(siblings [][]byte, oldKey, newKey []byte, oldPath,
|
||||
}
|
||||
|
||||
// up goes up recursively updating the intermediate nodes
|
||||
func (t *Tree) up(key []byte, siblings [][]byte, path []bool, currLvl int) ([]byte, error) {
|
||||
func (t *Tree) up(key []byte, siblings [][]byte, path []bool, currLvl, toLvl int) ([]byte, error) {
|
||||
var k, v []byte
|
||||
var err error
|
||||
if path[currLvl] {
|
||||
if path[currLvl+toLvl] {
|
||||
k, v, err = newIntermediate(t.hashFunction, siblings[currLvl], key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -331,7 +331,7 @@ func (t *Tree) up(key []byte, siblings [][]byte, path []bool, currLvl int) ([]by
|
||||
return k, nil
|
||||
}
|
||||
|
||||
return t.up(k, siblings, path, currLvl-1)
|
||||
return t.up(k, siblings, path, currLvl-1, toLvl)
|
||||
}
|
||||
|
||||
func newLeafValue(hashFunc HashFunction, k, v []byte) ([]byte, []byte, error) {
|
||||
@@ -440,7 +440,7 @@ func (t *Tree) Update(k, v []byte) error {
|
||||
t.root = leafKey
|
||||
return t.tx.Commit()
|
||||
}
|
||||
root, err := t.up(leafKey, siblings, path, len(siblings)-1)
|
||||
root, err := t.up(leafKey, siblings, path, len(siblings)-1, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user