NativeEngine
in package
implements
DiffEngineInterface
Class used internally by Horde_Text_Diff to actually compute the diffs.
This class is implemented using native PHP code.
The algorithm used here is mostly lifted from the perl module Algorithm::Diff (version 1.06) by Ned Konz, which is available at: http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
More ideas are taken from: http://www.ics.uci.edu/~eppstein/161/960229.html
Some ideas (and a bit of code) are taken from analyze.c, of GNU diffutils-2.7, which can be found at: ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
Some ideas (subdivision by NCHUNKS > 2, and some optimizations) are from Geoffrey T. Dairiki dairiki@dairiki.org. The original PHP version of this code was written by him, and is used/adapted with his permission.
Copyright 2004-2017 Horde LLC (http://www.horde.org/)
See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Tags
Interfaces, Classes, Traits and Enums
- DiffEngineInterface
- Interface for Diff Engines
Table of Contents
- $in_seq : array<string|int, mixed>|null
- $lcs : int|null
- $seq : array<string|int, mixed>|null
- $xchanged : array<string|int, mixed>
- $xind : array<string|int, mixed>
- $xv : array<string|int, mixed>
- $ychanged : array<string|int, mixed>
- $yind : array<string|int, mixed>
- $yv : array<string|int, mixed>
- $fromLines : array<string|int, mixed>
- $toLines : array<string|int, mixed>
- __construct() : mixed
- Constructor.
- diff() : OperationList
- Returns the array of differences.
- _compareseq() : mixed
- Finds LCS of two sequences.
- _diag() : mixed
- Divides the Largest Common Subsequence (LCS) of the sequences (XOFF, XLIM) and (YOFF, YLIM) into NCHUNKS approximately equally sized segments.
- _lcsPos() : mixed
- _shiftBoundaries() : mixed
- Adjusts inserts/deletes of identical lines to join changes as much as possible.
Properties
$in_seq
protected
array<string|int, mixed>|null
$in_seq
$lcs
protected
int|null
$lcs
$seq
protected
array<string|int, mixed>|null
$seq
$xchanged
protected
array<string|int, mixed>
$xchanged
= []
$xind
protected
array<string|int, mixed>
$xind
= []
$xv
protected
array<string|int, mixed>
$xv
= []
$ychanged
protected
array<string|int, mixed>
$ychanged
= []
$yind
protected
array<string|int, mixed>
$yind
= []
$yv
protected
array<string|int, mixed>
$yv
= []
$fromLines
private
array<string|int, mixed>
$fromLines
$toLines
private
array<string|int, mixed>
$toLines
Methods
__construct()
Constructor.
public
__construct(array<string|int, string> $fromLines, array<string|int, string> $toLines) : mixed
Parameters
- $fromLines : array<string|int, string>
-
lines of text from old file
- $toLines : array<string|int, string>
-
lines of text from new file
Return values
mixed —diff()
Returns the array of differences.
public
diff() : OperationList
Return values
OperationList —all changes made
_compareseq()
Finds LCS of two sequences.
protected
_compareseq(mixed $xoff, mixed $xlim, mixed $yoff, mixed $ylim) : mixed
The results are recorded in the vectors $this->{x,y}changed[], by storing a 1 in the element for each line that is an insertion or deletion (ie. is not in the LCS).
The subsequence of file 0 is (XOFF, XLIM) and likewise for file 1.
Note that XLIM, YLIM are exclusive bounds. All line numbers are origin-0 and discarded lines are not counted.
Parameters
- $xoff : mixed
- $xlim : mixed
- $yoff : mixed
- $ylim : mixed
Return values
mixed —_diag()
Divides the Largest Common Subsequence (LCS) of the sequences (XOFF, XLIM) and (YOFF, YLIM) into NCHUNKS approximately equally sized segments.
protected
_diag(mixed $xoff, mixed $xlim, mixed $yoff, mixed $ylim, mixed $nchunks) : mixed
Returns (LCS, PTS). LCS is the length of the LCS. PTS is an array of NCHUNKS+1 (X, Y) indexes giving the diving points between sub sequences. The first sub-sequence is contained in (X0, X1), (Y0, Y1), the second in (X1, X2), (Y1, Y2) and so on. Note that (X0, Y0) == (XOFF, YOFF) and (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
This public function assumes that the first lines of the specified portions of the two files do not match, and likewise that the last lines do not match. The caller must trim matching lines from the beginning and end of the portions it is going to specify.
Parameters
- $xoff : mixed
- $xlim : mixed
- $yoff : mixed
- $ylim : mixed
- $nchunks : mixed
Return values
mixed —_lcsPos()
protected
_lcsPos(mixed $ypos) : mixed
Parameters
- $ypos : mixed
Return values
mixed —_shiftBoundaries()
Adjusts inserts/deletes of identical lines to join changes as much as possible.
protected
_shiftBoundaries(mixed $lines, mixed &$changed, mixed $other_changed) : mixed
We do something when a run of changed lines include a line at one end and has an excluded, identical line at the other. We are free to choose which identical line is included. `compareseq' usually chooses the one at the beginning, but usually it is cleaner to consider the following identical line to be the "change".
This is extracted verbatim from analyze.c (GNU diffutils-2.7).
Parameters
- $lines : mixed
- $changed : mixed
- $other_changed : mixed