From 60782b3dc93b7bbc38e148e85dffe2f1ad6a4542 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 18 Feb 2020 19:26:01 +1100 Subject: [PATCH] Make diff implementation able to work on different iterator types --- src/diff.hh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/diff.hh b/src/diff.hh index 2e719669..20fd53d1 100644 --- a/src/diff.hh +++ b/src/diff.hh @@ -24,8 +24,8 @@ struct Snake enum Op { Add, Del, RevAdd, RevDel } op; }; -template -Snake find_end_snake_of_further_reaching_dpath(Iterator a, int N, Iterator b, int M, +template +Snake find_end_snake_of_further_reaching_dpath(IteratorA a, int N, IteratorB b, int M, const int* V, const int D, const int k, Equal eq) { const bool add = k == -D or (k != D and V[k-1] < V[k+1]); @@ -45,15 +45,16 @@ Snake find_end_snake_of_further_reaching_dpath(Iterator a, int N, Iterator b, in return { x, y, u, v, add ? Snake::Add : Snake::Del }; } -template -Snake find_middle_snake(Iterator a, int N, Iterator b, int M, +template +Snake find_middle_snake(IteratorA a, int N, IteratorB b, int M, int* V1, int* V2, int cost_limit, Equal eq) { const int delta = N - M; V1[1] = 0; V2[1] = 0; - std::reverse_iterator ra{a + N}, rb{b + M}; + std::reverse_iterator ra{a + N}; + std::reverse_iterator rb{b + M}; const int max_D = std::min((M + N + 1) / 2 + 1, cost_limit); for (int D = 0; D < max_D; ++D) { @@ -109,9 +110,9 @@ enum class DiffOp Remove }; -template -void find_diff_rec(Iterator a, int begA, int endA, - Iterator b, int begB, int endB, +template +void find_diff_rec(IteratorA a, int begA, int endA, + IteratorB b, int begB, int endB, int* V1, int* V2, int cost_limit, Equal eq, OnDiff&& on_diff) { @@ -172,8 +173,8 @@ struct Diff int posB; }; -template> -void for_each_diff(Iterator a, int N, Iterator b, int M, OnDiff&& on_diff, Equal eq = Equal{}) +template> +void for_each_diff(IteratorA a, int N, IteratorB b, int M, OnDiff&& on_diff, Equal eq = Equal{}) { const int max = 2 * (N + M) + 1; std::unique_ptr data(new int[2*max]);