Skip to content

Commit

Permalink
INTERNAL: Add comments to new SMGetResult merge method.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhm0311 committed Dec 27, 2023
1 parent 5ad8753 commit e0420d6
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,34 @@ public void mergeSMGetElements(final List<SMGetElement<T>> eachResult,
}
} else {
// do sort merge
boolean duplicated;
boolean doInsert; // Is current eachResult could be inserted?
int comp, pos = 0;
for (SMGetElement<T> result : eachResult) {
duplicated = false;
doInsert = true;
for (; pos < mergedResult.size(); pos++) {
// compare b+tree key
comp = result.compareBkeyTo(mergedResult.get(pos));
if ((reverse) ? (0 < comp) : (0 > comp)) {
if ((reverse) ? (comp > 0) : (comp < 0)) {
break;
}
if (comp == 0) { // compare key string
if (comp == 0) {
// Duplicated bkey. Compare the "cache key".
int keyComp = result.compareKeyTo(mergedResult.get(pos));
if ((reverse) ? (0 < keyComp) : (0 > keyComp)) {
if ((reverse) ? (keyComp > 0) : (keyComp < 0)) {
if (unique) {
mergedResult.remove(pos); // remove dup bkey
// Remove duplicated bkey.
mergedResult.remove(pos);
}
break;
} else {
if (unique) {
duplicated = true;
// NOT the first cache key with the same bkey. do NOT insert.
doInsert = false;
break;
}
}
}
}
if (duplicated) { // UNIQUE
if (!doInsert) { // UNIQUE
continue;
}
if (pos >= count) {
Expand All @@ -80,7 +82,6 @@ public void mergeSMGetElements(final List<SMGetElement<T>> eachResult,
}
mergedResult.add(pos, result);
if (mergedResult.size() > count) {
// Remove elements that exceed the requested count.
mergedResult.remove(count);
}
pos += 1;
Expand All @@ -92,11 +93,11 @@ public void mergeSMGetElements(final List<SMGetElement<T>> eachResult,
mergedTrimmedKeys.addAll(eachTrimmedResult);
} else {
// do sort merge trimmed list
int pos = 0;
int comp, pos = 0;
for (SMGetTrimKey result : eachTrimmedResult) {
for (; pos < mergedTrimmedKeys.size(); pos++) {
if ((reverse) ? (0 < result.compareTo(mergedTrimmedKeys.get(pos)))
: (0 > result.compareTo(mergedTrimmedKeys.get(pos)))) {
comp = result.compareTo(mergedTrimmedKeys.get(pos));
if ((reverse) ? (comp > 0) : (comp < 0)) {
break;
}
}
Expand Down

0 comments on commit e0420d6

Please sign in to comment.