LCS: other fixes to range emission.
This commit is contained in:
parent
2b67b6b87e
commit
4aa24e62a4
@ -584,12 +584,13 @@ void lcsCommand(client *c) {
|
||||
|
||||
i = alen, j = blen;
|
||||
while (computelcs && i > 0 && j > 0) {
|
||||
int emit_range = 0;
|
||||
if (a[i-1] == b[j-1]) {
|
||||
/* If there is a match, store the character and reduce
|
||||
* the indexes to look for a new match. */
|
||||
result[idx-1] = a[i-1];
|
||||
|
||||
/* Track the current range. */
|
||||
int emit_range = 0;
|
||||
if (arange_start == alen) {
|
||||
arange_start = i-1;
|
||||
arange_end = i-1;
|
||||
@ -605,7 +606,21 @@ void lcsCommand(client *c) {
|
||||
emit_range = 1;
|
||||
}
|
||||
}
|
||||
/* Emit the range if we matched with the first byte of
|
||||
* one of the two strings. We'll exit the loop ASAP. */
|
||||
if (arange_start == 0 || brange_start == 0) emit_range = 1;
|
||||
idx--; i--; j--;
|
||||
} else {
|
||||
/* Otherwise reduce i and j depending on the largest
|
||||
* LCS between, to understand what direction we need to go. */
|
||||
uint32_t lcs1 = LCS(i-1,j);
|
||||
uint32_t lcs2 = LCS(i,j-1);
|
||||
if (lcs1 > lcs2)
|
||||
i--;
|
||||
else
|
||||
j--;
|
||||
if (arange_start != alen) emit_range = 1;
|
||||
}
|
||||
|
||||
/* Emit the current range if needed. */
|
||||
if (emit_range) {
|
||||
@ -621,17 +636,6 @@ void lcsCommand(client *c) {
|
||||
arange_start = alen; /* Restart at the next match. */
|
||||
arraylen++;
|
||||
}
|
||||
idx--; i--; j--;
|
||||
} else {
|
||||
/* Otherwise reduce i and j depending on the largest
|
||||
* LCS between, to understand what direction we need to go. */
|
||||
uint32_t lcs1 = LCS(i-1,j);
|
||||
uint32_t lcs2 = LCS(i,j-1);
|
||||
if (lcs1 > lcs2)
|
||||
i--;
|
||||
else
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal modified key, increment dirty, ... */
|
||||
|
Loading…
x
Reference in New Issue
Block a user