Fix IteratorAscFrom() And IteratorDescFrom() Panic Bug
@@ -436,9 +436,11 @@ func (tree *BTree) IteratorAscFrom(key interface{}, match bool, f func(key, valu
tree.doIteratorAsc(node, node.Entries[index], index, f)
}
} else {
+ if index >= 0 && index < len(node.Entries) {
tree.doIteratorAsc(node, node.Entries[index], index, f)
}
}
+}
func (tree *BTree) doIteratorAsc(node *BTreeNode, entry *BTreeEntry, index int, f func(key, value interface{}) bool) {
first := true
@@ -511,9 +513,11 @@ func (tree *BTree) IteratorDescFrom(key interface{}, match bool, f func(key, val
tree.doIteratorDesc(node, node.Entries[index], index, f)
}
} else {
+ if index >= 0 && index < len(node.Entries) {
tree.doIteratorDesc(node, node.Entries[index], index, f)
}
}
+}
// IteratorDesc iterates the tree readonly in descending order with given callback function `f`.
// If `f` returns true, then it continues iterating; or false to stop.
