47 template <
typename elem,
typename sequence = vector< elem >,
typename comparator = Compare< elem > >
74 const sequence& b) : A(a),
B(b),
ses(false) {
80 bool deletesFirst) : A(a),
B(b),
ses(deletesFirst) {
86 const comparator& comp) : A(a),
B(b),
ses(false),
cmp(comp) {
93 const comparator& comp) : A(a),
B(b),
ses(deleteFirst),
cmp(comp) {
108 return lcs.getSequence();
137 this->trivial =
true;
141 this->trivial =
false;
145 this->editDistanceOnly =
true;
166 this->trivial =
true;
170 this->trivial =
false;
174 this->editDistanceOnly =
true;
181 elemList seqLst(seq.begin(), seq.end());
183 sesElemVec_iter vsesIt;
184 elemList_iter lstIt = seqLst.begin();
185 long long inc_dec_total = 0;
191 it->a += inc_dec_total;
192 inc_dec_total += it->inc_dec_count;
193 for (
long long i=0;i<it->a - gap;++i) {
196 gap = it->a + it->b + it->inc_dec_count;
197 vsesIt = shunk.begin();
198 while (vsesIt!=shunk.end()) {
199 switch (vsesIt->second.type) {
201 seqLst.insert(lstIt, vsesIt->first);
204 if (lstIt != seqLst.end()) {
205 lstIt = seqLst.erase(lstIt);
209 if (lstIt != seqLst.end()) {
222 sequence patchedSeq(seqLst.begin(), seqLst.end());
229 sequence
patch (
const sequence& seq)
const {
230 sesElemVec sesSeq =
ses.getSequence();
231 elemList seqLst(seq.begin(), seq.end());
232 elemList_iter lstIt = seqLst.begin();
233 for (sesElemVec_iter sesIt=sesSeq.begin();sesIt!=sesSeq.end();++sesIt) {
234 switch (sesIt->second.type) {
236 seqLst.insert(lstIt, sesIt->first);
239 lstIt = seqLst.erase(lstIt);
249 sequence patchedSeq(seqLst.begin(), seqLst.end());
265 fp =
new long long[
M +
N + 3];
266 fill(&
fp[0], &
fp[
M +
N + 3], -1);
272 for (
long long k=-p;k<=static_cast<long long>(
delta)-1;++k) {
275 for (
long long k=
static_cast<long long>(
delta)+p;k>=
static_cast<long long>(
delta)+1;--k) {
295 epc.push_back(cordinate);
312 template <
typename stream >
314 sesElemVec ses_v =
ses.getSequence();
319 printSES< ostream >(out);
325 template <
typename stream >
332 printSES< ostream >(s, out);
338 template <
typename stream,
template <
typename SEET,
typename STRT >
class PT >
340 sesElemVec ses_v =
ses.getSequence ();
341 for_each (ses_v.begin (), ses_v.end(), PT < sesElem, stream > (out));
347 template <
typename stream >
353 printUnifiedFormat< ostream >(out);
359 template <
typename stream >
365 printUnifiedFormat< ostream >(hunks, out);
372 sesElemVec common[2];
374 sesElemVec ses_v =
ses.getSequence();
376 long long length = distance(ses_v.begin(), ses_v.end());
377 long long middle = 0;
378 bool isMiddle, isAfter;
380 long long a, b, c, d;
381 long long inc_dec_count = 0;
386 isMiddle = isAfter =
false;
389 for (sesElemVec_iter it=ses_v.begin();it!=ses_v.end();++it, ++l_cnt) {
391 switch (einfo.
type) {
396 if (!isMiddle) isMiddle =
true;
398 if (l_cnt >= length) {
407 deletes.push_back(*it);
408 if (!isMiddle) isMiddle =
true;
410 if (l_cnt >= length) {
418 if (common[1].empty() && adds.empty() && deletes.empty() && change.empty()) {
420 if (a == 0 && c == 0) {
429 common[0].push_back(*it);
431 rotate(common[0].begin(), common[0].begin() + 1, common[0].end());
432 common[0].pop_back();
433 common[0].push_back(*it);
438 if (isMiddle && !isAfter) {
442 change.push_back(*it);
455 if (isAfter && !change.empty()) {
456 sesElemVec_iter cit = it;
469 long long c0size =
static_cast<long long>(common[0].size());
470 rotate(common[0].begin(),
474 common[0].pop_back();
486 hunk.
common[0] = common[0];
488 hunk.
common[1] = common[1];
498 a = b = c = d = middle = inc_dec_count = 0;
506 template <
typename stream>
511 long long x_idx, y_idx;
513 while (getline(st, line)) {
514 elem mark(line.begin(), line.begin() + 1);
515 elem e(line.begin() + 1, line.end());
536 M = distance(A.begin(), A.end());
537 N = distance(
B.begin(),
B.end());
557 long long snake(
const long long& k,
const long long& above,
const long long& below) {
559 long long y =
max(above, below);
561 while ((
size_t)x <
M && (
size_t)y <
N && (
swapped ?
cmp.impl(
B[(
size_t)y], A[(
size_t)x]) :
cmp.impl(A[(
size_t)x],
B[(
size_t)y]))) {
568 p.
x = x;p.
y = y;p.
k = r;
578 sequence_const_iter x(A.begin());
579 sequence_const_iter y(
B.begin());
580 long long x_idx, y_idx;
581 long long px_idx, py_idx;
582 bool complete =
false;
585 for (
size_t i=v.size()-1;!complete;--i) {
586 while(px_idx < v[i].x || py_idx < v[i].y) {
587 if (v[i].y - v[i].x > py_idx - px_idx) {
596 }
else if (v[i].y - v[i].x < py_idx - px_idx) {
621 if (i == 0) complete =
true;
624 if (x_idx >
static_cast<long long>(
M) && y_idx >
static_cast<long long>(
N)) {
640 sequence A_(A.begin() + (
size_t)x_idx - 1, A.end());
641 sequence B_(
B.begin() + (
size_t)y_idx - 1,
B.end());
644 M = distance(A.begin(), A.end());
645 N = distance(
B.begin(),
B.end());
649 fp =
new long long[
M +
N + 3];
650 fill(&
fp[0], &
fp[
M +
N + 3], -1);
662 ses.addSequence(*it, idx, 0, et);
667 ses.addSequence(*it, idx, 0, et);
674 void inline joinSesVec (sesElemVec& s1, sesElemVec& s2)
const {
676 for (sesElemVec_iter vit=s2.begin();vit!=s2.end();++vit) {
void enableTrivial() const
static Ses< elem > composeSesFromStream(stream &st)
void printUnifiedFormat(stream &out) const
dtl_typedefs(elem, sequence) sequence A
Diff(const sequence &a, const sequence &b, const comparator &comp)
void printSES(ostream &out=cout) const
Diff(const sequence &a, const sequence &b, bool deletesFirst)
static void printUnifiedFormat(const uniHunkVec &hunks, stream &out)
void editDistanceOnlyEnabled()
void recordOddSequence(long long idx, long long length, sequence_const_iter it, const edit_t et)
void composeUnifiedHunks()
sequence patch(const sequence &seq) const
long long getEditDistance() const
static void printSES(const Ses< elem > &s, stream &out)
elemVec getLcsVec() const
Diff(const sequence &a, const sequence &b, bool deleteFirst, const comparator &comp)
sequence uniPatch(const sequence &seq)
editPathCordinates pathCordinates
void printSES(stream &out) const
void printSES(stream &out) const
Lcs< elem > getLcs() const
Diff(const sequence &a, const sequence &b)
void printUnifiedFormat(ostream &out=cout) const
bool recordSequence(const editPathCordinates &v)
uniHunkVec getUniHunks() const
bool trivialEnabled() const
Ses< elem > getSes() const
long long snake(const long long &k, const long long &above, const long long &below)
static void printUnifiedFormat(const uniHunkVec &hunks, ostream &out=cout)
void joinSesVec(sesElemVec &s1, sesElemVec &s2) const
static void printSES(const Ses< elem > &s, ostream &out=cout)
void onOnlyEditDistance()
sesElemVec getSequence() const
void addSequence(elem e, long long beforeIdx, long long afterIdx, const edit_t type)
const long long DTL_CONTEXT_SIZE
const unsigned long long MAX_CORDINATES_SIZE
const long long DTL_SEPARATE_SIZE
vector< long long > editPath
vector< P > editPathCordinates
vector< sesElem > common[2]