protected DiffEngine::_compareseq($xoff, $xlim, $yoff, $ylim)
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.
File
- core/lib/Drupal/Component/Diff/Engine/DiffEngine.php, line 283
Class
- DiffEngine
- Class used internally by Diff to actually compute the diffs.
Namespace
Drupal\Component\Diff\Engine
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | protected 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 ; } } } |
Please login to continue.