From 3715d871612ef071dd54377fd923a20c7060e127 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Sun, 6 Sep 2020 02:31:03 -0500 Subject: [PATCH] Fix termination behavior Boundary must be (a, b] to conform to NodeIterator behavior (stop _at_ next valid key rather than before) --- pkg/iterator/iterator.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/iterator/iterator.go b/pkg/iterator/iterator.go index e2857ae..045f448 100644 --- a/pkg/iterator/iterator.go +++ b/pkg/iterator/iterator.go @@ -34,11 +34,13 @@ func (it *PrefixBoundIterator) Next(descend bool) bool { if it.endKey == nil { return it.current.Next(descend) } - cmp := bytes.Compare(it.current.Path(), it.endKey) // stop before endKey - if cmp >= 0 { + if !it.current.Next(descend) { return false } - return it.current.Next(descend) + p := it.current.Path(); if len(p) >= 4 { p = p[:4] } + // stop if underlying iterator went past endKey + cmp := bytes.Compare(it.current.Path(), it.endKey) + return cmp <= 0 } func (it *PrefixBoundIterator) Error() error {