File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Fhaculty \Graph \Algorithm \BaseGraph ;
6
6
use Fhaculty \Graph \Algorithm \Search \BreadthFirst as SearchBreadthFirst ;
7
-
8
- use Fhaculty \Graph \Exception \InvalidArgumentException ;
9
-
10
7
use Fhaculty \Graph \Graph ;
11
8
use Fhaculty \Graph \Vertex ;
9
+ use Fhaculty \Graph \Exception \InvalidArgumentException ;
10
+ use Fhaculty \Graph \Exception \UnderflowException ;
12
11
13
12
class ConnectedComponents extends BaseGraph
14
13
{
@@ -50,7 +49,14 @@ private function createSearch(Vertex $vertex)
50
49
*/
51
50
public function isSingle ()
52
51
{
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 );
54
60
55
61
return ($ this ->graph ->getNumberOfVertices () === $ alg ->getNumberOfVertices ());
56
62
}
You can’t perform that action at this time.
0 commit comments