Skip to content

Commit b85a6cf

Browse files
authored
short circuit is_connected (#552)
1 parent 35d4597 commit b85a6cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/connectivity.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ end
101101
Returns `true` if `g` is connected.
102102
For DiGraphs, this is equivalent to a test of weak connectivity.
103103
"""
104-
is_connected(g::Graph) = length(connected_components(g)) == 1
105-
is_connected(g::DiGraph) = is_weakly_connected(g)
104+
is_connected(g::Graph) = ne(g)+1 >= nv(g) && length(connected_components(g)) == 1
105+
is_connected(g::DiGraph) = ne(g)+1 >= nv(g) && is_weakly_connected(g)
106106

107107
"""Returns connected components of the undirected graph of `g`."""
108108
weakly_connected_components(g::DiGraph) = connected_components(Graph(g))

0 commit comments

Comments
 (0)