diff --git a/iterator.go b/iterator.go index a509ed1..2aaa62f 100644 --- a/iterator.go +++ b/iterator.go @@ -6,6 +6,7 @@ package iavl import ( "bytes" "errors" + "fmt" dbm "github.com/tendermint/tm-db" ) @@ -76,19 +77,19 @@ func (nodes *delayedNodes) length() int { // 1. If it is not an delayed node (node.delayed == false) it immediately returns it. // // A. If the `node` is a branch node: -// 1. If the traversal is postorder, then append the current node to the t.delayedNodes, -// with `delayed` set to false. This makes the current node returned *after* all the children -// are traversed, without being expanded. -// 2. Append the traversable children nodes into the `delayedNodes`, with `delayed` set to true. This -// makes the children nodes to be traversed, and expanded with their respective children. -// 3. If the traversal is preorder, (with the children to be traversed already pushed to the -// `delayedNodes`), returns the current node. -// 4. Call `traversal.next()` to further traverse through the `delayedNodes`. +// 1. If the traversal is postorder, then append the current node to the t.delayedNodes, +// with `delayed` set to false. This makes the current node returned *after* all the children +// are traversed, without being expanded. +// 2. Append the traversable children nodes into the `delayedNodes`, with `delayed` set to true. This +// makes the children nodes to be traversed, and expanded with their respective children. +// 3. If the traversal is preorder, (with the children to be traversed already pushed to the +// `delayedNodes`), returns the current node. +// 4. Call `traversal.next()` to further traverse through the `delayedNodes`. // // B. If the `node` is a leaf node, it will be returned without expand, by the following process: -// 1. If the traversal is postorder, the current node will be append to the `delayedNodes` with `delayed` -// set to false, and immediately returned at the subsequent call of `traversal.next()` at the last line. -// 2. If the traversal is preorder, the current node will be returned. +// 1. If the traversal is postorder, the current node will be append to the `delayedNodes` with `delayed` +// set to false, and immediately returned at the subsequent call of `traversal.next()` at the last line. +// 2. If the traversal is preorder, the current node will be returned. func (t *traversal) next() (*Node, error) { // End of traversal. if t.delayedNodes.length() == 0 { @@ -230,6 +231,9 @@ func (iter *Iterator) Next() { node, err := iter.t.next() // TODO: double-check if this error is correctly handled. if node == nil || err != nil { + if err != nil { + fmt.Printf("iterator closed due to %s\n", err) + } iter.t = nil iter.valid = false return