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

refact Next() in mergeiterator.go #22712

Closed
wants to merge 2 commits into from
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
20 changes: 10 additions & 10 deletions store/cachekv/internal/mergeiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ func (iter *cacheMergeIterator) Valid() bool {
func (iter *cacheMergeIterator) Next() {
iter.assertValid()

switch {
case !iter.parent.Valid():
// If parent is invalid, get the next cache item.
if !iter.parent.Valid() {
// Parent is invalid, so we advance the cache iterator
iter.cache.Next()
case !iter.cache.Valid():
// If cache is invalid, get the next parent item.
} else if !iter.cache.Valid(){
// Cache is invalid, so we advance the parent iterator
iter.parent.Next()
default:
// Both are valid. Compare keys.
} else {
// Both iterators are valid, so we compare their keys
keyP, keyC := iter.parent.Key(), iter.cache.Key()
switch iter.compare(keyP, keyC) {
case -1: // parent < cache
iter.parent.Next()
iter.parent.Next() // Advance parent
case 0: // parent == cache
iter.parent.Next()
iter.parent.Next() // Advance both iterators, since they are equal
iter.cache.Next()
case 1: // parent > cache
iter.cache.Next()
iter.cache.Next() // Advance cache
}
}

iter.valid = iter.skipUntilExistsOrInvalid()
}

Expand Down
Loading