Skip to content

Commit 7f6aef2

Browse files
committed
Add Algorithm\ShortestPath::hasVertex()
(moved from Algorithm\ShortestPath::BreadthFirst)
1 parent a092d61 commit 7f6aef2

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/ShortestPath/Base.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ public function getVerticesId()
120120
return array_keys($this->getDistanceMap());
121121
}
122122

123+
/**
124+
* checks whether there's a path from this start vertex to given end vertex
125+
*
126+
* @param Vertex $endVertex
127+
* @return boolean
128+
* @uses self::getEdgesTo()
129+
*/
130+
public function hasVertex(Vertex $vertex)
131+
{
132+
try {
133+
$this->getEdgesTo($vertex);
134+
}
135+
catch (OutOfBoundsException $e) {
136+
return false;
137+
}
138+
return true;
139+
}
140+
123141
/**
124142
* get map of vertex IDs to distance
125143
*

src/ShortestPath/BreadthFirst.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,6 @@ public function getDistanceMap()
9090
return $ret;
9191
}
9292

93-
/**
94-
* checks whether there's a path from this start vertex to given end vertex
95-
*
96-
* @param Vertex $endVertex
97-
* @return boolean
98-
* @uses self::getEdgesTo()
99-
*/
100-
public function hasVertex(Vertex $vertex)
101-
{
102-
try {
103-
$this->getEdgesTo($vertex);
104-
}
105-
catch (OutOfBoundsException $e) {
106-
return false;
107-
}
108-
return true;
109-
}
110-
11193
/**
11294
* get array of all target vertices this vertex has a path to
11395
*

0 commit comments

Comments
 (0)