Compare commits
24 Commits
gtest-upda
...
0e4c24a23d
Author | SHA1 | Date | |
---|---|---|---|
0e4c24a23d | |||
2e266fa5ee | |||
988e91555f | |||
cd45dd4808 | |||
946dc4cecb | |||
ebd9a49db9 | |||
18e674e4a6 | |||
0551c22f5e | |||
32787c066d | |||
ab0b64b43a | |||
831aeecf1f | |||
ebbde693a5 | |||
b83e617aab | |||
ea5975a080 | |||
ef50138616 | |||
ca3fa6846a | |||
afddfbccf6 | |||
6b030d6397 | |||
1bcddbf879 | |||
61c30c7836 | |||
9cf6da7279 | |||
45c54b42d3 | |||
33a68d8c2d | |||
424ab0dbb7 |
30
.github/workflows/cpp.yml
vendored
Normal file
30
.github/workflows/cpp.yml
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
name: C++
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install scons and gtest
|
||||||
|
run: |
|
||||||
|
sudo apt-get install -y scons
|
||||||
|
sudo apt-get install -y cmake scons
|
||||||
|
wget https://github.com/google/googletest/archive/release-1.11.0.zip
|
||||||
|
unzip -q release-1.11.0.zip
|
||||||
|
cd googletest-release-1.11.0
|
||||||
|
cmake .
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
- name: Build examples
|
||||||
|
run: |
|
||||||
|
cd examples
|
||||||
|
scons
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
cd test
|
||||||
|
scons check
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ examples/intdiff3
|
|||||||
examples/patch
|
examples/patch
|
||||||
examples/fpatch
|
examples/fpatch
|
||||||
examples/st2ses
|
examples/st2ses
|
||||||
|
examples/strdiff_storage
|
||||||
test/strdiff3_test
|
test/strdiff3_test
|
||||||
test/*/*/*_
|
test/*/*/*_
|
||||||
*.o
|
*.o
|
||||||
|
18
.travis.yml
18
.travis.yml
@ -1,18 +0,0 @@
|
|||||||
language: cpp
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
- clang
|
|
||||||
before_script:
|
|
||||||
- sudo apt-get install -y cmake
|
|
||||||
- wget https://github.com/google/googletest/archive/release-1.8.0.zip
|
|
||||||
- unzip -q release-1.8.0.zip
|
|
||||||
- cd googletest-release-1.8.0
|
|
||||||
- cmake .
|
|
||||||
- make
|
|
||||||
- sudo make install
|
|
||||||
- cd ..
|
|
||||||
script:
|
|
||||||
- cd examples
|
|
||||||
- scons
|
|
||||||
- cd ../test
|
|
||||||
- scons check
|
|
@ -1,3 +1,9 @@
|
|||||||
|
2022-04-11 Tatsuhiko Kubo <cubicdaiya@gmail.com>
|
||||||
|
|
||||||
|
* bugfix: fixed invalid offset in unified format difference when difference is too large.
|
||||||
|
|
||||||
|
* 1.20 released
|
||||||
|
|
||||||
2015-05-03 Tatsuhiko Kubo <cubicdaiya@gmail.com>
|
2015-05-03 Tatsuhiko Kubo <cubicdaiya@gmail.com>
|
||||||
|
|
||||||
* added some minor changes.
|
* added some minor changes.
|
||||||
|
54
README.md
54
README.md
@ -1,6 +1,4 @@
|
|||||||
# dtl
|
# dtl - forked from [https://github.com/cubicdaiya/dtl](https://github.com/cubicdaiya/dtl)
|
||||||
|
|
||||||
[](https://travis-ci.org/cubicdaiya/dtl)
|
|
||||||
|
|
||||||
`dtl` is the diff template library written in C++. The name of template is derived C++'s Template.
|
`dtl` is the diff template library written in C++. The name of template is derived C++'s Template.
|
||||||
|
|
||||||
@ -8,30 +6,30 @@
|
|||||||
|
|
||||||
* [Features](#features)
|
* [Features](#features)
|
||||||
* [Getting started](#getting-started)
|
* [Getting started](#getting-started)
|
||||||
* [Compare two strings](#compare-two-strings)
|
* [Compare two strings](#compare-two-strings)
|
||||||
* [Compare two data has arbitrary type](#compare-two-data-has-arbitrary-type)
|
* [Compare two data has arbitrary type](#compare-two-data-has-arbitrary-type)
|
||||||
* [Merge three sequences](#merge-three-sequences)
|
* [Merge three sequences](#merge-three-sequences)
|
||||||
* [Patch function](#patch-function)
|
* [Patch function](#patch-function)
|
||||||
* [Difference as Unified Format](#difference-as-unified-format)
|
* [Difference as Unified Format](#difference-as-unified-format)
|
||||||
* [Compare large sequences](#compare-large-sequences)
|
* [Compare large sequences](#compare-large-sequences)
|
||||||
* [Unserious difference](#unserious-difference)
|
* [Unserious difference](#unserious-difference)
|
||||||
* [Calculate only Edit Distance](#calculate-only-edit-distance)
|
* [Calculate only Edit Distance](#calculate-only-edit-distance)
|
||||||
* [Algorithm](#algorithm)
|
* [Algorithm](#algorithm)
|
||||||
* [Computational complexity](#computational-complexity)
|
* [Computational complexity](#computational-complexity)
|
||||||
* [Comparison when difference between two sequences is very large](#comparison-when-difference-between-two-sequences-is-very-large)
|
* [Comparison when difference between two sequences is very large](#comparison-when-difference-between-two-sequences-is-very-large)
|
||||||
* [Implementations with various programming languages](#implementations-with-various-programming-languages)
|
* [Implementations with various programming languages](#implementations-with-various-programming-languages)
|
||||||
* [Examples](#examples)
|
* [Examples](#examples)
|
||||||
* [strdiff](#strdiff)
|
* [strdiff](#strdiff)
|
||||||
* [intdiff](#intdiff)
|
* [intdiff](#intdiff)
|
||||||
* [unidiff](#unidiff)
|
* [unidiff](#unidiff)
|
||||||
* [unistrdiff](#unistrdiff)
|
* [unistrdiff](#unistrdiff)
|
||||||
* [strdiff3](#strdiff3)
|
* [strdiff3](#strdiff3)
|
||||||
* [intdiff3](#intdiff3)
|
* [intdiff3](#intdiff3)
|
||||||
* [patch](#patch)
|
* [patch](#patch)
|
||||||
* [fpatch](#fpatch)
|
* [fpatch](#fpatch)
|
||||||
* [Running tests](#running-tests)
|
* [Running tests](#running-tests)
|
||||||
* [Building test programs](#building-test-programs)
|
* [Building test programs](#building-test-programs)
|
||||||
* [Running test programs](#running-test-programs)
|
* [Running test programs](#running-test-programs)
|
||||||
* [Old commit histories](#old-commit-histories)
|
* [Old commit histories](#old-commit-histories)
|
||||||
* [License](#license)
|
* [License](#license)
|
||||||
|
|
||||||
@ -253,7 +251,7 @@ dtl::Diff<elem, sequence> d(A, B);
|
|||||||
d.compose();
|
d.compose();
|
||||||
d.composeUnifiedHunks()
|
d.composeUnifiedHunks()
|
||||||
string s1(A);
|
string s1(A);
|
||||||
string s2 = d.UniPatch(s1);
|
string s2 = d.uniPatch(s1);
|
||||||
```
|
```
|
||||||
|
|
||||||
When the above code is run, s2 becomes "abd".
|
When the above code is run, s2 becomes "abd".
|
||||||
@ -650,14 +648,14 @@ $
|
|||||||
|
|
||||||
# Running tests
|
# Running tests
|
||||||
|
|
||||||
`dtl` uses [googletest](http://code.google.com/p/googletest/) and [SCons](http://www.scons.org/) with testing dtl-self.
|
`dtl` uses [googletest](https://github.com/google/googletest) and [SCons](http://www.scons.org/) with testing dtl-self.
|
||||||
|
|
||||||
# Building test programs
|
# Building test programs
|
||||||
|
|
||||||
If you build test programs for `dtl`, run `scons` in test direcotry.
|
If you build test programs for `dtl`, run `scons` in test direcotry.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ GTEST_ROOT=${gtest_root_dir} scons
|
$ scons
|
||||||
```
|
```
|
||||||
|
|
||||||
# Running test programs
|
# Running test programs
|
||||||
@ -665,7 +663,7 @@ $ GTEST_ROOT=${gtest_root_dir} scons
|
|||||||
If you run all tests for `dtl`, run 'scons check' in test direcotry. (it is necessary that gtest is compiled)
|
If you run all tests for `dtl`, run 'scons check' in test direcotry. (it is necessary that gtest is compiled)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ GTEST_ROOT=${gtest_root_dir} scons check
|
$ scons check
|
||||||
```
|
```
|
||||||
|
|
||||||
If you run sectional tests, you may exeucte `dtl_test` directly after you run `scons`.
|
If you run sectional tests, you may exeucte `dtl_test` directly after you run `scons`.
|
||||||
|
34
dtl/Diff.hpp
34
dtl/Diff.hpp
@ -67,6 +67,8 @@ namespace dtl {
|
|||||||
bool editDistanceOnly;
|
bool editDistanceOnly;
|
||||||
uniHunkVec uniHunks;
|
uniHunkVec uniHunks;
|
||||||
comparator cmp;
|
comparator cmp;
|
||||||
|
long long ox;
|
||||||
|
long long oy;
|
||||||
public :
|
public :
|
||||||
Diff () {}
|
Diff () {}
|
||||||
|
|
||||||
@ -162,7 +164,7 @@ namespace dtl {
|
|||||||
return trivial;
|
return trivial;
|
||||||
}
|
}
|
||||||
|
|
||||||
void enableTrivial () const {
|
void enableTrivial () {
|
||||||
this->trivial = true;
|
this->trivial = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +262,8 @@ namespace dtl {
|
|||||||
if (isHuge()) {
|
if (isHuge()) {
|
||||||
pathCordinates.reserve(MAX_CORDINATES_SIZE);
|
pathCordinates.reserve(MAX_CORDINATES_SIZE);
|
||||||
}
|
}
|
||||||
|
ox = 0;
|
||||||
|
oy = 0;
|
||||||
long long p = -1;
|
long long p = -1;
|
||||||
fp = new long long[M + N + 3];
|
fp = new long long[M + N + 3];
|
||||||
fill(&fp[0], &fp[M + N + 3], -1);
|
fill(&fp[0], &fp[M + N + 3], -1);
|
||||||
@ -280,7 +283,7 @@ namespace dtl {
|
|||||||
|
|
||||||
editDistance += static_cast<long long>(delta) + 2 * p;
|
editDistance += static_cast<long long>(delta) + 2 * p;
|
||||||
long long r = path[delta+offset];
|
long long r = path[delta+offset];
|
||||||
P cordinate;
|
P cordinate{};
|
||||||
editPathCordinates epc(0);
|
editPathCordinates epc(0);
|
||||||
|
|
||||||
// recording edit distance only
|
// recording edit distance only
|
||||||
@ -341,6 +344,15 @@ namespace dtl {
|
|||||||
for_each (ses_v.begin (), ses_v.end(), PT < sesElem, stream > (out));
|
for_each (ses_v.begin (), ses_v.end(), PT < sesElem, stream > (out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* store difference between A and B as an SES with custom storage
|
||||||
|
*/
|
||||||
|
template < typename storedData, template < typename SEET, typename STRT > class ST >
|
||||||
|
void storeSES(storedData& sd) const {
|
||||||
|
sesElemVec ses_v = ses.getSequence();
|
||||||
|
for_each(ses_v.begin(), ses_v.end(), ST < sesElem, storedData >(sd));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print difference between A and B in the Unified Format
|
* print difference between A and B in the Unified Format
|
||||||
*/
|
*/
|
||||||
@ -549,6 +561,8 @@ namespace dtl {
|
|||||||
trivial = false;
|
trivial = false;
|
||||||
editDistanceOnly = false;
|
editDistanceOnly = false;
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
|
ox = 0;
|
||||||
|
oy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -586,18 +600,18 @@ namespace dtl {
|
|||||||
while(px_idx < v[i].x || py_idx < v[i].y) {
|
while(px_idx < v[i].x || py_idx < v[i].y) {
|
||||||
if (v[i].y - v[i].x > py_idx - px_idx) {
|
if (v[i].y - v[i].x > py_idx - px_idx) {
|
||||||
if (!wasSwapped()) {
|
if (!wasSwapped()) {
|
||||||
ses.addSequence(*y, 0, y_idx, SES_ADD);
|
ses.addSequence(*y, 0, y_idx + oy, SES_ADD);
|
||||||
} else {
|
} else {
|
||||||
ses.addSequence(*y, y_idx, 0, SES_DELETE);
|
ses.addSequence(*y, y_idx + oy, 0, SES_DELETE);
|
||||||
}
|
}
|
||||||
++y;
|
++y;
|
||||||
++y_idx;
|
++y_idx;
|
||||||
++py_idx;
|
++py_idx;
|
||||||
} else if (v[i].y - v[i].x < py_idx - px_idx) {
|
} else if (v[i].y - v[i].x < py_idx - px_idx) {
|
||||||
if (!wasSwapped()) {
|
if (!wasSwapped()) {
|
||||||
ses.addSequence(*x, x_idx, 0, SES_DELETE);
|
ses.addSequence(*x, x_idx + ox, 0, SES_DELETE);
|
||||||
} else {
|
} else {
|
||||||
ses.addSequence(*x, 0, x_idx, SES_ADD);
|
ses.addSequence(*x, 0, x_idx + ox, SES_ADD);
|
||||||
}
|
}
|
||||||
++x;
|
++x;
|
||||||
++x_idx;
|
++x_idx;
|
||||||
@ -605,10 +619,10 @@ namespace dtl {
|
|||||||
} else {
|
} else {
|
||||||
if (!wasSwapped()) {
|
if (!wasSwapped()) {
|
||||||
lcs.addSequence(*x);
|
lcs.addSequence(*x);
|
||||||
ses.addSequence(*x, x_idx, y_idx, SES_COMMON);
|
ses.addSequence(*x, x_idx + ox, y_idx + oy, SES_COMMON);
|
||||||
} else {
|
} else {
|
||||||
lcs.addSequence(*y);
|
lcs.addSequence(*y);
|
||||||
ses.addSequence(*y, y_idx, x_idx, SES_COMMON);
|
ses.addSequence(*y, y_idx + oy, x_idx + ox, SES_COMMON);
|
||||||
}
|
}
|
||||||
++x;
|
++x;
|
||||||
++y;
|
++y;
|
||||||
@ -649,6 +663,8 @@ namespace dtl {
|
|||||||
fp = new long long[M + N + 3];
|
fp = new long long[M + N + 3];
|
||||||
fill(&fp[0], &fp[M + N + 3], -1);
|
fill(&fp[0], &fp[M + N + 3], -1);
|
||||||
fill(path.begin(), path.end(), -1);
|
fill(path.begin(), path.end(), -1);
|
||||||
|
ox = x_idx - 1;
|
||||||
|
oy = y_idx - 1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -119,6 +119,20 @@ namespace dtl {
|
|||||||
stream& out_;
|
stream& out_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* storage class template
|
||||||
|
*/
|
||||||
|
template <typename sesElem, typename storedData >
|
||||||
|
class Storage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Storage(storedData& sd) : storedData_(sd) {}
|
||||||
|
virtual ~Storage() {}
|
||||||
|
virtual void operator() (const sesElem& se) const = 0;
|
||||||
|
protected:
|
||||||
|
storedData& storedData_;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compare class template
|
* compare class template
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,7 @@ namespace dtl {
|
|||||||
/**
|
/**
|
||||||
* version string
|
* version string
|
||||||
*/
|
*/
|
||||||
const string version = "1.19";
|
const string version = "1.20";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* type of edit for SES
|
* type of edit for SES
|
||||||
|
@ -15,28 +15,29 @@ if os.sys.platform != "win32":
|
|||||||
conf = Configure(env);
|
conf = Configure(env);
|
||||||
|
|
||||||
if not conf.CheckCXX():
|
if not conf.CheckCXX():
|
||||||
print "The C++ compiler is not installed!"
|
print("The C++ compiler is not installed!")
|
||||||
Exit(1)
|
Exit(1)
|
||||||
|
|
||||||
libs = ['stdc++']
|
libs = ['stdc++']
|
||||||
for lib in libs:
|
for lib in libs:
|
||||||
if not conf.CheckLib(lib):
|
if not conf.CheckLib(lib):
|
||||||
print "library " + lib + " not installed!"
|
print("library " + lib + " not installed!")
|
||||||
Exit(1)
|
Exit(1)
|
||||||
|
|
||||||
conf.Finish()
|
conf.Finish()
|
||||||
|
|
||||||
targets = { 'strdiff' : ['strdiff.cpp', 'common.cpp'], # diff between two string sequences
|
targets = { 'strdiff' : ['strdiff.cpp', 'common.cpp'], # diff between two string sequences
|
||||||
'intdiff' : ['intdiff.cpp'], # diff between two integer sequences
|
'intdiff' : ['intdiff.cpp'], # diff between two integer sequences
|
||||||
'unidiff' : ['unidiff.cpp', 'common.cpp'], # unified diff between two files
|
'unidiff' : ['unidiff.cpp', 'common.cpp'], # unified diff between two files
|
||||||
'unistrdiff' : ['unistrdiff.cpp', 'common.cpp'], # unified diff between two strings
|
'unistrdiff' : ['unistrdiff.cpp', 'common.cpp'], # unified diff between two strings
|
||||||
'bdiff' : ['bdiff.cpp', 'common.cpp'], # diff between two byte sequences
|
'bdiff' : ['bdiff.cpp', 'common.cpp'], # diff between two byte sequences
|
||||||
'strdiff3' : ['strdiff3.cpp', 'common.cpp'], # three-way string diff program using dtl
|
'strdiff3' : ['strdiff3.cpp', 'common.cpp'], # three-way string diff program using dtl
|
||||||
'intdiff3' : ['intdiff3.cpp'], # three-way integer diff program using dtl
|
'intdiff3' : ['intdiff3.cpp'], # three-way integer diff program using dtl
|
||||||
'patch' : ['patch.cpp', 'common.cpp'], # string patch program using dtl
|
'patch' : ['patch.cpp', 'common.cpp'], # string patch program using dtl
|
||||||
'fpatch' : ['fpatch.cpp', 'common.cpp'], # file patch program using dtl
|
'fpatch' : ['fpatch.cpp', 'common.cpp'], # file patch program using dtl
|
||||||
'st2ses' : ['st2ses.cpp', 'common.cpp'], # convert SES format file to SES instance
|
'st2ses' : ['st2ses.cpp', 'common.cpp'], # convert SES format file to SES instance
|
||||||
'strdiff_cp' : ['strdiff_cp.cpp', 'common.cpp'], # diff between two string sequences with custom printer
|
'strdiff_cp' : ['strdiff_cp.cpp', 'common.cpp'], # diff between two string sequences with custom printer
|
||||||
|
'strdiff_storage' : ['strdiff_storage.cpp', 'common.cpp'], # diff between two string sequences with custom storage
|
||||||
}
|
}
|
||||||
|
|
||||||
[ env.Program(target, targets[target]) for target in targets ]
|
[ env.Program(target, targets[target]) for target in targets ]
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
#ifndef DTL_PRINTERS
|
#ifndef DTL_PRINTERS
|
||||||
#define DTL_PRINTERS
|
#define DTL_PRINTERS
|
||||||
|
|
||||||
|
#include <dtl/dtl.hpp>
|
||||||
|
|
||||||
template <typename sesElem, typename stream = ostream >
|
template <typename sesElem, typename stream = ostream >
|
||||||
class customChangePrinter : public Printer < sesElem, stream >
|
class customChangePrinter : public dtl::Printer < sesElem, stream >
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
customChangePrinter () : Printer < sesElem, stream > () {}
|
customChangePrinter () : dtl::Printer < sesElem, stream > () {}
|
||||||
customChangePrinter (stream& out) : Printer < sesElem, stream > (out) {}
|
customChangePrinter (stream& out) : dtl::Printer < sesElem, stream > (out) {}
|
||||||
~customChangePrinter () {}
|
~customChangePrinter () {}
|
||||||
void operator() (const sesElem& se) const {
|
void operator() (const sesElem& se) const {
|
||||||
switch (se.second.type) {
|
switch (se.second.type) {
|
||||||
case SES_ADD:
|
case dtl::SES_ADD:
|
||||||
this->out_ << "Add: " << se.first << endl;
|
this->out_ << "Add: " << se.first << std::endl;
|
||||||
break;
|
break;
|
||||||
case SES_DELETE:
|
case dtl::SES_DELETE:
|
||||||
this->out_ << "Delete: " << se.first << endl;
|
this->out_ << "Delete: " << se.first << std::endl;
|
||||||
break;
|
break;
|
||||||
case SES_COMMON:
|
case dtl::SES_COMMON:
|
||||||
this->out_ << "Common: " << se.first << endl;
|
this->out_ << "Common: " << se.first << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
examples/storage.hpp
Normal file
27
examples/storage.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef DTL_STORAGE
|
||||||
|
#define DTL_STORAGE
|
||||||
|
|
||||||
|
#include <dtl/dtl.hpp>
|
||||||
|
|
||||||
|
template <typename sesElem, typename storedData >
|
||||||
|
class CustomStorage : public dtl::Storage < sesElem, storedData >
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
CustomStorage(storedData& sd) : dtl::Storage < sesElem, storedData > (sd) {}
|
||||||
|
~CustomStorage() {}
|
||||||
|
void operator() (const sesElem& se) const {
|
||||||
|
switch (se.second.type) {
|
||||||
|
case dtl::SES_ADD:
|
||||||
|
this->storedData_ = this->storedData_ + "Add: " + se.first + "\n";
|
||||||
|
break;
|
||||||
|
case dtl::SES_DELETE:
|
||||||
|
this->storedData_ = this->storedData_ + "Delete: " + se.first + "\n";
|
||||||
|
break;
|
||||||
|
case dtl::SES_COMMON:
|
||||||
|
this->storedData_ = this->storedData_ + "Common: " + se.first + "\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DTL_STORAGE
|
@ -1,19 +1,14 @@
|
|||||||
|
|
||||||
#include <dtl/dtl.hpp>
|
#include <dtl/dtl.hpp>
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "printers.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
using dtl::Diff;
|
using dtl::Diff;
|
||||||
using dtl::SES_ADD;
|
|
||||||
using dtl::SES_DELETE;
|
|
||||||
using dtl::SES_COMMON;
|
|
||||||
using dtl::Printer;
|
|
||||||
|
|
||||||
#include "printers.hpp"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
|
|
||||||
|
38
examples/strdiff_storage.cpp
Normal file
38
examples/strdiff_storage.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <dtl/dtl.hpp>
|
||||||
|
#include "common.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "storage.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using dtl::Diff;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
|
||||||
|
if (isFewArgs(argc)) {
|
||||||
|
cerr << "Too few arguments." << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef char elem;
|
||||||
|
typedef string sequence;
|
||||||
|
|
||||||
|
sequence A(argv[1]);
|
||||||
|
sequence B(argv[2]);
|
||||||
|
|
||||||
|
Diff< elem, sequence > d(A, B);
|
||||||
|
d.compose();
|
||||||
|
|
||||||
|
// Shortest Edit Script
|
||||||
|
cout << "SES" << endl;
|
||||||
|
|
||||||
|
string result;
|
||||||
|
|
||||||
|
d.storeSES < string, CustomStorage > (result);
|
||||||
|
|
||||||
|
cout << result;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -35,6 +35,7 @@ protected :
|
|||||||
cases.push_back(createCase("abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoiewahrgqqabcdef",
|
cases.push_back(createCase("abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoiewahrgqqabcdef",
|
||||||
"3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8
|
"3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8
|
||||||
cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9
|
cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9
|
||||||
|
cases.push_back(createCase("aaaaaaaaaaaaa>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>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||||
ASSERT_EQ(cases[9].B, cases[9].diff.patch(cases[9].A));
|
ASSERT_EQ(cases[9].B, cases[9].diff.patch(cases[9].A));
|
||||||
ASSERT_EQ(cases[9].B, cases[9].diff.uniPatch(cases[9].A));
|
ASSERT_EQ(cases[9].B, cases[9].diff.uniPatch(cases[9].A));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F (Patchtest, patch_test10) {
|
||||||
|
ASSERT_EQ(cases[10].B, cases[10].diff.patch(cases[10].A));
|
||||||
|
ASSERT_EQ(cases[10].B, cases[10].diff.uniPatch(cases[10].A));
|
||||||
|
}
|
||||||
|
@ -11,18 +11,19 @@ def path_chomp(path):
|
|||||||
env = Environment(
|
env = Environment(
|
||||||
CPPFLAGS=['-Wall', '-O2'],
|
CPPFLAGS=['-Wall', '-O2'],
|
||||||
CPPPATH=['..'],
|
CPPPATH=['..'],
|
||||||
|
CXXFLAGS="-std=c++11",
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = Configure(env);
|
conf = Configure(env);
|
||||||
|
|
||||||
if not conf.CheckCXX():
|
if not conf.CheckCXX():
|
||||||
print "c++ compiler is not installed!"
|
print("c++ compiler is not installed!")
|
||||||
Exit(1)
|
Exit(1)
|
||||||
|
|
||||||
libs = ['stdc++', 'pthread', 'gtest']
|
libs = ['stdc++', 'pthread', 'gtest']
|
||||||
for lib in libs:
|
for lib in libs:
|
||||||
if not conf.CheckLib(lib):
|
if not conf.CheckLib(lib):
|
||||||
print "library " + lib + " not installed!"
|
print("library " + lib + " not installed!")
|
||||||
Exit(1)
|
Exit(1)
|
||||||
|
|
||||||
conf.Finish()
|
conf.Finish()
|
||||||
|
Reference in New Issue
Block a user