File tree Expand file tree Collapse file tree
lib/Fhaculty/Graph/Algorithm Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55use Fhaculty \Graph \Algorithm \BaseGraph ;
66use Fhaculty \Graph \Algorithm \Search \BreadthFirst as SearchBreadthFirst ;
7-
8- use Fhaculty \Graph \Exception \InvalidArgumentException ;
9-
107use Fhaculty \Graph \Graph ;
118use Fhaculty \Graph \Vertex ;
9+ use Fhaculty \Graph \Exception \InvalidArgumentException ;
10+ use Fhaculty \Graph \Exception \UnderflowException ;
1211
1312class ConnectedComponents extends BaseGraph
1413{
@@ -50,7 +49,14 @@ private function createSearch(Vertex $vertex)
5049 */
5150 public function isSingle ()
5251 {
53- $ alg = $ this ->createSearch ($ this ->graph ->getVertexFirst ());
52+ try {
53+ $ vertex = $ this ->graph ->getVertexFirst ();
54+ }
55+ catch (UnderflowException $ e ) {
56+ // no first vertex => empty graph => has zero components
57+ return false ;
58+ }
59+ $ alg = $ this ->createSearch ($ vertex );
5460
5561 return ($ this ->graph ->getNumberOfVertices () === $ alg ->getNumberOfVertices ());
5662 }
You can’t perform that action at this time.
0 commit comments