MCPcopy
hub / github.com/bgrins/TinyColor / diff

Function diff

npm/deno_asserts@0.168.0.mjs:85–232  ·  view source on GitHub ↗
(A, B)

Source from the content-addressed store, hash-verified

83 return common;
84}
85function diff(A, B) {
86 const prefixCommon = createCommon(A, B);
87 const suffixCommon = createCommon(A.slice(prefixCommon.length), B.slice(prefixCommon.length), true).reverse();
88 A = suffixCommon.length ? A.slice(prefixCommon.length, -suffixCommon.length) : A.slice(prefixCommon.length);
89 B = suffixCommon.length ? B.slice(prefixCommon.length, -suffixCommon.length) : B.slice(prefixCommon.length);
90 const swapped = B.length > A.length;
91 [A, B] = swapped ? [
92 B,
93 A
94 ] : [
95 A,
96 B
97 ];
98 const M = A.length;
99 const N = B.length;
100 if (!M && !N && !suffixCommon.length && !prefixCommon.length) return [];
101 if (!N) {
102 return [
103 ...prefixCommon.map((c)=>({
104 type: DiffType.common,
105 value: c
106 })),
107 ...A.map((a)=>({
108 type: swapped ? DiffType.added : DiffType.removed,
109 value: a
110 })),
111 ...suffixCommon.map((c)=>({
112 type: DiffType.common,
113 value: c
114 }))
115 ];
116 }
117 const offset = N;
118 const delta = M - N;
119 const size = M + N + 1;
120 const fp = Array.from({
121 length: size
122 }, ()=>({
123 y: -1,
124 id: -1
125 }));
126 const routes = new Uint32Array((M * N + size + 1) * 2);
127 const diffTypesPtrOffset = routes.length / 2;
128 let ptr = 0;
129 let p = -1;
130 function backTrace(A, B, current, swapped) {
131 const M = A.length;
132 const N = B.length;
133 const result = [];
134 let a = M - 1;
135 let b = N - 1;
136 let j = routes[current.id];
137 let type = routes[current.id + diffTypesPtrOffset];
138 while(true){
139 if (!j && !type) break;
140 const prev = j;
141 if (type === 1) {
142 result.unshift({

Callers 3

diffstrFunction · 0.85
assertEqualsFunction · 0.85
assertStrictEqualsFunction · 0.85

Calls 3

createCommonFunction · 0.85
snakeFunction · 0.85
backTraceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…