Skip to content

Commit

Permalink
avoid always using fast iterator in mutable tree iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Mar 2, 2022
1 parent fe90684 commit 6eced7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions immutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ func (t *ImmutableTree) Iterate(fn func(key []byte, value []byte) bool) bool {
// Iterator returns an iterator over the immutable tree.
func (t *ImmutableTree) Iterator(start, end []byte, ascending bool) dbm.Iterator {
if t.IsFastCacheEnabled() {
fmt.Println("immutable tree - iterator - use fast")
return NewFastIterator(start, end, ascending, t.ndb)
} else {
fmt.Println("immutable tree - iterator - use regular")
return NewIterator(start, end, ascending, t)
}
}
Expand Down
7 changes: 6 additions & 1 deletion mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ func (t *MutableTree) Iterate(fn func(key []byte, value []byte) bool) (stopped b
// Iterator returns an iterator over the mutable tree.
// CONTRACT: no updates are made to the tree while an iterator is active.
func (t *MutableTree) Iterator(start, end []byte, ascending bool) dbm.Iterator {
return NewUnsavedFastIterator(start, end, ascending, t.ndb, t.unsavedFastNodeAdditions, t.unsavedFastNodeRemovals)
if t.IsFastCacheEnabled() {
fmt.Println("mutable tree - iterator - use fast")
return NewUnsavedFastIterator(start, end, ascending, t.ndb, t.unsavedFastNodeAdditions, t.unsavedFastNodeRemovals)
}
fmt.Println("mutable tree - iterator - use immutable")
return t.ImmutableTree.Iterator(start, end, ascending)
}

func (tree *MutableTree) set(key []byte, value []byte) (orphans []*Node, updated bool) {
Expand Down

0 comments on commit 6eced7b

Please sign in to comment.