* Finds the longest common subsequence between the arrays * aLines[aStart...aEnd] and bLines[bStart...bEnd], inclusive. Then for each * subsequence, recursively performs another LCS search (via addSubMatch), * until there are none found, at which point the subsequence is dumped to * the
(
aStart: number,
aEnd: number,
bStart: number,
bEnd: number,
uniqueCommonMap: Map<string, Subsequence> = uniqueCommon(
aLines,
aStart,
aEnd,
bLines,
bStart,
bEnd,
),
)
| 254 | * aLines[aStart...aEnd] and bLines[bStart...bEnd], inclusive. |
| 255 | */ |
| 256 | function recurseLCS( |
| 257 | aStart: number, |
| 258 | aEnd: number, |
| 259 | bStart: number, |
| 260 | bEnd: number, |
| 261 | uniqueCommonMap: Map<string, Subsequence> = uniqueCommon( |
| 262 | aLines, |
| 263 | aStart, |
| 264 | aEnd, |
| 265 | bLines, |
| 266 | bStart, |
| 267 | bEnd, |
| 268 | ), |
| 269 | ) { |
| 270 | const lcs = longestCommonSubsequence(uniqueCommonMap); |
| 271 | |
| 272 | if (lcs.length === 0) { |
| 273 | addSubMatch(aStart, aEnd, bStart, bEnd); |
| 274 | } else { |
| 275 | if (aStart < lcs[0].aIndex || bStart < lcs[0].bIndex) { |
| 276 | addSubMatch(aStart, lcs[0].aIndex - 1, bStart, lcs[0].bIndex - 1); |
| 277 | } |
| 278 | |
| 279 | let i; |
| 280 | for (i = 0; i < lcs.length - 1; i++) { |
| 281 | addSubMatch( |
| 282 | lcs[i].aIndex, |
| 283 | lcs[i + 1].aIndex - 1, |
| 284 | lcs[i].bIndex, |
| 285 | lcs[i + 1].bIndex - 1, |
| 286 | ); |
| 287 | } |
| 288 | |
| 289 | if (lcs[i].aIndex <= aEnd || lcs[i].bIndex <= bEnd) { |
| 290 | addSubMatch(lcs[i].aIndex, aEnd, lcs[i].bIndex, bEnd); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | recurseLCS(0, aLines.length - 1, 0, bLines.length - 1); |
| 296 |
no test coverage detected