function _DiffEngine::_compareseq in Diff 5
Same name and namespace in other branches
- 5.2 DiffEngine.php \_DiffEngine::_compareseq()
- 6.2 DiffEngine.php \_DiffEngine::_compareseq()
- 6 DiffEngine.php \_DiffEngine::_compareseq()
- 7.3 DiffEngine.php \_DiffEngine::_compareseq()
- 7.2 DiffEngine.php \_DiffEngine::_compareseq()
1 call to _DiffEngine::_compareseq()
File
- ./
DiffEngine.php, line 366
Class
- _DiffEngine
- Class used internally by Diff to actually compute the diffs.
Code
function _compareseq($xoff, $xlim, $yoff, $ylim) {
// Slide down the bottom initial diagonal.
while ($xoff < $xlim && $yoff < $ylim && $this->xv[$xoff] == $this->yv[$yoff]) {
++$xoff;
++$yoff;
}
// Slide up the top initial diagonal.
while ($xlim > $xoff && $ylim > $yoff && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
--$xlim;
--$ylim;
}
if ($xoff == $xlim || $yoff == $ylim) {
$lcs = 0;
}
else {
// This is ad hoc but seems to work well.
//$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
//$nchunks = max(2,min(8,(int)$nchunks));
$nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1;
list($lcs, $seps) = $this
->_diag($xoff, $xlim, $yoff, $ylim, $nchunks);
}
if ($lcs == 0) {
// X and Y sequences have no common subsequence:
// mark all changed.
while ($yoff < $ylim) {
$this->ychanged[$this->yind[$yoff++]] = 1;
}
while ($xoff < $xlim) {
$this->xchanged[$this->xind[$xoff++]] = 1;
}
}
else {
// Use the partitions to split this problem into subproblems.
reset($seps);
$pt1 = $seps[0];
while ($pt2 = next($seps)) {
$this
->_compareseq($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
$pt1 = $pt2;
}
}
}