Longest common subsequence: Difference between revisions

m
Clarified naming of the FindLCS() method, traceLCS bool, and chains deque.
(Resorted to verbose typedef and parameter names to help clarify their purpose.)
m (Clarified naming of the FindLCS() method, traceLCS bool, and chains deque.)
Line 493:
typedef deque<INDEXES*> MATCHES;
 
uint32_t PairsFindLCS(MATCHES& indexesOf2MatchedByIndex1, shared_ptr<Pair>* pairs) {
auto tracetraceLCS = pairs != nullptr;
PAIRS traceschains;
THRESHOLD threshold;
 
Line 528:
// divided by factors ranging from 2 up to 10 or more.
//
auto skipskipIndex2 = next(it2) != dq2.rend() &&
(limit == threshold.begin() || *prev(limit) < *next(it2));
if (skipskipIndex2) continue;
 
if (limit == threshold.end()) {
// insertInsert caseCase
threshold.push_back(index2);
// Refresh limit iterator:
limit = prev(threshold.end());
if (tracetraceLCS) {
auto prefix = index3 > 0 ? traceschains[index3 - 1] : nullptr;
auto last = make_shared<Pair>(index1, index2, prefix);
traceschains.push_back(last);
}
}
else if (index2 < *limit) {
// replacementUpdate caseCase
// Update limit value:
*limit = index2;
if (tracetraceLCS) {
auto prefix = index3 > 0 ? traceschains[index3 - 1] : nullptr;
auto last = make_shared<Pair>(index1, index2, prefix);
traceschains[index3] = last;
}
}
Line 558 ⟶ 559:
} // next index1
 
if (tracetraceLCS) {
// Return the LCS as a linked list of matched index pairs:
auto last = traceschains.size() > 0 ? traceschains.back() : nullptr;
// Reverse longest back-tracechain
*pairs = Pair::Reverse(last);
}
Line 606 ⟶ 607:
Match(indexesOf2MatchedByChar, indexesOf2MatchedByIndex1, s1, s2);
shared_ptr<Pair> pairs; // obtain the LCS as index pairs
auto length = PairsFindLCS(indexesOf2MatchedByIndex1, &pairs);
return Select(pairs, length, false, s1, s2);
}
159

edits