trie: add start key to NodeIterator constructors

The 'step' method is split into two parts, 'peek' and 'push'. peek
returns the next state but doesn't make it current.

The end of iteration was previously tracked by setting 'trie' to nil.
End of iteration is now tracked using the 'iteratorEnd' error, which is
slightly cleaner and requires less code.
This commit is contained in:
Felix Lange
2017-04-13 14:41:24 +02:00
parent a13e920af0
commit 4047ccad2f
9 changed files with 148 additions and 75 deletions

View File

@ -125,9 +125,10 @@ func New(root common.Hash, db Database) (*Trie, error) {
return trie, nil
}
// Iterator returns an iterator over all mappings in the trie.
func (t *Trie) NodeIterator() NodeIterator {
return newNodeIterator(t)
// NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at
// the key after the given start key.
func (t *Trie) NodeIterator(start []byte) NodeIterator {
return newNodeIterator(t, start)
}
// Get returns the value for key stored in the trie.