MCPcopy Index your code
hub / github.com/nodejs/node / backtrack

Function backtrack

lib/internal/assert/myers_diff.js:80–125  ·  view source on GitHub ↗
(trace, actual, expected, checkCommaDisparity)

Source from the content-addressed store, hash-verified

78}
79
80function backtrack(trace, actual, expected, checkCommaDisparity) {
81 const actualLength = actual.length;
82 const expectedLength = expected.length;
83 const max = actualLength + expectedLength;
84
85 let x = actualLength;
86 let y = expectedLength;
87 const result = [];
88
89 for (let diffLevel = trace.length - 1; diffLevel >= 0; diffLevel--) {
90 const v = trace[diffLevel];
91 const diagonalIndex = x - y;
92 const offset = diagonalIndex + max;
93
94 let prevDiagonalIndex;
95 if (
96 diagonalIndex === -diffLevel ||
97 (diagonalIndex !== diffLevel && v[offset - 1] < v[offset + 1])
98 ) {
99 prevDiagonalIndex = diagonalIndex + 1;
100 } else {
101 prevDiagonalIndex = diagonalIndex - 1;
102 }
103
104 const prevX = v[prevDiagonalIndex + max];
105 const prevY = prevX - prevDiagonalIndex;
106
107 while (x > prevX && y > prevY) {
108 const actualItem = actual[x - 1];
109 const value = checkCommaDisparity && !StringPrototypeEndsWith(actualItem, ',') ? expected[y - 1] : actualItem;
110 ArrayPrototypePush(result, [ kOperations.NOP, value ]);
111 x--;
112 y--;
113 }
114
115 if (diffLevel > 0) {
116 if (x > prevX) {
117 ArrayPrototypePush(result, [ kOperations.INSERT, actual[--x] ]);
118 } else {
119 ArrayPrototypePush(result, [ kOperations.DELETE, expected[--y] ]);
120 }
121 }
122 }
123
124 return result;
125}
126
127function printSimpleMyersDiff(diff) {
128 let message = '';

Callers 1

myersDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…