MCPcopy Create free account
hub / github.com/Effect-TS/effect / diffStrings

Function diffStrings

packages/effect/src/TextDiff.ts:752–765  ·  view source on GitHub ↗
(a: ReadonlyArray<string>, b: ReadonlyArray<string>, maxEdits?: number)

Source from the content-addressed store, hash-verified

750
751// Interns the tokens so the search compares integers instead of strings
752const diffStrings = (a: ReadonlyArray<string>, b: ReadonlyArray<string>, maxEdits?: number) => {
753 const ids = new Map<string, number>()
754 const intern = (token: string) => {
755 let id = ids.get(token)
756 if (id === undefined) {
757 id = ids.size
758 ids.set(token, id)
759 }
760 return id
761 }
762 const ai = Int32Array.from(a, intern)
763 const bi = Int32Array.from(b, intern)
764 return editScript(a, b, (i, j) => ai[i] === bi[j], maxEdits)
765}
766
767const editScript = <A>(
768 a: ReadonlyArray<A>,

Callers 2

linesFunction · 0.85
codePointsFunction · 0.85

Calls 2

editScriptFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected