Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzelin committed Mar 8, 2024
1 parent 8c64198 commit 12b2e88
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.annotation.Nullable;

import java.util.Iterator;
import java.util.LinkedList;

/**
Expand Down Expand Up @@ -58,6 +59,21 @@ public void add(KeyValue kv) {

@Override
public KeyValue getResult() {
// 1. Find the latest high level record
Iterator<KeyValue> descending = candidates.descendingIterator();
KeyValue highLevel = null;
while (descending.hasNext()) {
KeyValue kv = descending.next();
if (kv.level() > 0) {
if (highLevel != null) {
descending.remove();
} else {
highLevel = kv;
}
}
}

// 2. Do the merge for inputs
mergeFunction.reset();
candidates.forEach(mergeFunction::add);
return mergeFunction.getResult();
Expand Down

0 comments on commit 12b2e88

Please sign in to comment.