Make diff implementation able to work on different iterator types
This commit is contained in:
parent
ce93a7b032
commit
60782b3dc9
21
src/diff.hh
21
src/diff.hh
|
@ -24,8 +24,8 @@ struct Snake
|
|||
enum Op { Add, Del, RevAdd, RevDel } op;
|
||||
};
|
||||
|
||||
template<typename Iterator, typename Equal>
|
||||
Snake find_end_snake_of_further_reaching_dpath(Iterator a, int N, Iterator b, int M,
|
||||
template<typename IteratorA, typename IteratorB, typename Equal>
|
||||
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<typename Iterator, typename Equal>
|
||||
Snake find_middle_snake(Iterator a, int N, Iterator b, int M,
|
||||
template<typename IteratorA, typename IteratorB, typename Equal>
|
||||
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<Iterator> ra{a + N}, rb{b + M};
|
||||
std::reverse_iterator<IteratorA> ra{a + N};
|
||||
std::reverse_iterator<IteratorB> 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<typename Iterator, typename Equal, typename OnDiff>
|
||||
void find_diff_rec(Iterator a, int begA, int endA,
|
||||
Iterator b, int begB, int endB,
|
||||
template<typename IteratorA, typename IteratorB, typename Equal, typename OnDiff>
|
||||
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<typename Iterator, typename OnDiff, typename Equal = std::equal_to<>>
|
||||
void for_each_diff(Iterator a, int N, Iterator b, int M, OnDiff&& on_diff, Equal eq = Equal{})
|
||||
template<typename IteratorA, typename IteratorB, typename OnDiff, typename Equal = std::equal_to<>>
|
||||
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<int[]> data(new int[2*max]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user