File: intdiff3.cpp

package info (click to toggle)
dtl 1.19-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 424 kB
  • sloc: cpp: 2,214; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

using dtl::Diff3;

int main(int, char**) {
    
    int a[10]      = {1, 2, 3, 4, 5, 6, 7, 3, 9, 10};
    int b[10]      = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int c[10]      = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10};
    int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10};
    
    cout << "a:";
    for (int i=0;i<10;++i) {
        cout << a[i] << " ";
    }
    cout << endl;
    cout << "b:";
    for (int i=0;i<10;++i) {
        cout << b[i] << " ";
    }
    cout << endl;
    cout << "c:";
    for (int i=0;i<10;++i) {
        cout << c[i] << " ";
    }
    cout << endl;
    
    typedef int elem;
    typedef vector< int > sequence;
    sequence A(&a[0], &a[10]);
    sequence B(&b[0], &b[10]);
    sequence C(&c[0], &c[10]);
    sequence Answer(&answer[0], &answer[10]);
    Diff3< elem > diff3(A, B, C);
    diff3.compose();
    if (!diff3.merge()) {
        cerr << "conflict." << endl;
        return -1;
    }
    sequence s = diff3.getMergedSequence();
    cout << "s:";
    for (sequence::iterator it=s.begin();it!=s.end();++it) {
        cout << *it << " ";
    }
    cout << endl;
    
    assert(s == Answer);
    cout << "intdiff3 OK" << endl;
    
    return 0;
}