diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-02-09 21:30:30 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-02-09 21:31:10 +1100 |
| commit | bbf62d1779b033f0efddfff49649c511273e210a (patch) | |
| tree | 6e6b63437a34a1072d097717c3ad6c8a3a45f37c /src/diff.hh | |
| parent | b7a3d80bde0fc0fbf20c72f5980e1674de808248 (diff) | |
diff: try to improve code readability
Diffstat (limited to 'src/diff.hh')
| -rw-r--r-- | src/diff.hh | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/diff.hh b/src/diff.hh index 49c5b504..cc6b52d4 100644 --- a/src/diff.hh +++ b/src/diff.hh @@ -14,9 +14,12 @@ namespace Kakoune { +// A snake is an edit followed by a (possibly empty) diagonal struct Snake { + // The end points of the diagonal (x, y) -> (u, v) int x, y, u, v; + // the edit op, reverse op happen at the end of the diagonal enum Op { Add, Del, RevAdd, RevDel } op; }; @@ -77,22 +80,23 @@ Snake find_middle_snake(Iterator a, int N, Iterator b, int M, // We did not find a minimal path in less than max_D iterations, iterate one more time finding the best Snake best{}; + auto score = [](const Snake& s) { return s.u + s.v; }; for (int k1 = -max_D; k1 <= max_D; k1 += 2) { auto p = find_end_snake_of_further_reaching_dpath(a, N, b, M, V1, max_D, k1, eq); V1[k1] = p.u; - if ((delta % 2 != 0) and p.u + p.v >= best.u + best.v and p.u <= N and p.v <= M) + if ((delta % 2 != 0) and p.u <= N and p.v <= M and score(p) >= score(best)) best = p; } for (int k2 = -max_D; k2 <= max_D; k2 += 2) { auto p = find_end_snake_of_further_reaching_dpath(ra, N, rb, M, V2, max_D, k2, eq); V2[k2] = p.u; - if ((delta % 2 == 0) and p.u + p.v >= best.u + best.v and p.u <= N and p.v <= M) + if ((delta % 2 == 0) and p.u <= N and p.v <= M and score(p) >= score(best)) best = {p.x, p.y, p.u, p.v, (Snake::Op)(p.op + Snake::RevAdd)}; } - if (best.op >= Snake::RevAdd) + if (best.op >= Snake::RevAdd) // reverse the snake now, as we were comparing snake length best = { N - best.u, M - best.v, N - best.x , M - best.y, best.op }; return best; } |
