Skip to content

Commit 303582b

Browse files
committed
Additional helper getWeight()
1 parent 4bf420c commit 303582b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/MinimumSpanningTree/Base.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ abstract public function getEdges();
5454
*/
5555
abstract protected function getGraph();
5656

57+
/**
58+
* get total weight of minimum spanning tree
59+
*
60+
* @return float
61+
*/
62+
public function getWeight()
63+
{
64+
return $this->getEdges()->getSumCallback(function (Edge $edge) {
65+
return $edge->getWeight();
66+
});
67+
}
68+
5769
/**
5870
* helper method to add a set of Edges to the given set of sorted edges
5971
*

0 commit comments

Comments
 (0)