Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterator: allow NextPrefix from exhausted position #3603

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,15 @@ func (i *Iterator) NextPrefix() bool {
}

func (i *Iterator) nextPrefix() IterValidityState {
// We don't need to support NextPrefix from an exhausted position, but we want
// to implement predictable semantics for the metamorphic tests.
//
// The iterator could be exhausted in either direction; in both cases,
// returning whatever Next returns is correct.
if i.iterValidityState == IterExhausted {
return i.nextWithLimit(nil)
}

if i.rangeKey != nil {
// NB: Check Valid() before clearing requiresReposition.
i.rangeKey.prevPosHadRangeKey = i.rangeKey.hasRangeKey && i.Valid()
Expand All @@ -1740,11 +1749,6 @@ func (i *Iterator) nextPrefix() IterValidityState {
// key.
i.rangeKey.updated = i.rangeKey.hasRangeKey && !i.Valid() && i.opts.rangeKeys()
}
// NextPrefix from an exhausted position is undefined. We keep the exhausted
// position, which provides determinism for the metamorphic tests.
if i.iterValidityState == IterExhausted {
return i.iterValidityState
}

// Although NextPrefix documents that behavior at IterAtLimit is undefined,
// this function handles these cases as a simple prefix-agnostic Next. This
Expand Down
Loading