Skip to content

Commit df4d3e0

Browse files
committed
Move Set::hasLoop() to new Algorithm\Loop
1 parent d79fd27 commit df4d3e0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Loop.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Fhaculty\Graph\Algorithm;
4+
5+
use Fhaculty\Graph\Algorithm\BaseSet;
6+
use Fhaculty\Graph\Edge\Base as Edge;
7+
use Fhaculty\Graph\Vertex;
8+
9+
/**
10+
* Basic algorithms for working with loop edges
11+
*
12+
* A loop (also called a self-loop or a "buckle") is an edge that connects a
13+
* Vertex to itself. A simple graph contains no loops.
14+
*
15+
* @link http://en.wikipedia.org/wiki/Loop_%28graph_theory%29
16+
*/
17+
class Loop extends BaseSet
18+
{
19+
/**
20+
* checks whether this graph has any loops (edges from vertex to itself)
21+
*
22+
* @return boolean
23+
* @uses Edge::isLoop()
24+
*/
25+
public function hasLoop()
26+
{
27+
foreach ($this->set->getEdges() as $edge) {
28+
if ($edge->isLoop()) {
29+
return true;
30+
}
31+
}
32+
33+
return false;
34+
}
35+
}

0 commit comments

Comments
 (0)