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;
|
enum Op { Add, Del, RevAdd, RevDel } op;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Iterator, typename Equal>
|
template<typename IteratorA, typename IteratorB, typename Equal>
|
||||||
Snake find_end_snake_of_further_reaching_dpath(Iterator a, int N, Iterator b, int M,
|
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 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]);
|
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 };
|
return { x, y, u, v, add ? Snake::Add : Snake::Del };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator, typename Equal>
|
template<typename IteratorA, typename IteratorB, typename Equal>
|
||||||
Snake find_middle_snake(Iterator a, int N, Iterator b, int M,
|
Snake find_middle_snake(IteratorA a, int N, IteratorB b, int M,
|
||||||
int* V1, int* V2, int cost_limit, Equal eq)
|
int* V1, int* V2, int cost_limit, Equal eq)
|
||||||
{
|
{
|
||||||
const int delta = N - M;
|
const int delta = N - M;
|
||||||
V1[1] = 0;
|
V1[1] = 0;
|
||||||
V2[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);
|
const int max_D = std::min((M + N + 1) / 2 + 1, cost_limit);
|
||||||
for (int D = 0; D < max_D; ++D)
|
for (int D = 0; D < max_D; ++D)
|
||||||
{
|
{
|
||||||
|
@ -109,9 +110,9 @@ enum class DiffOp
|
||||||
Remove
|
Remove
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Iterator, typename Equal, typename OnDiff>
|
template<typename IteratorA, typename IteratorB, typename Equal, typename OnDiff>
|
||||||
void find_diff_rec(Iterator a, int begA, int endA,
|
void find_diff_rec(IteratorA a, int begA, int endA,
|
||||||
Iterator b, int begB, int endB,
|
IteratorB b, int begB, int endB,
|
||||||
int* V1, int* V2, int cost_limit,
|
int* V1, int* V2, int cost_limit,
|
||||||
Equal eq, OnDiff&& on_diff)
|
Equal eq, OnDiff&& on_diff)
|
||||||
{
|
{
|
||||||
|
@ -172,8 +173,8 @@ struct Diff
|
||||||
int posB;
|
int posB;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Iterator, typename OnDiff, typename Equal = std::equal_to<>>
|
template<typename IteratorA, typename IteratorB, 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{})
|
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;
|
const int max = 2 * (N + M) + 1;
|
||||||
std::unique_ptr<int[]> data(new int[2*max]);
|
std::unique_ptr<int[]> data(new int[2*max]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user