Skip to content

Commit 02046da

Browse files
committed
Merge pull request #75 from clue/remove-set
Remove base `Set`
2 parents 3e61948 + 2596ea0 commit 02046da

29 files changed

Lines changed: 103 additions & 124 deletions

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ you spot any mistakes.
7575
accordingly.
7676
([#72](https://github.com/clue/graph/issues/72))
7777

78+
* BC break: Remove all occurances of `getNumberOfVertices()` and
79+
`getNumberOfEdges()` ([#75](https://github.com/clue/graph/issues/75) and
80+
[#48](https://github.com/clue/graph/issues/48)):
81+
82+
| Old name | New name |
83+
|---|---|
84+
| `$set->getNumberOfVertices()` | `count($set->getVertices())` |
85+
| `$set->getNumberOfEdges()` | `count($set->getEdges())` |
86+
87+
* BC break: Replace base `Set` class with `Set\DualAggregate` interface. This
88+
is unlikely to affect you, but might potentially break your custom
89+
inheritance or polymorphism for algorithms.
90+
([#75](https://github.com/clue/graph/issues/75))
91+
7892
* Feature: Add `Algorithm\ShortestPath\Base::hasVertex(Vertex $vertex)` to check whether
7993
a path to the given Vertex exists ([#62](https://github.com/clue/graph/issues/62)).
8094

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Fhaculty\Graph\Algorithm;
44

55
use Fhaculty\Graph\Algorithm\Base;
6-
use Fhaculty\Graph\Set;
6+
use Fhaculty\Graph\Set\DualAggregate;
77
use Fhaculty\Graph\Graph;
88
use Fhaculty\Graph\Walk;
99

@@ -12,12 +12,12 @@
1212
*
1313
* @see Set
1414
*/
15-
abstract class BaseSet extends Base
15+
abstract class BaseDual extends Base
1616
{
1717
/**
1818
* Set to operate on
1919
*
20-
* @var Set
20+
* @var DualAggregate
2121
*/
2222
protected $set;
2323

@@ -26,7 +26,7 @@ abstract class BaseSet extends Base
2626
*
2727
* @param Graph|Walk|Set $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
2828
*/
29-
public function __construct(Set $graphOrWalk)
29+
public function __construct(DualAggregate $graphOrWalk)
3030
{
3131
$this->set = $graphOrWalk;
3232
}

lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ private function createSearch(Vertex $vertex)
6565
* connected here.
6666
*
6767
* @return boolean
68-
* @uses AlgorithmSearchBreadthFirst::getNumberOfVertices()
6968
* @see self::getNumberOfComponents()
7069
*/
7170
public function isSingle()
@@ -79,7 +78,7 @@ public function isSingle()
7978
}
8079
$alg = $this->createSearch($vertex);
8180

82-
return ($this->graph->getNumberOfVertices() === $alg->getNumberOfVertices());
81+
return (count($this->graph->getVertices()) === count($alg->getVertices()));
8382
}
8483

8584
/**

lib/Fhaculty/Graph/Algorithm/Directed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Direction
1212
* @link http://en.wikipedia.org/wiki/Digraph_%28mathematics%29
1313
*/
14-
class Directed extends BaseSet
14+
class Directed extends BaseDual
1515
{
1616
/**
1717
* checks whether the graph has any directed edges (aka digraph)

lib/Fhaculty/Graph/Algorithm/Flow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @link http://en.wikipedia.org/wiki/Flow_network
1919
* @see Algorithm\Balance
2020
*/
21-
class Flow extends BaseSet
21+
class Flow extends BaseDual
2222
{
2323
/**
2424
* check if this graph has any flow set (any edge has a non-NULL flow)

lib/Fhaculty/Graph/Algorithm/Loop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Fhaculty\Graph\Algorithm;
44

5-
use Fhaculty\Graph\Algorithm\BaseSet;
5+
use Fhaculty\Graph\Algorithm\BaseDual;
66
use Fhaculty\Graph\Edge\Base as Edge;
77
use Fhaculty\Graph\Vertex;
88

@@ -14,7 +14,7 @@
1414
*
1515
* @link http://en.wikipedia.org/wiki/Loop_%28graph_theory%29
1616
*/
17-
class Loop extends BaseSet
17+
class Loop extends BaseDual
1818
{
1919
/**
2020
* checks whether this graph has any loops (edges from vertex to itself)

lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ public function createGraph()
124124
* @param Graph $graph
125125
* @return boolean
126126
* @throws Exception if given graph is not a clone of the original graph (each vertex has to be present in both graphs)
127-
* @uses Graph::getNumberOfVertices()
128127
* @uses Graph::getBalanace()
129128
* @uses Graph::getVertex()
130129
*/
131130
private function isBalanceReached(Graph $graph)
132131
{
133-
if ($graph->getNumberOfVertices() !== $this->graph->getNumberOfVertices()) {
132+
if (count($graph->getVertices()) !== count($this->graph->getVertices())) {
134133
throw new DomainException('Given graph does not appear to be a clone of input graph');
135134
}
136135
foreach ($this->graph->getVertices()->getMap() as $vid => $vertex) {

lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getEdges()
125125

126126
// definition of spanning tree: number of edges = number of vertices - 1
127127
// above algorithm does not check isolated edges or may otherwise return multiple connected components => force check
128-
if (count($returnEdges) !== ($this->graph->getNumberOfVertices() - 1)) {
128+
if (count($returnEdges) !== (count($this->graph->getVertices()) - 1)) {
129129
throw new UnexpectedValueException('Graph is not connected');
130130
}
131131

lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Prim.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getEdges()
3535
$returnEdges = array();
3636

3737
// iterate n-1 times (per definition, resulting MST MUST have n-1 edges)
38-
for ($i = 0, $n = $this->startVertex->getGraph()->getNumberOfVertices() - 1; $i < $n; ++$i) {
38+
for ($i = 0, $n = count($this->startVertex->getGraph()->getVertices()) - 1; $i < $n; ++$i) {
3939
$markInserted[$vertexCurrent->getId()] = true;
4040

4141
// get unvisited vertex of the edge and add edges from new vertex

lib/Fhaculty/Graph/Algorithm/Property/GraphProperty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function isNull()
4646
*/
4747
public function isTrivial()
4848
{
49-
return ($this->graph->getEdges()->isEmpty() && $this->graph->getNumberOfVertices() === 1);
49+
return ($this->graph->getEdges()->isEmpty() && count($this->graph->getVertices()) === 1);
5050
}
5151
}

0 commit comments

Comments
 (0)