@@ 27-37 (lines=11) @@ | ||
24 | * Compare elements in order to place them correctly in the heap while sifting up. |
|
25 | * @see \SplMinHeap::compare() |
|
26 | */ |
|
27 | public function compare($boxA, $boxB) |
|
28 | { |
|
29 | $choice = $boxA->getItems()->count() - $boxB->getItems()->count(); |
|
30 | if ($choice === 0) { |
|
31 | $choice = $boxB->getBox()->getInnerVolume() - $boxA->getBox()->getInnerVolume(); |
|
32 | } |
|
33 | if ($choice === 0) { |
|
34 | $choice = $boxA->getWeight() - $boxB->getWeight(); |
|
35 | } |
|
36 | return $choice; |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * Reversed version of compare |
|
@@ 43-53 (lines=11) @@ | ||
40 | * Reversed version of compare |
|
41 | * @return int |
|
42 | */ |
|
43 | public function reverseCompare($boxA, $boxB) |
|
44 | { |
|
45 | $choice = $boxB->getItems()->count() - $boxA->getItems()->count(); |
|
46 | if ($choice === 0) { |
|
47 | $choice = $boxA->getBox()->getInnerVolume() - $boxB->getBox()->getInnerVolume(); |
|
48 | } |
|
49 | if ($choice === 0) { |
|
50 | $choice = $boxB->getWeight() - $boxA->getWeight(); |
|
51 | } |
|
52 | return $choice; |
|
53 | } |
|
54 | ||
55 | /** |
|
56 | * Calculate the average (mean) weight of the boxes |