MCPcopy Create free account
hub / github.com/comaps/comaps / DiffMyersSimple

Function DiffMyersSimple

libs/coding/diff.hpp:94–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92 class TTmpFileSink // Sink to store temporary information.
93 >
94TSignedWord 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.

Callers 1

UNIT_TESTFunction · 0.85

Calls 2

sizeMethod · 0.45
WriteMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.68