Copied!

Implements the Myers diff algorithm.

Myers, Eugene W. "An O (ND) difference algorithm and its variations."
Algorithmica 1.1 (1986): 251-266.

  • internal
CloneableInstantiable
Methods
public __construct(callable $isEqual)
 

Create differ over the given equality relation.

  • param callable $isEqual Equality relation with signature function($a, $b) : bool
public diff(array $old, array $new)
 

Calculate diff (edit script) from $old to $new.

  • param array $old Original array
  • param array $new New array
  • return \DiffElem[] Diff (edit script)
public diffWithReplacements(array $old, array $new)
 

Calculate diff, including "replace" operations.

If a sequence of remove operations is followed by the same number of add operations, these
will be coalesced into replace operations.

  • param array $old Original array
  • param array $new New array
  • return \DiffElem[] Diff (edit script), including replace operations
Properties
private $isEqual = NULL
Methods
private calculateTrace(array $a, array $b)
private coalesceReplacements(array $diff)
 

Coalesce equal-length sequences of remove+add into a replace operation.

  • param \DiffElem[] $diff
  • return \DiffElem[]
private extractDiff(array $trace, int $x, int $y, array $a, array $b)
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration