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