MCPcopy Create free account
hub / github.com/arktypeio/arktype / diffOf

Function diffOf

ark/aot/unwrite.ts:481–517  ·  view source on GitHub ↗
(
	base: string[],
	other: string[],
	from = 0,
	to = base.length,
	otherFrom = 0,
	otherTo = other.length
)

Source from the content-addressed store, hash-verified

479 }
480
481const diffOf = (
482 base: string[],
483 other: string[],
484 from = 0,
485 to = base.length,
486 otherFrom = 0,
487 otherTo = other.length
488): Hunk[] => {
489 const hunks: Hunk[] = []
490 const compare = (b0: number, b1: number, o0: number, o1: number): void => {
491 while (b0 < b1 && o0 < o1 && base[b0] === other[o0]) {
492 b0++
493 o0++
494 }
495 while (b0 < b1 && o0 < o1 && base[b1 - 1] === other[o1 - 1]) {
496 b1--
497 o1--
498 }
499 if (b0 === b1 && o0 === o1) return
500 if (b0 === b1 || o0 === o1) return void hunks.push([b0, b1, o0, o1])
501 const anchors = anchorsOf(base, other, b0, b1, o0, o1)
502 if (anchors.length) {
503 let [b, o] = [b0, o0]
504 for (const [anchor, otherAnchor] of anchors) {
505 compare(b, anchor, o, otherAnchor)
506 b = anchor + 1
507 o = otherAnchor + 1
508 }
509 return compare(b, b1, o, o1)
510 }
511 if ((b1 - b0) * (o1 - o0) > maxCompared)
512 return void hunks.push([b0, b1, o0, o1])
513 compareEach(base, other, b0, b1, o0, o1, hunks)
514 }
515 compare(from, to, otherFrom, otherTo)
516 return hunks
517}
518
519// tokens each list holds once within the runs, in the order both have them,
520// as a patience diff finds them: what a module declares or imports is mostly

Callers 2

compareFunction · 0.85
diffFunction · 0.85

Calls 1

compareFunction · 0.70

Tested by

no test coverage detected