[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/diff/ -> DairikiDiff.php (summary)

A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3) Copyright © 2000, 2001 Geoffrey T. Dairiki <[email protected]> You may copy this code freely under the conditions of the GPL.

File Size: 1076 lines (26 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 9 classes

DiffOpCopy:: (2 methods):
  __construct()
  reverse()

DiffOpDelete:: (2 methods):
  __construct()
  reverse()

DiffOpAdd:: (2 methods):
  __construct()
  reverse()

DiffOpChange:: (2 methods):
  __construct()
  reverse()

DiffEngine:: (7 methods):
  diff()
  diffLocal()
  lineHash()
  diag()
  lcsPos()
  compareSeq()
  shiftBoundaries()

Diff:: (7 methods):
  __construct()
  getEdits()
  reverse()
  isEmpty()
  lcs()
  orig()
  closing()

MappedDiff:: (1 method):
  __construct()

HWLDFWordAccumulator:: (4 methods):
  flushGroup()
  flushLine()
  addWords()
  getLines()

WordLevelDiff:: (4 methods):
  __construct()
  split()
  orig()
  closing()

Defines 4 functions

  getType()
  getOrig()
  getClosing()
  norig()
  nclosing()

Class: DiffOpCopy  - X-Ref


__construct( $orig, $closing = false )   X-Ref
No description

reverse()   X-Ref

return: DiffOpCopy

Class: DiffOpDelete  - X-Ref


__construct( $lines )   X-Ref
No description

reverse()   X-Ref

return: DiffOpAdd

Class: DiffOpAdd  - X-Ref


__construct( $lines )   X-Ref
No description

reverse()   X-Ref

return: DiffOpDelete

Class: DiffOpChange  - X-Ref


__construct( $orig, $closing )   X-Ref
No description

reverse()   X-Ref

return: DiffOpChange

Class: DiffEngine  - X-Ref

Class used internally by Diff to actually compute the diffs.

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 are (and a bit of code) are from from analyze.c, from GNU
diffutils-2.7, which can be found at:
ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz

closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
are my own.

Line length limits for robustness added by Tim Starling, 2005-08-31
Alternative implementation added by Guy Van den Broeck, 2008-07-30

diff( $from_lines, $to_lines )   X-Ref

param: string[] $from_lines
param: string[] $to_lines
return: DiffOp[]

diffLocal( $from_lines, $to_lines )   X-Ref

param: string[] $from_lines
param: string[] $to_lines

lineHash( $line )   X-Ref
Returns the whole line if it's small enough, or the MD5 hash otherwise

param: string $line
return: string

diag( $xoff, $xlim, $yoff, $ylim, $nchunks )   X-Ref
Divide the Largest Common Subsequence (LCS) of the sequences
[XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
sized segments.

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 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.

param: int $xoff
param: int $xlim
param: int $yoff
param: int $ylim
param: int $nchunks
return: array List of two elements, integer and array[].

lcsPos( $ypos )   X-Ref

param: int $ypos
return: int

compareSeq( $xoff, $xlim, $yoff, $ylim )   X-Ref
Find LCS of two sequences.

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.

param: int $xoff
param: int $xlim
param: int $yoff
param: int $ylim

shiftBoundaries( $lines, &$changed, $other_changed )   X-Ref
Adjust inserts/deletes of identical lines to join changes
as much as possible.

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).

Class: Diff  - X-Ref

Class representing a 'diff' between two sequences of strings.

__construct( $from_lines, $to_lines )   X-Ref
Constructor.
Computes diff between sequences of strings.

param: string[] $from_lines An array of strings.
param: string[] $to_lines An array of strings.

getEdits()   X-Ref

return: DiffOp[]

reverse()   X-Ref
Compute reversed Diff.

SYNOPSIS:

$diff = new Diff($lines1, $lines2);
$rev = $diff->reverse();

return: Object A Diff object representing the inverse of the

isEmpty()   X-Ref
Check for empty diff.

return: bool True if two sequences were identical.

lcs()   X-Ref
Compute the length of the Longest Common Subsequence (LCS).

This is mostly for diagnostic purposed.

return: int The length of the LCS.

orig()   X-Ref
Get the original set of lines.

This reconstructs the $from_lines parameter passed to the
constructor.

return: string[] The original sequence of strings.

closing()   X-Ref
Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the
constructor.

return: string[] The sequence of strings.

Class: MappedDiff  - X-Ref


__construct( $from_lines, $to_lines,$mapped_from_lines, $mapped_to_lines )   X-Ref
Constructor.

Computes diff between sequences of strings.

This can be used to compute things like
case-insensitve diffs, or diffs which ignore
changes in white-space.

param: string[] $from_lines An array of strings.
param: string[] $to_lines An array of strings.
param: string[] $mapped_from_lines This array should
param: string[] $mapped_to_lines This array should

Class: HWLDFWordAccumulator  - X-Ref


flushGroup( $new_tag )   X-Ref

param: string $new_tag

flushLine( $new_tag )   X-Ref

param: string $new_tag

addWords( $words, $tag = '' )   X-Ref

param: string[] $words
param: string $tag

getLines()   X-Ref

return: string[]

Class: WordLevelDiff  - X-Ref


__construct( $orig_lines, $closing_lines )   X-Ref

param: string[] $orig_lines
param: string[] $closing_lines

split( $lines )   X-Ref

param: string[] $lines
return: array[]

orig()   X-Ref

return: string[]

closing()   X-Ref

return: string[]

Functions
Functions that are not part of a class:

getType()   X-Ref

return: string

getOrig()   X-Ref

return: string[]

getClosing( $i = null )   X-Ref

param: int $i
return: string|null

norig()   X-Ref

return: int

nclosing()   X-Ref

return: int



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1