99use Fhaculty \Graph \Exception \InvalidArgumentException ;
1010use Fhaculty \Graph \Exception \UnderflowException ;
1111
12+ /**
13+ * Algorithm for working with connected components
14+ *
15+ * @link http://en.wikipedia.org/wiki/Connected_component_%28graph_theory%29
16+ * @link http://mathworld.wolfram.com/ConnectedGraph.html
17+ * @link http://math.stackexchange.com/questions/50551/is-the-empty-graph-connected
18+ */
1219class ConnectedComponents extends BaseGraph
1320{
1421 /**
@@ -40,12 +47,21 @@ private function createSearch(Vertex $vertex)
4047 /**
4148 * check whether this graph consists of only a single component
4249 *
43- * this is faster than calling getNumberOfComponents(), as it only has to
50+ * If a Graph consists of only a single component, it is said to be a
51+ * connected Graph, otherwise it's called a disconnected Graph.
52+ *
53+ * This method returns exactly the same result as checking
54+ * <pre>($this->getNumberOfComponents() === 1)</pre>. However, using this
55+ * method is faster than calling getNumberOfComponents(), as it only has to
4456 * count all vertices in one component to see if the graph consists of only
45- * a single component
57+ * a single component.
58+ *
59+ * As such, a null Graph (a Graph with no vertices) is not considered
60+ * connected here.
4661 *
4762 * @return boolean
4863 * @uses AlgorithmSearchBreadthFirst::getNumberOfVertices()
64+ * @see self::getNumberOfComponents()
4965 */
5066 public function isSingle ()
5167 {
@@ -62,6 +78,10 @@ public function isSingle()
6278 }
6379
6480 /**
81+ * count number of connected components
82+ *
83+ * A null Graph (a Graph with no vertices) will return 0 components.
84+ *
6585 * @return int number of components
6686 * @uses Graph::getVertices()
6787 * @uses AlgorithmSearchBreadthFirst::getVerticesIds()
0 commit comments