MCPcopy
hub / github.com/midrender/revideo / findUnique

Function findUnique

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

* Finds all unique values in lines[start...end], inclusive. This * function is used in preparation for determining the longest common * subsequence. * * @param lines - The array to search * @param start - The starting index (inclusive) * @param end - The ending index (inclusive)

(lines: string[], start: number, end: number)

Source from the content-addressed store, hash-verified

42 * @returns A map of the unique lines to their index
43 */
44 function findUnique(lines: string[], start: number, end: number) {
45 const lineMap = new Map<string, {count: number; index: number}>();
46 for (let i = start; i <= end; i++) {
47 const line = lines[i];
48 const data = lineMap.get(line);
49 if (data) {
50 data.count++;
51 data.index = i;
52 } else {
53 lineMap.set(line, {count: 1, index: i});
54 }
55 }
56
57 const newMap = new Map<string, number>();
58 for (const [key, value] of lineMap) {
59 if (value.count === 1) {
60 newMap.set(key, value.index);
61 }
62 }
63
64 return newMap;
65 }
66
67 /**
68 * Finds all the unique common entries between aArray[aStart...aEnd] and

Callers 1

uniqueCommonFunction · 0.85

Calls 2

setMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected