MediaWiki  master
DiffEngine.php
Go to the documentation of this file.
1 <?php
26 
27 // FIXME: Don't use assert() in this file
28 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.assert
29 
47 class DiffEngine {
48 
49  // Input variables
51  private $from;
53  private $to;
55  private $m;
57  private $n;
58 
60  private $tooLong;
62  private $powLimit;
63 
65  protected $bailoutComplexity = 0;
66 
67  // State variables
69  private $maxDifferences;
72 
73  // Output variables
75  public $length;
77  public $removed;
79  public $added;
82 
87  public function __construct( $tooLong = 2000000, $powLimit = 1.45 ) {
88  $this->tooLong = $tooLong;
89  $this->powLimit = $powLimit;
90  }
91 
101  public function diff( $from_lines, $to_lines ) {
102  // Diff and store locally
103  $this->diffInternal( $from_lines, $to_lines );
104 
105  // Merge edits when possible
106  $this->shiftBoundaries( $from_lines, $this->removed, $this->added );
107  $this->shiftBoundaries( $to_lines, $this->added, $this->removed );
108 
109  // Compute the edit operations.
110  $n_from = count( $from_lines );
111  $n_to = count( $to_lines );
112 
113  $edits = [];
114  $xi = $yi = 0;
115  while ( $xi < $n_from || $yi < $n_to ) {
116  assert( $yi < $n_to || $this->removed[$xi] );
117  assert( $xi < $n_from || $this->added[$yi] );
118 
119  // Skip matching "snake".
120  $copy = [];
121  while ( $xi < $n_from && $yi < $n_to
122  && !$this->removed[$xi] && !$this->added[$yi]
123  ) {
124  $copy[] = $from_lines[$xi++];
125  ++$yi;
126  }
127  if ( $copy ) {
128  $edits[] = new DiffOpCopy( $copy );
129  }
130 
131  // Find deletes & adds.
132  $delete = [];
133  while ( $xi < $n_from && $this->removed[$xi] ) {
134  $delete[] = $from_lines[$xi++];
135  }
136 
137  $add = [];
138  while ( $yi < $n_to && $this->added[$yi] ) {
139  $add[] = $to_lines[$yi++];
140  }
141 
142  if ( $delete && $add ) {
143  $edits[] = new DiffOpChange( $delete, $add );
144  } elseif ( $delete ) {
145  $edits[] = new DiffOpDelete( $delete );
146  } elseif ( $add ) {
147  $edits[] = new DiffOpAdd( $add );
148  }
149  }
150 
151  return $edits;
152  }
153 
158  public function setBailoutComplexity( $value ) {
159  $this->bailoutComplexity = $value;
160  }
161 
179  private function shiftBoundaries( array $lines, array &$changed, array $other_changed ) {
180  $i = 0;
181  $j = 0;
182 
183  assert( count( $lines ) == count( $changed ) );
184  $len = count( $lines );
185  $other_len = count( $other_changed );
186 
187  while ( 1 ) {
188  /*
189  * Scan forwards to find beginning of another run of changes.
190  * Also keep track of the corresponding point in the other file.
191  *
192  * Throughout this code, $i and $j are adjusted together so that
193  * the first $i elements of $changed and the first $j elements
194  * of $other_changed both contain the same number of zeros
195  * (unchanged lines).
196  * Furthermore, $j is always kept so that $j == $other_len or
197  * $other_changed[$j] == false.
198  */
199  while ( $j < $other_len && $other_changed[$j] ) {
200  $j++;
201  }
202 
203  while ( $i < $len && !$changed[$i] ) {
204  assert( $j < $other_len && !$other_changed[$j] );
205  $i++;
206  $j++;
207  while ( $j < $other_len && $other_changed[$j] ) {
208  $j++;
209  }
210  }
211 
212  if ( $i == $len ) {
213  break;
214  }
215 
216  $start = $i;
217 
218  // Find the end of this run of changes.
219  while ( ++$i < $len && $changed[$i] ) {
220  continue;
221  }
222 
223  do {
224  /*
225  * Record the length of this run of changes, so that
226  * we can later determine whether the run has grown.
227  */
228  $runlength = $i - $start;
229 
230  /*
231  * Move the changed region back, so long as the
232  * previous unchanged line matches the last changed one.
233  * This merges with previous changed regions.
234  */
235  while ( $start > 0 && $lines[$start - 1] == $lines[$i - 1] ) {
236  $changed[--$start] = 1;
237  $changed[--$i] = false;
238  // @phan-suppress-next-line PhanPluginLoopVariableReuse
239  while ( $start > 0 && $changed[$start - 1] ) {
240  $start--;
241  }
242  assert( $j > 0 );
243  while ( $other_changed[--$j] ) {
244  continue;
245  }
246  assert( $j >= 0 && !$other_changed[$j] );
247  }
248 
249  /*
250  * Set CORRESPONDING to the end of the changed run, at the last
251  * point where it corresponds to a changed run in the other file.
252  * CORRESPONDING == LEN means no such point has been found.
253  */
254  $corresponding = $j < $other_len ? $i : $len;
255 
256  /*
257  * Move the changed region forward, so long as the
258  * first changed line matches the following unchanged one.
259  * This merges with following changed regions.
260  * Do this second, so that if there are no merges,
261  * the changed region is moved forward as far as possible.
262  */
263  while ( $i < $len && $lines[$start] == $lines[$i] ) {
264  $changed[$start++] = false;
265  $changed[$i++] = 1;
266  while ( $i < $len && $changed[$i] ) {
267  $i++;
268  }
269 
270  assert( $j < $other_len && !$other_changed[$j] );
271  $j++;
272  if ( $j < $other_len && $other_changed[$j] ) {
273  $corresponding = $i;
274  while ( $j < $other_len && $other_changed[$j] ) {
275  $j++;
276  }
277  }
278  }
279  } while ( $runlength != $i - $start );
280 
281  /*
282  * If possible, move the fully-merged run of changes
283  * back to a corresponding run in the other file.
284  */
285  while ( $corresponding < $i ) {
286  $changed[--$start] = 1;
287  $changed[--$i] = 0;
288  assert( $j > 0 );
289  while ( $other_changed[--$j] ) {
290  continue;
291  }
292  assert( $j >= 0 && !$other_changed[$j] );
293  }
294  }
295  }
296 
302  protected function diffInternal( array $from, array $to ) {
303  // remember initial lengths
304  $m = count( $from );
305  $n = count( $to );
306 
307  $this->heuristicUsed = false;
308 
309  // output
310  $removed = $m > 0 ? array_fill( 0, $m, true ) : [];
311  $added = $n > 0 ? array_fill( 0, $n, true ) : [];
312 
313  // reduce the complexity for the next step (intentionally done twice)
314  // remove common tokens at the start
315  $i = 0;
316  while ( $i < $m && $i < $n && $from[$i] === $to[$i] ) {
317  $removed[$i] = $added[$i] = false;
318  unset( $from[$i], $to[$i] );
319  ++$i;
320  }
321 
322  // remove common tokens at the end
323  $j = 1;
324  while ( $i + $j <= $m && $i + $j <= $n && $from[$m - $j] === $to[$n - $j] ) {
325  $removed[$m - $j] = $added[$n - $j] = false;
326  unset( $from[$m - $j], $to[$n - $j] );
327  ++$j;
328  }
329 
330  $this->from = $newFromIndex = $this->to = $newToIndex = [];
331 
332  // remove tokens not in both sequences
333  $shared = [];
334  foreach ( $from as $key ) {
335  $shared[$key] = false;
336  }
337 
338  foreach ( $to as $index => &$el ) {
339  if ( array_key_exists( $el, $shared ) ) {
340  // keep it
341  $this->to[] = $el;
342  $shared[$el] = true;
343  $newToIndex[] = $index;
344  }
345  }
346  foreach ( $from as $index => &$el ) {
347  if ( $shared[$el] ) {
348  // keep it
349  $this->from[] = $el;
350  $newFromIndex[] = $index;
351  }
352  }
353 
354  unset( $shared, $from, $to );
355 
356  $this->m = count( $this->from );
357  $this->n = count( $this->to );
358 
359  if ( $this->bailoutComplexity > 0 && $this->m * $this->n > $this->bailoutComplexity ) {
360  throw new ComplexityException();
361  }
362 
363  $this->removed = $this->m > 0 ? array_fill( 0, $this->m, true ) : [];
364  $this->added = $this->n > 0 ? array_fill( 0, $this->n, true ) : [];
365 
366  if ( $this->m == 0 || $this->n == 0 ) {
367  $this->length = 0;
368  } else {
369  $this->maxDifferences = ceil( ( $this->m + $this->n ) / 2.0 );
370  if ( $this->m * $this->n > $this->tooLong ) {
371  // limit complexity to D^POW_LIMIT for long sequences
372  $this->maxDifferences = floor( $this->maxDifferences ** ( $this->powLimit - 1.0 ) );
373  wfDebug( "Limiting max number of differences to $this->maxDifferences" );
374  }
375 
376  /*
377  * The common prefixes and suffixes are always part of some LCS, include
378  * them now to reduce our search space
379  */
380  $max = min( $this->m, $this->n );
381  for ( $forwardBound = 0; $forwardBound < $max
382  && $this->from[$forwardBound] === $this->to[$forwardBound];
383  ++$forwardBound
384  ) {
385  $this->removed[$forwardBound] = $this->added[$forwardBound] = false;
386  }
387 
388  $backBoundL1 = $this->m - 1;
389  $backBoundL2 = $this->n - 1;
390 
391  while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
392  && $this->from[$backBoundL1] === $this->to[$backBoundL2]
393  ) {
394  $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
395  }
396 
397  $temp = array_fill( 0, $this->m + $this->n + 1, 0 );
398  $V = [ $temp, $temp ];
399  $snake = [ 0, 0, 0 ];
400 
401  $this->length = $forwardBound + $this->m - $backBoundL1 - 1
402  + $this->lcs_rec(
403  $forwardBound,
404  $backBoundL1,
405  $forwardBound,
406  $backBoundL2,
407  $V,
408  $snake
409  );
410  }
411 
412  $this->m = $m;
413  $this->n = $n;
414 
415  $this->length += $i + $j - 1;
416 
417  foreach ( $this->removed as $key => &$removed_elem ) {
418  if ( !$removed_elem ) {
419  $removed[$newFromIndex[$key]] = false;
420  }
421  }
422  foreach ( $this->added as $key => &$added_elem ) {
423  if ( !$added_elem ) {
424  $added[$newToIndex[$key]] = false;
425  }
426  }
427  $this->removed = $removed;
428  $this->added = $added;
429  }
430 
440  private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
441  // check that both sequences are non-empty
442  if ( $bottoml1 > $topl1 || $bottoml2 > $topl2 ) {
443  return 0;
444  }
445 
446  $d = $this->find_middle_snake( $bottoml1, $topl1, $bottoml2,
447  $topl2, $V, $snake );
448 
449  // need to store these so we don't lose them when they're
450  // overwritten by the recursion
451  list( $startx, $starty, $len ) = $snake;
452 
453  // the middle snake is part of the LCS, store it
454  for ( $i = 0; $i < $len; ++$i ) {
455  $this->removed[$startx + $i] = $this->added[$starty + $i] = false;
456  }
457 
458  if ( $d > 1 ) {
459  return $len
460  + $this->lcs_rec( $bottoml1, $startx - 1, $bottoml2,
461  $starty - 1, $V, $snake )
462  + $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
463  $topl2, $V, $snake );
464  } elseif ( $d == 1 ) {
465  /*
466  * In this case the sequences differ by exactly 1 line. We have
467  * already saved all the lines after the difference in the for loop
468  * above, now we need to save all the lines before the difference.
469  */
470  $max = min( $startx - $bottoml1, $starty - $bottoml2 );
471  for ( $i = 0; $i < $max; ++$i ) {
472  $this->removed[$bottoml1 + $i] =
473  $this->added[$bottoml2 + $i] = false;
474  }
475 
476  return $max + $len;
477  }
478 
479  return $len;
480  }
481 
491  private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
492  $from = &$this->from;
493  $to = &$this->to;
494  $V0 = &$V[0];
495  $V1 = &$V[1];
496  $snake0 = &$snake[0];
497  $snake1 = &$snake[1];
498  $snake2 = &$snake[2];
499  $bottoml1_min_1 = $bottoml1 - 1;
500  $bottoml2_min_1 = $bottoml2 - 1;
501  $N = $topl1 - $bottoml1_min_1;
502  $M = $topl2 - $bottoml2_min_1;
503  $delta = $N - $M;
504  $maxabsx = $N + $bottoml1;
505  $maxabsy = $M + $bottoml2;
506  $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
507 
508  // value_to_add_forward: a 0 or 1 that we add to the start
509  // offset to make it odd/even
510  if ( $M & 1 ) {
511  $value_to_add_forward = 1;
512  } else {
513  $value_to_add_forward = 0;
514  }
515 
516  if ( $N & 1 ) {
517  $value_to_add_backward = 1;
518  } else {
519  $value_to_add_backward = 0;
520  }
521 
522  $start_forward = -$M;
523  $end_forward = $N;
524  $start_backward = -$N;
525  $end_backward = $M;
526 
527  $limit_min_1 = $limit - 1;
528  $limit_plus_1 = $limit + 1;
529 
530  $V0[$limit_plus_1] = 0;
531  $V1[$limit_min_1] = $N;
532  $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
533 
534  if ( $delta & 1 ) {
535  for ( $d = 0; $d <= $limit; ++$d ) {
536  $start_diag = max( $value_to_add_forward + $start_forward, -$d );
537  $end_diag = min( $end_forward, $d );
538  $value_to_add_forward = 1 - $value_to_add_forward;
539 
540  // compute forward furthest reaching paths
541  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
542  if ( $k == -$d || ( $k < $d
543  && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
544  ) {
545  $x = $V0[$limit_plus_1 + $k];
546  } else {
547  $x = $V0[$limit_min_1 + $k] + 1;
548  }
549 
550  $absx = $snake0 = $x + $bottoml1;
551  $absy = $snake1 = $x - $k + $bottoml2;
552 
553  while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
554  ++$absx;
555  ++$absy;
556  }
557  $x = $absx - $bottoml1;
558 
559  $snake2 = $absx - $snake0;
560  $V0[$limit + $k] = $x;
561  if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
562  && $x >= $V1[$limit + $k - $delta]
563  ) {
564  return 2 * $d - 1;
565  }
566 
567  // check to see if we can cut down the diagonal range
568  if ( $x >= $N && $end_forward > $k - 1 ) {
569  $end_forward = $k - 1;
570  } elseif ( $absy - $bottoml2 >= $M ) {
571  $start_forward = $k + 1;
572  $value_to_add_forward = 0;
573  }
574  }
575 
576  $start_diag = max( $value_to_add_backward + $start_backward, -$d );
577  $end_diag = min( $end_backward, $d );
578  $value_to_add_backward = 1 - $value_to_add_backward;
579 
580  // compute backward furthest reaching paths
581  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
582  if ( $k == $d
583  || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
584  ) {
585  $x = $V1[$limit_min_1 + $k];
586  } else {
587  $x = $V1[$limit_plus_1 + $k] - 1;
588  }
589 
590  $y = $x - $k - $delta;
591 
592  $snake2 = 0;
593  while ( $x > 0 && $y > 0
594  && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
595  ) {
596  --$x;
597  --$y;
598  ++$snake2;
599  }
600  $V1[$limit + $k] = $x;
601 
602  // check to see if we can cut down our diagonal range
603  if ( $x <= 0 ) {
604  $start_backward = $k + 1;
605  $value_to_add_backward = 0;
606  } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
607  $end_backward = $k - 1;
608  }
609  }
610  }
611  } else {
612  for ( $d = 0; $d <= $limit; ++$d ) {
613  $start_diag = max( $value_to_add_forward + $start_forward, -$d );
614  $end_diag = min( $end_forward, $d );
615  $value_to_add_forward = 1 - $value_to_add_forward;
616 
617  // compute forward furthest reaching paths
618  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
619  if ( $k == -$d
620  || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
621  ) {
622  $x = $V0[$limit_plus_1 + $k];
623  } else {
624  $x = $V0[$limit_min_1 + $k] + 1;
625  }
626 
627  $absx = $snake0 = $x + $bottoml1;
628  $absy = $snake1 = $x - $k + $bottoml2;
629 
630  while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
631  ++$absx;
632  ++$absy;
633  }
634  $x = $absx - $bottoml1;
635  $snake2 = $absx - $snake0;
636  $V0[$limit + $k] = $x;
637 
638  // check to see if we can cut down the diagonal range
639  if ( $x >= $N && $end_forward > $k - 1 ) {
640  $end_forward = $k - 1;
641  } elseif ( $absy - $bottoml2 >= $M ) {
642  $start_forward = $k + 1;
643  $value_to_add_forward = 0;
644  }
645  }
646 
647  $start_diag = max( $value_to_add_backward + $start_backward, -$d );
648  $end_diag = min( $end_backward, $d );
649  $value_to_add_backward = 1 - $value_to_add_backward;
650 
651  // compute backward furthest reaching paths
652  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
653  if ( $k == $d
654  || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
655  ) {
656  $x = $V1[$limit_min_1 + $k];
657  } else {
658  $x = $V1[$limit_plus_1 + $k] - 1;
659  }
660 
661  $y = $x - $k - $delta;
662 
663  $snake2 = 0;
664  while ( $x > 0 && $y > 0
665  && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
666  ) {
667  --$x;
668  --$y;
669  ++$snake2;
670  }
671  $V1[$limit + $k] = $x;
672 
673  if ( $k >= -$delta - $d && $k <= $d - $delta
674  && $x <= $V0[$limit + $k + $delta]
675  ) {
676  $snake0 = $bottoml1 + $x;
677  $snake1 = $bottoml2 + $y;
678 
679  return 2 * $d;
680  }
681 
682  // check to see if we can cut down our diagonal range
683  if ( $x <= 0 ) {
684  $start_backward = $k + 1;
685  $value_to_add_backward = 0;
686  } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
687  $end_backward = $k - 1;
688  }
689  }
690  }
691  }
692  /*
693  * computing the true LCS is too expensive, instead find the diagonal
694  * with the most progress and pretend a midle snake of length 0 occurs
695  * there.
696  */
697 
698  $most_progress = self::findMostProgress( $M, $N, $limit, $V );
699 
700  $snake0 = $bottoml1 + $most_progress[0];
701  $snake1 = $bottoml2 + $most_progress[1];
702  $snake2 = 0;
703  wfDebug( "Computing the LCS is too expensive. Using a heuristic." );
704  $this->heuristicUsed = true;
705 
706  return 5; /*
707  * HACK: since we didn't really finish the LCS computation
708  * we don't really know the length of the SES. We don't do
709  * anything with the result anyway, unless it's <=1. We know
710  * for a fact SES > 1 so 5 is as good a number as any to
711  * return here
712  */
713  }
714 
722  private static function findMostProgress( $M, $N, $limit, $V ) {
723  $delta = $N - $M;
724 
725  if ( ( $M & 1 ) == ( $limit & 1 ) ) {
726  $forward_start_diag = max( -$M, -$limit );
727  } else {
728  $forward_start_diag = max( 1 - $M, -$limit );
729  }
730 
731  $forward_end_diag = min( $N, $limit );
732 
733  if ( ( $N & 1 ) == ( $limit & 1 ) ) {
734  $backward_start_diag = max( -$N, -$limit );
735  } else {
736  $backward_start_diag = max( 1 - $N, -$limit );
737  }
738 
739  $backward_end_diag = -min( $M, $limit );
740 
741  $temp = [ 0, 0, 0 ];
742 
743  $max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
744  $backward_end_diag - $backward_start_diag ) / 2 ), $temp );
745  $num_progress = 0; // the 1st entry is current, it is initialized
746  // with 0s
747 
748  // first search the forward diagonals
749  for ( $k = $forward_start_diag; $k <= $forward_end_diag; $k += 2 ) {
750  $x = $V[0][$limit + $k];
751  $y = $x - $k;
752  if ( $x > $N || $y > $M ) {
753  continue;
754  }
755 
756  $progress = $x + $y;
757  if ( $progress > $max_progress[0][2] ) {
758  $num_progress = 0;
759  $max_progress[0][0] = $x;
760  $max_progress[0][1] = $y;
761  $max_progress[0][2] = $progress;
762  } elseif ( $progress == $max_progress[0][2] ) {
763  ++$num_progress;
764  $max_progress[$num_progress][0] = $x;
765  $max_progress[$num_progress][1] = $y;
766  $max_progress[$num_progress][2] = $progress;
767  }
768  }
769 
770  $max_progress_forward = true; // initially the maximum
771  // progress is in the forward
772  // direction
773 
774  // now search the backward diagonals
775  for ( $k = $backward_start_diag; $k <= $backward_end_diag; $k += 2 ) {
776  $x = $V[1][$limit + $k];
777  $y = $x - $k - $delta;
778  if ( $x < 0 || $y < 0 ) {
779  continue;
780  }
781 
782  $progress = $N - $x + $M - $y;
783  if ( $progress > $max_progress[0][2] ) {
784  $num_progress = 0;
785  $max_progress_forward = false;
786  $max_progress[0][0] = $x;
787  $max_progress[0][1] = $y;
788  $max_progress[0][2] = $progress;
789  } elseif ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
790  ++$num_progress;
791  $max_progress[$num_progress][0] = $x;
792  $max_progress[$num_progress][1] = $y;
793  $max_progress[$num_progress][2] = $progress;
794  }
795  }
796 
797  // return the middle diagonal with maximal progress.
798  return $max_progress[(int)floor( $num_progress / 2 )];
799  }
800 
804  public function getLcsLength() {
805  if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
806  $this->lcsLengthCorrectedForHeuristic = true;
807  $this->length = $this->m - array_sum( $this->added );
808  }
809 
810  return $this->length;
811  }
812 
813 }
DiffEngine\$lcsLengthCorrectedForHeuristic
bool $lcsLengthCorrectedForHeuristic
Definition: DiffEngine.php:71
DiffEngine\$heuristicUsed
bool $heuristicUsed
Definition: DiffEngine.php:81
DiffEngine\shiftBoundaries
shiftBoundaries(array $lines, array &$changed, array $other_changed)
Adjust inserts/deletes of identical lines to join changes as much as possible.
Definition: DiffEngine.php:179
n
while(( $__line=Maintenance::readconsole()) !==false) print n
Definition: eval.php:69
DiffOpDelete
Extends DiffOp.
Definition: DiffOpDelete.php:35
DiffEngine\$bailoutComplexity
int $bailoutComplexity
Definition: DiffEngine.php:65
DiffEngine\$maxDifferences
float $maxDifferences
Definition: DiffEngine.php:69
DiffOpChange
Extends DiffOp.
Definition: DiffOpChange.php:35
DiffEngine\diff
diff( $from_lines, $to_lines)
Performs diff.
Definition: DiffEngine.php:101
DiffEngine\getLcsLength
getLcsLength()
Definition: DiffEngine.php:804
DiffOpCopy
Extends DiffOp.
Definition: DiffOpCopy.php:35
DiffEngine\$to
string[] $to
Definition: DiffEngine.php:53
DiffEngine\$from
string[] $from
Definition: DiffEngine.php:51
DiffOpAdd
Extends DiffOp.
Definition: DiffOpAdd.php:35
DiffEngine\setBailoutComplexity
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Definition: DiffEngine.php:158
DiffEngine\$removed
array $removed
Definition: DiffEngine.php:77
DiffEngine\findMostProgress
static findMostProgress( $M, $N, $limit, $V)
Definition: DiffEngine.php:722
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
DiffEngine\$m
int $m
Definition: DiffEngine.php:55
DiffEngine\$powLimit
float $powLimit
Definition: DiffEngine.php:62
$lines
if(!file_exists( $CREDITS)) $lines
Definition: updateCredits.php:45
DiffEngine\__construct
__construct( $tooLong=2000000, $powLimit=1.45)
Definition: DiffEngine.php:87
DiffEngine\$n
int $n
Definition: DiffEngine.php:57
DiffEngine
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
Definition: DiffEngine.php:47
DiffEngine\$length
int $length
Definition: DiffEngine.php:75
MediaWiki\Diff\ComplexityException
@newable
Definition: ComplexityException.php:29
DiffEngine\$added
array $added
Definition: DiffEngine.php:79
DiffEngine\lcs_rec
lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake)
Definition: DiffEngine.php:440
DiffEngine\$tooLong
int $tooLong
Definition: DiffEngine.php:60
DiffEngine\diffInternal
diffInternal(array $from, array $to)
Definition: DiffEngine.php:302
DiffEngine\find_middle_snake
find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake)
Definition: DiffEngine.php:491