MCPcopy Index your code
hub / github.com/midrender/revideo / recurseLCS

Function recurseLCS

packages/2d/src/lib/code/diff.ts:256–293  ·  view source on GitHub ↗

* 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,
    ),
  )

Source from the content-addressed store, hash-verified

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

Callers 2

addSubMatchFunction · 0.85
patienceDiffFunction · 0.85

Calls 3

uniqueCommonFunction · 0.85
longestCommonSubsequenceFunction · 0.85
addSubMatchFunction · 0.85

Tested by

no test coverage detected