symdiff - skip identical subtrees
This commit is contained in:
parent
91549f449c
commit
d1fb6e1f55
@ -138,10 +138,13 @@ func (it *symmDiffIterator) seek() {
|
||||
it.yieldFromA = false
|
||||
return
|
||||
case 0:
|
||||
if it.a.Next(true) {
|
||||
// if A and B have the same path and non-zero hash, they are identical and we can skip
|
||||
// the whole subtree
|
||||
noHash := it.a.Hash() == common.Hash{}
|
||||
if it.a.Next(noHash) {
|
||||
it.count++
|
||||
}
|
||||
if it.b.Next(true) {
|
||||
if it.b.Next(noHash) {
|
||||
it.count++
|
||||
}
|
||||
}
|
||||
@ -156,9 +159,6 @@ func (it *symmDiffIterator) Error() error {
|
||||
}
|
||||
|
||||
func compareNodes(a, b trie.NodeIterator) int {
|
||||
// if cmp := bytes.Compare(a.Path(), b.Path()); cmp != 0 {
|
||||
// return cmp
|
||||
// }
|
||||
if a.Leaf() && !b.Leaf() {
|
||||
return -1
|
||||
} else if b.Leaf() && !a.Leaf() {
|
||||
|
@ -50,7 +50,7 @@ func TestSymmetricDifferenceIterator(t *testing.T) {
|
||||
for di.Next(true) {
|
||||
t.Errorf("iterator should not yield any elements")
|
||||
}
|
||||
assert.Equal(t, 4, *count)
|
||||
assert.Equal(t, 2, *count)
|
||||
|
||||
trieb := trie.NewEmpty(db)
|
||||
di, count = utils.NewSymmetricDifferenceIterator(triea.NodeIterator([]byte("food")), trieb.NodeIterator(nil))
|
||||
|
Loading…
Reference in New Issue
Block a user