(actual, expected, checkCommaDisparity = false)
| 32 | } |
| 33 | |
| 34 | function myersDiff(actual, expected, checkCommaDisparity = false) { |
| 35 | const actualLength = actual.length; |
| 36 | const expectedLength = expected.length; |
| 37 | const max = actualLength + expectedLength; |
| 38 | |
| 39 | if (max > 2 ** 31 - 1) { |
| 40 | throw new ERR_OUT_OF_RANGE( |
| 41 | 'myersDiff input size', |
| 42 | '< 2^31', |
| 43 | max, |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | const v = new Int32Array(2 * max + 1); |
| 48 | const trace = []; |
| 49 | |
| 50 | for (let diffLevel = 0; diffLevel <= max; diffLevel++) { |
| 51 | ArrayPrototypePush(trace, new Int32Array(v)); // Clone the current state of `v` |
| 52 | |
| 53 | for (let diagonalIndex = -diffLevel; diagonalIndex <= diffLevel; diagonalIndex += 2) { |
| 54 | const offset = diagonalIndex + max; |
| 55 | const previousOffset = v[offset - 1]; |
| 56 | const nextOffset = v[offset + 1]; |
| 57 | let x = diagonalIndex === -diffLevel || (diagonalIndex !== diffLevel && previousOffset < nextOffset) ? |
| 58 | nextOffset : |
| 59 | previousOffset + 1; |
| 60 | let y = x - diagonalIndex; |
| 61 | |
| 62 | while ( |
| 63 | x < actualLength && |
| 64 | y < expectedLength && |
| 65 | areLinesEqual(actual[x], expected[y], checkCommaDisparity) |
| 66 | ) { |
| 67 | x++; |
| 68 | y++; |
| 69 | } |
| 70 | |
| 71 | v[offset] = x; |
| 72 | |
| 73 | if (x >= actualLength && y >= expectedLength) { |
| 74 | return backtrack(trace, actual, expected, checkCommaDisparity); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | function backtrack(trace, actual, expected, checkCommaDisparity) { |
| 81 | const actualLength = actual.length; |
no test coverage detected
searching dependent graphs…