diff --git a/include/dtl/Diff.hpp b/include/dtl/Diff.hpp index 222d9adb..57067f9f 100644 --- a/include/dtl/Diff.hpp +++ b/include/dtl/Diff.hpp @@ -67,6 +67,8 @@ namespace dtl { bool editDistanceOnly; uniHunkVec uniHunks; comparator cmp; + long long ox; + long long oy; public : Diff () {} @@ -162,7 +164,7 @@ namespace dtl { return trivial; } - void enableTrivial () const { + void enableTrivial () { this->trivial = true; } @@ -260,7 +262,8 @@ namespace dtl { if (isHuge()) { pathCordinates.reserve(MAX_CORDINATES_SIZE); } - + ox = 0; + oy = 0; long long p = -1; fp = new long long[M + N + 3]; fill(&fp[0], &fp[M + N + 3], -1); @@ -340,6 +343,15 @@ namespace dtl { sesElemVec ses_v = ses.getSequence (); 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 @@ -586,18 +598,18 @@ namespace dtl { while(px_idx < v[i].x || py_idx < v[i].y) { if (v[i].y - v[i].x > py_idx - px_idx) { if (!wasSwapped()) { - ses.addSequence(*y, 0, y_idx, SES_ADD); + ses.addSequence(*y, 0, y_idx + oy, SES_ADD); } else { - ses.addSequence(*y, y_idx, 0, SES_DELETE); + ses.addSequence(*y, y_idx + oy, 0, SES_DELETE); } ++y; ++y_idx; ++py_idx; } else if (v[i].y - v[i].x < py_idx - px_idx) { if (!wasSwapped()) { - ses.addSequence(*x, x_idx, 0, SES_DELETE); + ses.addSequence(*x, x_idx + ox, 0, SES_DELETE); } else { - ses.addSequence(*x, 0, x_idx, SES_ADD); + ses.addSequence(*x, 0, x_idx + ox, SES_ADD); } ++x; ++x_idx; @@ -605,10 +617,10 @@ namespace dtl { } else { if (!wasSwapped()) { lcs.addSequence(*x); - ses.addSequence(*x, x_idx, y_idx, SES_COMMON); + ses.addSequence(*x, x_idx + ox, y_idx + oy, SES_COMMON); } else { lcs.addSequence(*y); - ses.addSequence(*y, y_idx, x_idx, SES_COMMON); + ses.addSequence(*y, y_idx + oy, x_idx + ox, SES_COMMON); } ++x; ++y; @@ -649,6 +661,8 @@ namespace dtl { fp = new long long[M + N + 3]; fill(&fp[0], &fp[M + N + 3], -1); fill(path.begin(), path.end(), -1); + ox = x_idx - 1; + oy = y_idx - 1; return false; } return true; diff --git a/include/dtl/functors.hpp b/include/dtl/functors.hpp index a4da5e5f..86d8709d 100644 --- a/include/dtl/functors.hpp +++ b/include/dtl/functors.hpp @@ -118,6 +118,20 @@ namespace dtl { private : stream& out_; }; + + /** + * storage class template + */ + template + class Storage + { + public: + Storage(storedData& sd) : storedData_(sd) {} + virtual ~Storage() {} + virtual void operator() (const sesElem& se) const = 0; + protected: + storedData& storedData_; + }; /** * compare class template diff --git a/include/dtl/variables.hpp b/include/dtl/variables.hpp index cbf5a54e..4f53a887 100644 --- a/include/dtl/variables.hpp +++ b/include/dtl/variables.hpp @@ -63,7 +63,7 @@ namespace dtl { /** * version string */ - const string version = "1.19"; + const string version = "1.21"; /** * type of edit for SES