Skip to content

Commit

Permalink
Improve Next() algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykorean committed Feb 12, 2024
1 parent 52ca621 commit 1139dab
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions db/multi_cf_iterator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,33 @@ void MultiCfIteratorImpl::SeekToFirst() {

void MultiCfIteratorImpl::Next() {
assert(Valid());

auto* current = min_heap_.top().iterator;
std::string current_key_copy =
std::string(current->key().data(), current->key().size());
while (!min_heap_.empty() &&
comparator_->Compare(current->key(), current_key_copy) == 0) {
current->Next();
if (current->Valid()) {
// 1. Keep the top iterator (by popping it from the heap)
// 2. Make sure all others have iterated past the top iterator key slice
// 3. Advance the top iterator, and add it back to the heap if valid
auto top = min_heap_.top();
min_heap_.pop();
if (!min_heap_.empty()) {
auto* current = min_heap_.top().iterator;
while (current->Valid() &&
comparator_->Compare(top.iterator->key(), current->key()) == 0) {
assert(current->status().ok());
min_heap_.replace_top(min_heap_.top());
} else {
considerStatus(current->status());
min_heap_.pop();
}
if (!min_heap_.empty()) {
current = min_heap_.top().iterator;
current->Next();

if (current->Valid()) {
min_heap_.replace_top(min_heap_.top());
} else {
considerStatus(current->status());
min_heap_.pop();
}
if (!min_heap_.empty()) {
current = min_heap_.top().iterator;
}
}
}
top.iterator->Next();
if (top.iterator->Valid()) {
min_heap_.push(top);
}
}

const AttributeGroups kNoAttributeGroups;
Expand Down

0 comments on commit 1139dab

Please sign in to comment.