Skip to content

Commit 2b0e963

Browse files
committed
Improve documentation for Algorithm\ConnectedComponents
1 parent 84dd3aa commit 2b0e963

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/ConnectedComponents.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
use Fhaculty\Graph\Exception\InvalidArgumentException;
1010
use 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+
*/
1219
class 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

Comments
 (0)