Longest common subsequence: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Clarified preferNextIndex2 optimization to the Hunt and Szymanski algorithm.)
Line 573: Line 573:


//
//
// Look ahead to the next index2 value to optimize space used in the Hunt
// Look ahead to the next index2 value to optimize Pairs used by the Hunt
// and Szymanski algorithm. If the next index2 is also an improvement on
// and Szymanski algorithm. If the next index2 is also an improvement on
// the value currently held in threshold[index3], a new Pair will only be
// the value currently held in threshold[index3], a new Pair will only be
// superseded on the next index2 iteration.
// superseded on the next index2 iteration.
//
//
// Depending on match redundancy, the number of Pair constructions may be
// Verify the next value of index2 will be greater than the final element
// divided by factors ranging from 2 up to 10 or more.
// of the next shorter LCS at prev(limit):
//
//
auto skipIndex2 = next(it2) != dq2.rend() &&
auto preferNextIndex2 = next(it2) != dq2.rend() &&
(limit == threshold.begin() || *prev(limit) < *next(it2));
(limit == threshold.begin() || *prev(limit) < *next(it2));

//
// Depending on match redundancy, this optimization may reduce the number
// of Pair allocations by factors ranging from 2 up to 10 or more.
//
if (skipIndex2) continue;
if (skipIndex2) continue;