File: intdiff.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 (49 lines) | stat: -rw-r--r-- 1,045 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

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

using namespace std;

using dtl::Diff;

int main(int, char**){
    
    int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int b[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10};
    int asiz = sizeof(a) / sizeof(int);
    int bsiz = sizeof(b) / sizeof(int);
    for (int i=0;i<asiz;++i) {
        cout << a[i] << " ";
    }
    cout << endl;
    for (int i=0;i<bsiz;++i) {
        cout << b[i] << " ";
    }
    cout << endl;
    
    typedef  int elem;
    typedef  vector< int > sequence;

    sequence A(&a[0], &a[asiz]);
    sequence B(&b[0], &b[bsiz]);
    Diff< elem > d(A, B);
    d.compose();

    // editDistance
    cout << "editDistance:" << d.getEditDistance() << endl;

    // Longest Common Subsequence
    sequence lcs_v = d.getLcsVec();
    cout << "LCS: ";
    for (sequence::iterator vit=lcs_v.begin();vit!=lcs_v.end();++vit) {
        cout << *vit << " ";
    }
    cout << endl;
    
    // Shortest Edit Script
    cout << "SES" << endl;
    d.printSES();
    
    return 0;
}