X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsebastian%2Fdiff%2Fsrc%2FLCS%2FTimeEfficientLongestCommonSubsequenceImplementation.php;h=f31db3eb8dfdae1096479f935db72e0cdfecaac4;hp=4fc9d3ecf62447e99290df13726b82d06e014058;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/sebastian/diff/src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php b/vendor/sebastian/diff/src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php index 4fc9d3ecf..f31db3eb8 100644 --- a/vendor/sebastian/diff/src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php +++ b/vendor/sebastian/diff/src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php @@ -1,6 +1,6 @@ * @@ -26,8 +26,8 @@ class TimeEfficientImplementation implements LongestCommonSubsequence public function calculate(array $from, array $to) { $common = array(); - $fromLength = count($from); - $toLength = count($to); + $fromLength = \count($from); + $toLength = \count($to); $width = $fromLength + 1; $matrix = new \SplFixedArray($width * ($toLength + 1)); @@ -42,7 +42,7 @@ class TimeEfficientImplementation implements LongestCommonSubsequence for ($i = 1; $i <= $fromLength; ++$i) { for ($j = 1; $j <= $toLength; ++$j) { $o = ($j * $width) + $i; - $matrix[$o] = max( + $matrix[$o] = \max( $matrix[$o - 1], $matrix[$o - $width], $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0 @@ -54,12 +54,13 @@ class TimeEfficientImplementation implements LongestCommonSubsequence $j = $toLength; while ($i > 0 && $j > 0) { - if ($from[$i-1] === $to[$j-1]) { - $common[] = $from[$i-1]; + if ($from[$i - 1] === $to[$j - 1]) { + $common[] = $from[$i - 1]; --$i; --$j; } else { $o = ($j * $width) + $i; + if ($matrix[$o - $width] > $matrix[$o - 1]) { --$j; } else { @@ -68,6 +69,6 @@ class TimeEfficientImplementation implements LongestCommonSubsequence } } - return array_reverse($common); + return \array_reverse($common); } }