Convert a list of common substring indices into a diff.
Convert a list of common substring indices into a diff.
a diff of a
and b
based on initialCommonSubstringIndices
.
If initialCommonSubstringIndices
contains no empty runs, the result
will not contain an Insert(_)
followed by a Delete(_)
, i.e. in
difference regions it puts characters from a
before those from b
.
If initialCommonSubstringIndices
does not correspond to a common
subsequence of a
and b
, hilarity may ensue.
Find a (dist, (xlo, xhi, ylo))
such that dist
is the LCS edit
distance between a.substring(i, n)
and b.substring(j, m)
, and such
that a(i) == b(i - xlo + ylo)
for all i
in (xlo until xhi)
.
Find a (dist, (xlo, xhi, ylo))
such that dist
is the LCS edit
distance between a.substring(i, n)
and b.substring(j, m)
, and such
that a(i) == b(i - xlo + ylo)
for all i
in (xlo until xhi)
.
If 0 <= i <= n <= a.size
and 0 <= j <= m <= b.size
don't both hold,
hilarity may ensue.
the observed/old sequence
the expected/new sequence
an index into vForward
and vReverse
such that
((zero - (a.size + b.size)) to (zero + (a.size + b.size)))
is a range
of valid (in-bounds) indices into vForward
and vReverse
an array, some entries of which will be overwritten
an array, some entries of which will be overwritten
the start (inclusive) of the substring of a
to search in
the end (exclusive) of the substring of a
to search in
the start (inclusive) of the substring of b
to search in
the end (exclusive) of the substring of b
to search in
see description
a list of substring indices (xlo, xhi, ylo)
which together
make up a (the) longest common subsequence between a
and b
.
The substring index triples are such that
lcsRuns(a, b).forall { case (xlo, xhi, ylo) => (xlo until xhi).forall(i => a(i) == b(i - xlo + ylo)) }
furthermore lcsRuns(a, b).flatMap(t => Seq(t._1, t._2))
is sorted, and
so is lcsRuns(a, b).map(_._3)
See "An O(ND)
Difference Algorithm and Its Variations" by Eugene
W.
See "An O(ND)
Difference Algorithm and Its Variations" by Eugene
W. Myers at http://xmailserver.org/diff2.pdf; this implements the
linear space recursive bidirectional search.
a char-by-char diff describing how to turn a
into b
.
Specifically,
a == longestCommonSubsequenceEdits(a, b).collect { case Common(c) => c case Delete(c) => c }.mkString
and
b == longestCommonSubsequenceEdits(a, b).collect { case Common(c) => c case Insert(c) => c }.mkString
and
// this is the longest common subsequence of a and b: longestCommonSubsequenceEdits(a, b).collect { case Common(c) => c }
Use findMiddle to find a common substring with (approximately) half the differences before it and half the differences after it, such that the common substring is part of the longest common subsequence.
Use findMiddle to find a common substring with (approximately) half the differences before it and half the differences after it, such that the common substring is part of the longest common subsequence. This substring may be empty. Then recursively solve the two subproblems on each side of the substring.
The parameters are the same as findMiddle with one exception.
return value accumulator, initially Nil
a list of common substring indices making up the longest common subsequence.
(Since version ) see corresponding Javadoc for more information.