Skip to content

Commit 5843509

Browse files
Cleanup
1 parent 1534560 commit 5843509

4 files changed

+18
-14
lines changed

src/Differ.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -247,32 +247,36 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
247247
}
248248

249249
/**
250-
* @param array|string $from
251-
* @param array|string $to
250+
* @param array $from
251+
* @param array $to
252252
* @return LongestCommonSubsequence
253253
*/
254-
private function selectLcsImplementation($from, $to)
254+
private function selectLcsImplementation(array $from, array $to)
255255
{
256-
// We don't want to use the time efficient implementation if it's memory
256+
// We do not want to use the time-efficient implementation if its memory
257257
// footprint will probably exceed this value. Note that the footprint
258258
// calculation is only an estimation for the matrix and the LCS method
259259
// will typically allocate a bit more memory than this.
260-
$memoryLimit = 100 * 1024*1024;
260+
$memoryLimit = 100 * 1024 * 1024;
261+
261262
if ($this->calculateEstimatedFootprint($from, $to) > $memoryLimit) {
262-
return new MemoryEfficientImplementation;
263+
return new MemoryEfficientImplementation;
263264
}
265+
264266
return new TimeEfficientImplementation;
265267
}
266268

267269
/**
268270
* Calculates the estimated memory footprint for the DP-based method.
269271
*
270-
* @param type $from
271-
* @param type $to
272+
* @param array $from
273+
* @param array $to
274+
* @return integer
272275
*/
273-
private function calculateEstimatedFootprint($from, $to)
276+
private function calculateEstimatedFootprint(array $from, array $to)
274277
{
275278
$itemSize = PHP_INT_SIZE == 4 ? 76 : 144;
279+
276280
return $itemSize * pow(min(count($from), count($to)), 2);
277281
}
278282
}

src/LCS/LongestCommonSubsequence.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ interface LongestCommonSubsequence
6464
* @return array
6565
*/
6666
public function calculate(array $from, array $to);
67-
}
67+
}

src/LCS/MemoryEfficientLongestCommonSubsequenceImplementation.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function calculate(array $from, array $to)
8585
$jMax = 0;
8686
$max = 0;
8787

88-
for($j = 0; $j <= $cTo; $j++) {
88+
for ($j = 0; $j <= $cTo; $j++) {
8989
$m = $llB[$j] + $llE[$cTo - $j];
9090

9191
if ($m >= $max) {
@@ -115,7 +115,7 @@ private function length(array $from, array $to)
115115
$cFrom = count($from);
116116
$cTo = count($to);
117117

118-
for($i = 0; $i < $cFrom; $i++) {
118+
for ($i = 0; $i < $cFrom; $i++) {
119119
$prev = $current;
120120

121121
for ($j = 0; $j < $cTo; $j++) {
@@ -129,4 +129,4 @@ private function length(array $from, array $to)
129129

130130
return $current;
131131
}
132-
}
132+
}

src/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ public function calculate(array $from, array $to)
105105

106106
return $common;
107107
}
108-
}
108+
}

0 commit comments

Comments
 (0)