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  while ( $start > 0 && $changed[$start - 1] ) {
239  $start--;
240  }
241  assert( $j > 0 );
242  while ( $other_changed[--$j] ) {
243  continue;
244  }
245  assert( $j >= 0 && !$other_changed[$j] );
246  }
247 
248  /*
249  * Set CORRESPONDING to the end of the changed run, at the last
250  * point where it corresponds to a changed run in the other file.
251  * CORRESPONDING == LEN means no such point has been found.
252  */
253  $corresponding = $j < $other_len ? $i : $len;
254 
255  /*
256  * Move the changed region forward, so long as the
257  * first changed line matches the following unchanged one.
258  * This merges with following changed regions.
259  * Do this second, so that if there are no merges,
260  * the changed region is moved forward as far as possible.
261  */
262  while ( $i < $len && $lines[$start] == $lines[$i] ) {
263  $changed[$start++] = false;
264  $changed[$i++] = 1;
265  while ( $i < $len && $changed[$i] ) {
266  $i++;
267  }
268 
269  assert( $j < $other_len && !$other_changed[$j] );
270  $j++;
271  if ( $j < $other_len && $other_changed[$j] ) {
272  $corresponding = $i;
273  while ( $j < $other_len && $other_changed[$j] ) {
274  $j++;
275  }
276  }
277  }
278  } while ( $runlength != $i - $start );
279 
280  /*
281  * If possible, move the fully-merged run of changes
282  * back to a corresponding run in the other file.
283  */
284  while ( $corresponding < $i ) {
285  $changed[--$start] = 1;
286  $changed[--$i] = 0;
287  assert( $j > 0 );
288  while ( $other_changed[--$j] ) {
289  continue;
290  }
291  assert( $j >= 0 && !$other_changed[$j] );
292  }
293  }
294  }
295 
301  protected function diffInternal( array $from, array $to ) {
302  // remember initial lengths
303  $m = count( $from );
304  $n = count( $to );
305 
306  $this->heuristicUsed = false;
307 
308  // output
309  $removed = $m > 0 ? array_fill( 0, $m, true ) : [];
310  $added = $n > 0 ? array_fill( 0, $n, true ) : [];
311 
312  // reduce the complexity for the next step (intentionally done twice)
313  // remove common tokens at the start
314  $i = 0;
315  while ( $i < $m && $i < $n && $from[$i] === $to[$i] ) {
316  $removed[$i] = $added[$i] = false;
317  unset( $from[$i], $to[$i] );
318  ++$i;
319  }
320 
321  // remove common tokens at the end
322  $j = 1;
323  while ( $i + $j <= $m && $i + $j <= $n && $from[$m - $j] === $to[$n - $j] ) {
324  $removed[$m - $j] = $added[$n - $j] = false;
325  unset( $from[$m - $j], $to[$n - $j] );
326  ++$j;
327  }
328 
329  $this->from = $newFromIndex = $this->to = $newToIndex = [];
330 
331  // remove tokens not in both sequences
332  $shared = [];
333  foreach ( $from as $key ) {
334  $shared[$key] = false;
335  }
336 
337  foreach ( $to as $index => &$el ) {
338  if ( array_key_exists( $el, $shared ) ) {
339  // keep it
340  $this->to[] = $el;
341  $shared[$el] = true;
342  $newToIndex[] = $index;
343  }
344  }
345  foreach ( $from as $index => &$el ) {
346  if ( $shared[$el] ) {
347  // keep it
348  $this->from[] = $el;
349  $newFromIndex[] = $index;
350  }
351  }
352 
353  unset( $shared, $from, $to );
354 
355  $this->m = count( $this->from );
356  $this->n = count( $this->to );
357 
358  if ( $this->bailoutComplexity > 0 && $this->m * $this->n > $this->bailoutComplexity ) {
359  throw new ComplexityException();
360  }
361 
362  $this->removed = $this->m > 0 ? array_fill( 0, $this->m, true ) : [];
363  $this->added = $this->n > 0 ? array_fill( 0, $this->n, true ) : [];
364 
365  if ( $this->m == 0 || $this->n == 0 ) {
366  $this->length = 0;
367  } else {
368  $this->maxDifferences = ceil( ( $this->m + $this->n ) / 2.0 );
369  if ( $this->m * $this->n > $this->tooLong ) {
370  // limit complexity to D^POW_LIMIT for long sequences
371  $this->maxDifferences = floor( $this->maxDifferences ** ( $this->powLimit - 1.0 ) );
372  wfDebug( "Limiting max number of differences to $this->maxDifferences" );
373  }
374 
375  /*
376  * The common prefixes and suffixes are always part of some LCS, include
377  * them now to reduce our search space
378  */
379  $max = min( $this->m, $this->n );
380  for ( $forwardBound = 0; $forwardBound < $max
381  && $this->from[$forwardBound] === $this->to[$forwardBound];
382  ++$forwardBound
383  ) {
384  $this->removed[$forwardBound] = $this->added[$forwardBound] = false;
385  }
386 
387  $backBoundL1 = $this->m - 1;
388  $backBoundL2 = $this->n - 1;
389 
390  while ( $backBoundL1 >= $forwardBound && $backBoundL2 >= $forwardBound
391  && $this->from[$backBoundL1] === $this->to[$backBoundL2]
392  ) {
393  $this->removed[$backBoundL1--] = $this->added[$backBoundL2--] = false;
394  }
395 
396  $temp = array_fill( 0, $this->m + $this->n + 1, 0 );
397  $V = [ $temp, $temp ];
398  $snake = [ 0, 0, 0 ];
399 
400  $this->length = $forwardBound + $this->m - $backBoundL1 - 1
401  + $this->lcs_rec(
402  $forwardBound,
403  $backBoundL1,
404  $forwardBound,
405  $backBoundL2,
406  $V,
407  $snake
408  );
409  }
410 
411  $this->m = $m;
412  $this->n = $n;
413 
414  $this->length += $i + $j - 1;
415 
416  foreach ( $this->removed as $key => &$removed_elem ) {
417  if ( !$removed_elem ) {
418  $removed[$newFromIndex[$key]] = false;
419  }
420  }
421  foreach ( $this->added as $key => &$added_elem ) {
422  if ( !$added_elem ) {
423  $added[$newToIndex[$key]] = false;
424  }
425  }
426  $this->removed = $removed;
427  $this->added = $added;
428  }
429 
439  private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
440  // check that both sequences are non-empty
441  if ( $bottoml1 > $topl1 || $bottoml2 > $topl2 ) {
442  return 0;
443  }
444 
445  $d = $this->find_middle_snake( $bottoml1, $topl1, $bottoml2,
446  $topl2, $V, $snake );
447 
448  // need to store these so we don't lose them when they're
449  // overwritten by the recursion
450  list( $startx, $starty, $len ) = $snake;
451 
452  // the middle snake is part of the LCS, store it
453  for ( $i = 0; $i < $len; ++$i ) {
454  $this->removed[$startx + $i] = $this->added[$starty + $i] = false;
455  }
456 
457  if ( $d > 1 ) {
458  return $len
459  + $this->lcs_rec( $bottoml1, $startx - 1, $bottoml2,
460  $starty - 1, $V, $snake )
461  + $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
462  $topl2, $V, $snake );
463  } elseif ( $d == 1 ) {
464  /*
465  * In this case the sequences differ by exactly 1 line. We have
466  * already saved all the lines after the difference in the for loop
467  * above, now we need to save all the lines before the difference.
468  */
469  $max = min( $startx - $bottoml1, $starty - $bottoml2 );
470  for ( $i = 0; $i < $max; ++$i ) {
471  $this->removed[$bottoml1 + $i] =
472  $this->added[$bottoml2 + $i] = false;
473  }
474 
475  return $max + $len;
476  }
477 
478  return $len;
479  }
480 
490  private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
491  $from = &$this->from;
492  $to = &$this->to;
493  $V0 = &$V[0];
494  $V1 = &$V[1];
495  $snake0 = &$snake[0];
496  $snake1 = &$snake[1];
497  $snake2 = &$snake[2];
498  $bottoml1_min_1 = $bottoml1 - 1;
499  $bottoml2_min_1 = $bottoml2 - 1;
500  $N = $topl1 - $bottoml1_min_1;
501  $M = $topl2 - $bottoml2_min_1;
502  $delta = $N - $M;
503  $maxabsx = $N + $bottoml1;
504  $maxabsy = $M + $bottoml2;
505  $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
506 
507  // value_to_add_forward: a 0 or 1 that we add to the start
508  // offset to make it odd/even
509  if ( $M & 1 ) {
510  $value_to_add_forward = 1;
511  } else {
512  $value_to_add_forward = 0;
513  }
514 
515  if ( $N & 1 ) {
516  $value_to_add_backward = 1;
517  } else {
518  $value_to_add_backward = 0;
519  }
520 
521  $start_forward = -$M;
522  $end_forward = $N;
523  $start_backward = -$N;
524  $end_backward = $M;
525 
526  $limit_min_1 = $limit - 1;
527  $limit_plus_1 = $limit + 1;
528 
529  $V0[$limit_plus_1] = 0;
530  $V1[$limit_min_1] = $N;
531  $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) );
532 
533  if ( $delta & 1 ) {
534  for ( $d = 0; $d <= $limit; ++$d ) {
535  $start_diag = max( $value_to_add_forward + $start_forward, -$d );
536  $end_diag = min( $end_forward, $d );
537  $value_to_add_forward = 1 - $value_to_add_forward;
538 
539  // compute forward furthest reaching paths
540  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
541  if ( $k == -$d || ( $k < $d
542  && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
543  ) {
544  $x = $V0[$limit_plus_1 + $k];
545  } else {
546  $x = $V0[$limit_min_1 + $k] + 1;
547  }
548 
549  $absx = $snake0 = $x + $bottoml1;
550  $absy = $snake1 = $x - $k + $bottoml2;
551 
552  while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
553  ++$absx;
554  ++$absy;
555  }
556  $x = $absx - $bottoml1;
557 
558  $snake2 = $absx - $snake0;
559  $V0[$limit + $k] = $x;
560  if ( $k >= $delta - $d + 1 && $k <= $delta + $d - 1
561  && $x >= $V1[$limit + $k - $delta]
562  ) {
563  return 2 * $d - 1;
564  }
565 
566  // check to see if we can cut down the diagonal range
567  if ( $x >= $N && $end_forward > $k - 1 ) {
568  $end_forward = $k - 1;
569  } elseif ( $absy - $bottoml2 >= $M ) {
570  $start_forward = $k + 1;
571  $value_to_add_forward = 0;
572  }
573  }
574 
575  $start_diag = max( $value_to_add_backward + $start_backward, -$d );
576  $end_diag = min( $end_backward, $d );
577  $value_to_add_backward = 1 - $value_to_add_backward;
578 
579  // compute backward furthest reaching paths
580  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
581  if ( $k == $d
582  || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
583  ) {
584  $x = $V1[$limit_min_1 + $k];
585  } else {
586  $x = $V1[$limit_plus_1 + $k] - 1;
587  }
588 
589  $y = $x - $k - $delta;
590 
591  $snake2 = 0;
592  while ( $x > 0 && $y > 0
593  && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
594  ) {
595  --$x;
596  --$y;
597  ++$snake2;
598  }
599  $V1[$limit + $k] = $x;
600 
601  // check to see if we can cut down our diagonal range
602  if ( $x <= 0 ) {
603  $start_backward = $k + 1;
604  $value_to_add_backward = 0;
605  } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
606  $end_backward = $k - 1;
607  }
608  }
609  }
610  } else {
611  for ( $d = 0; $d <= $limit; ++$d ) {
612  $start_diag = max( $value_to_add_forward + $start_forward, -$d );
613  $end_diag = min( $end_forward, $d );
614  $value_to_add_forward = 1 - $value_to_add_forward;
615 
616  // compute forward furthest reaching paths
617  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
618  if ( $k == -$d
619  || ( $k < $d && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k] )
620  ) {
621  $x = $V0[$limit_plus_1 + $k];
622  } else {
623  $x = $V0[$limit_min_1 + $k] + 1;
624  }
625 
626  $absx = $snake0 = $x + $bottoml1;
627  $absy = $snake1 = $x - $k + $bottoml2;
628 
629  while ( $absx < $maxabsx && $absy < $maxabsy && $from[$absx] === $to[$absy] ) {
630  ++$absx;
631  ++$absy;
632  }
633  $x = $absx - $bottoml1;
634  $snake2 = $absx - $snake0;
635  $V0[$limit + $k] = $x;
636 
637  // check to see if we can cut down the diagonal range
638  if ( $x >= $N && $end_forward > $k - 1 ) {
639  $end_forward = $k - 1;
640  } elseif ( $absy - $bottoml2 >= $M ) {
641  $start_forward = $k + 1;
642  $value_to_add_forward = 0;
643  }
644  }
645 
646  $start_diag = max( $value_to_add_backward + $start_backward, -$d );
647  $end_diag = min( $end_backward, $d );
648  $value_to_add_backward = 1 - $value_to_add_backward;
649 
650  // compute backward furthest reaching paths
651  for ( $k = $start_diag; $k <= $end_diag; $k += 2 ) {
652  if ( $k == $d
653  || ( $k != -$d && $V1[$limit_min_1 + $k] < $V1[$limit_plus_1 + $k] )
654  ) {
655  $x = $V1[$limit_min_1 + $k];
656  } else {
657  $x = $V1[$limit_plus_1 + $k] - 1;
658  }
659 
660  $y = $x - $k - $delta;
661 
662  $snake2 = 0;
663  while ( $x > 0 && $y > 0
664  && $from[$x + $bottoml1_min_1] === $to[$y + $bottoml2_min_1]
665  ) {
666  --$x;
667  --$y;
668  ++$snake2;
669  }
670  $V1[$limit + $k] = $x;
671 
672  if ( $k >= -$delta - $d && $k <= $d - $delta
673  && $x <= $V0[$limit + $k + $delta]
674  ) {
675  $snake0 = $bottoml1 + $x;
676  $snake1 = $bottoml2 + $y;
677 
678  return 2 * $d;
679  }
680 
681  // check to see if we can cut down our diagonal range
682  if ( $x <= 0 ) {
683  $start_backward = $k + 1;
684  $value_to_add_backward = 0;
685  } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
686  $end_backward = $k - 1;
687  }
688  }
689  }
690  }
691  /*
692  * computing the true LCS is too expensive, instead find the diagonal
693  * with the most progress and pretend a midle snake of length 0 occurs
694  * there.
695  */
696 
697  $most_progress = self::findMostProgress( $M, $N, $limit, $V );
698 
699  $snake0 = $bottoml1 + $most_progress[0];
700  $snake1 = $bottoml2 + $most_progress[1];
701  $snake2 = 0;
702  wfDebug( "Computing the LCS is too expensive. Using a heuristic." );
703  $this->heuristicUsed = true;
704 
705  return 5; /*
706  * HACK: since we didn't really finish the LCS computation
707  * we don't really know the length of the SES. We don't do
708  * anything with the result anyway, unless it's <=1. We know
709  * for a fact SES > 1 so 5 is as good a number as any to
710  * return here
711  */
712  }
713 
721  private static function findMostProgress( $M, $N, $limit, $V ) {
722  $delta = $N - $M;
723 
724  if ( ( $M & 1 ) == ( $limit & 1 ) ) {
725  $forward_start_diag = max( -$M, -$limit );
726  } else {
727  $forward_start_diag = max( 1 - $M, -$limit );
728  }
729 
730  $forward_end_diag = min( $N, $limit );
731 
732  if ( ( $N & 1 ) == ( $limit & 1 ) ) {
733  $backward_start_diag = max( -$N, -$limit );
734  } else {
735  $backward_start_diag = max( 1 - $N, -$limit );
736  }
737 
738  $backward_end_diag = -min( $M, $limit );
739 
740  $temp = [ 0, 0, 0 ];
741 
742  $max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
743  $backward_end_diag - $backward_start_diag ) / 2 ), $temp );
744  $num_progress = 0; // the 1st entry is current, it is initialized
745  // with 0s
746 
747  // first search the forward diagonals
748  for ( $k = $forward_start_diag; $k <= $forward_end_diag; $k += 2 ) {
749  $x = $V[0][$limit + $k];
750  $y = $x - $k;
751  if ( $x > $N || $y > $M ) {
752  continue;
753  }
754 
755  $progress = $x + $y;
756  if ( $progress > $max_progress[0][2] ) {
757  $num_progress = 0;
758  $max_progress[0][0] = $x;
759  $max_progress[0][1] = $y;
760  $max_progress[0][2] = $progress;
761  } elseif ( $progress == $max_progress[0][2] ) {
762  ++$num_progress;
763  $max_progress[$num_progress][0] = $x;
764  $max_progress[$num_progress][1] = $y;
765  $max_progress[$num_progress][2] = $progress;
766  }
767  }
768 
769  $max_progress_forward = true; // initially the maximum
770  // progress is in the forward
771  // direction
772 
773  // now search the backward diagonals
774  for ( $k = $backward_start_diag; $k <= $backward_end_diag; $k += 2 ) {
775  $x = $V[1][$limit + $k];
776  $y = $x - $k - $delta;
777  if ( $x < 0 || $y < 0 ) {
778  continue;
779  }
780 
781  $progress = $N - $x + $M - $y;
782  if ( $progress > $max_progress[0][2] ) {
783  $num_progress = 0;
784  $max_progress_forward = false;
785  $max_progress[0][0] = $x;
786  $max_progress[0][1] = $y;
787  $max_progress[0][2] = $progress;
788  } elseif ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
789  ++$num_progress;
790  $max_progress[$num_progress][0] = $x;
791  $max_progress[$num_progress][1] = $y;
792  $max_progress[$num_progress][2] = $progress;
793  }
794  }
795 
796  // return the middle diagonal with maximal progress.
797  return $max_progress[(int)floor( $num_progress / 2 )];
798  }
799 
803  public function getLcsLength() {
804  if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
805  $this->lcsLengthCorrectedForHeuristic = true;
806  $this->length = $this->m - array_sum( $this->added );
807  }
808 
809  return $this->length;
810  }
811 
812 }
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:64
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:803
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:721
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:910
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:49
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:439
DiffEngine\$tooLong
int $tooLong
Definition: DiffEngine.php:60
DiffEngine\diffInternal
diffInternal(array $from, array $to)
Definition: DiffEngine.php:301
DiffEngine\find_middle_snake
find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake)
Definition: DiffEngine.php:490