| 92 | class TTmpFileSink // Sink to store temporary information. |
| 93 | > |
| 94 | TSignedWord DiffMyersSimple(TSrcVector const & A, TDstVector const & B, TSignedWord maxPatchSize, |
| 95 | TTmpFileSink & tmpSink) |
| 96 | { |
| 97 | ASSERT_GREATER(maxPatchSize, 0, ()); |
| 98 | std::vector<TSignedWord> V(2 * maxPatchSize + 1); |
| 99 | for (TSignedWord d = 0; d <= maxPatchSize; ++d) |
| 100 | { |
| 101 | for (TSignedWord k = -d; k <= d; k += 2) |
| 102 | { |
| 103 | TSignedWord x; |
| 104 | if (k == -d || (k != d && V[maxPatchSize + k - 1] < V[maxPatchSize + k + 1])) |
| 105 | x = V[maxPatchSize + k + 1]; |
| 106 | else |
| 107 | x = V[maxPatchSize + k - 1] + 1; |
| 108 | while (x < static_cast<TSignedWord>(A.size()) && x - k < static_cast<TSignedWord>(B.size()) && A[x] == B[x - k]) |
| 109 | ++x; |
| 110 | V[maxPatchSize + k] = x; |
| 111 | if (x == static_cast<TSignedWord>(A.size()) && x - k == static_cast<TSignedWord>(B.size())) |
| 112 | return d; |
| 113 | } |
| 114 | tmpSink.Write(&V[maxPatchSize - d], (2 * d + 1) * sizeof(TSignedWord)); |
| 115 | } |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | // Differ that just replaces old with new, with the only optimization of skipping equal values |
| 120 | // at the beginning and at the end. |