MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / withinEdits

Function withinEdits

graph-ui/src/browser-ai/relationship-answer.ts:86–99  ·  view source on GitHub ↗
(left: string, right: string, limit: number)

Source from the content-addressed store, hash-verified

84
85/** Optimal string alignment distance of at most `limit`. */
86export function withinEdits(left: string, right: string, limit: number): boolean {
87 if (Math.abs(left.length - right.length) > limit) return false;
88 const rows = [Array.from({ length: right.length + 1 }, (_, index) => index)];
89 for (let i = 1; i <= left.length; i++) {
90 const row = [i];
91 for (let j = 1; j <= right.length; j++) {
92 const cost = left[i - 1] === right[j - 1] ? 0 : 1;
93 row[j] = Math.min(rows[i - 1][j] + 1, row[j - 1] + 1, rows[i - 1][j - 1] + cost);
94 if (i > 1 && j > 1 && left[i - 1] === right[j - 2] && left[i - 2] === right[j - 1]) row[j] = Math.min(row[j], rows[i - 2][j - 2] + 1);
95 }
96 rows.push(row);
97 }
98 return rows[left.length][right.length] <= limit;
99}
100const withinOneEdit = (left: string, right: string) => withinEdits(left, right, 1);
101
102/** "wer ruf X auf", "who cals X", "aufgerufn": a relation word with one typo reads as the word. */

Callers 5

normalizeFunction · 0.90
knownNamesFunction · 0.90
sameFunction · 0.90
withinOneEditFunction · 0.85
nearSelectionFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected