Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bipartit.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getColors()
// breadth search all vertices in same component
do {
// next vertex in color
$vertex = array_shift($queue);
$vertex = \array_shift($queue);
$color = $colors[$vertex->getId()];
$nextColor = 1-$color;

Expand Down
2 changes: 1 addition & 1 deletion src/ConnectedComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function isSingle()
}
$alg = $this->createSearch($vertex);

return (count($this->graph->getVertices()) === count($alg->getVertices()));
return (\count($this->graph->getVertices()) === \count($alg->getVertices()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Degree.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function isVertexSink(Vertex $vertex)
*/
public function getDegreeVertex(Vertex $vertex)
{
return count($vertex->getEdges());
return \count($vertex->getEdges());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Groups extends BaseGraph
*/
public function getNumberOfGroups()
{
return count($this->getGroups());
return \count($this->getGroups());
}

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ public function getGroups()
$groups[$vertex->getGroup()] = true;
}

return array_keys($groups);
return \array_keys($groups);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/MaximumMatching/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class Base extends BaseGraph
*/
public function getNumberOfMatches()
{
return count($this->getEdges());
return \count($this->getEdges());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/MinimumSpanningTree/Kruskal.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getEdges()
$worseColor = $bColor;

// more vertices with color a => paint all in b in a's color
if (count($colorVertices[$bColor]) > count($colorVertices[$aColor])) {
if (\count($colorVertices[$bColor]) > \count($colorVertices[$aColor])) {
$betterColor = $bColor;
$worseColor = $aColor;
}
Expand All @@ -125,7 +125,7 @@ public function getEdges()

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

Expand Down
2 changes: 1 addition & 1 deletion src/MinimumSpanningTree/Prim.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getEdges()
$returnEdges = array();

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

// get unvisited vertex of the edge and add edges from new vertex
Expand Down
4 changes: 2 additions & 2 deletions src/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getEdgesParallelEdge(Edge $edge)
$edges = $ends->getVertexFirst()->getEdges()->getEdgesIntersection($ends->getVertexLast()->getEdges())->getVector();
}

$pos = array_search($edge, $edges, true);
$pos = \array_search($edge, $edges, true);

if ($pos === false) {
// @codeCoverageIgnoreStart
Expand All @@ -79,6 +79,6 @@ public function getEdgesParallelEdge(Edge $edge)
// exclude current edge from parallel edges
unset($edges[$pos]);

return new Edges(array_values($edges));
return new Edges(\array_values($edges));
}
}
2 changes: 1 addition & 1 deletion src/Property/GraphProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function isNull()
*/
public function isTrivial()
{
return ($this->graph->getEdges()->isEmpty() && count($this->graph->getVertices()) === 1);
return ($this->graph->getEdges()->isEmpty() && \count($this->graph->getVertices()) === 1);
}
}
14 changes: 7 additions & 7 deletions src/Property/WalkProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function hasCycle()
*/
public function isLoop()
{
return (count($this->walk->getEdges()) === 1 && $this->isCycle());
return (\count($this->walk->getEdges()) === 1 && $this->isCycle());
}

/**
Expand Down Expand Up @@ -214,11 +214,11 @@ public function hasLoop()
public function isDigon()
{
// exactly 2 edges
return (count($this->walk->getEdges()) === 2 &&
return (\count($this->walk->getEdges()) === 2 &&
// no duplicate edges
!$this->hasArrayDuplicates($this->walk->getEdges()->getVector()) &&
// exactly two distinct vertices
count($this->walk->getVertices()->getVerticesDistinct()) === 2 &&
\count($this->walk->getVertices()->getVerticesDistinct()) === 2 &&
// this is actually a cycle
$this->isCycle());
}
Expand All @@ -238,9 +238,9 @@ public function isDigon()
public function isTriangle()
{
// exactly 3 (implicitly distinct) edges
return (count($this->walk->getEdges()) === 3 &&
return (\count($this->walk->getEdges()) === 3 &&
// exactly three distinct vertices
count($this->walk->getVertices()->getVerticesDistinct()) === 3 &&
\count($this->walk->getVertices()->getVerticesDistinct()) === 3 &&
// this is actually a cycle
$this->isCycle());
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private function hasArrayDuplicates($array)
$compare = array();
foreach ($array as $element) {
// duplicate element found
if (in_array($element, $compare, true)) {
if (\in_array($element, $compare, true)) {
return true;
} else {
// add element to temporary array to check for duplicates
Expand All @@ -368,7 +368,7 @@ private function hasArrayDuplicates($array)
private function isArrayContentsEqual($a, $b)
{
foreach ($b as $one) {
$pos = array_search($one, $a, true);
$pos = \array_search($one, $a, true);
if ($pos === false) {
return false;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Search/BreadthFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getVertices($maxDepth = PHP_INT_MAX)

do {
// get first from queue
$t = array_shift($queue);
$t = \array_shift($queue);
// save as visited
$visited[$t->getId()] = $t;

Expand Down
4 changes: 2 additions & 2 deletions src/Search/DepthFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function getVertices()
{
$visited = array();
$todo = array($this->vertex);
while ($vertex = array_shift($todo)) {
while ($vertex = \array_shift($todo)) {
if (!isset($visited[$vertex->getId()])) {
$visited[$vertex->getId()] = $vertex;

foreach (array_reverse($this->getVerticesAdjacent($vertex)->getMap(), true) as $vid => $nextVertex) {
foreach (\array_reverse($this->getVerticesAdjacent($vertex)->getMap(), true) as $vid => $nextVertex) {
$todo[] = $nextVertex;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ShortestPath/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function getEdgesToInternal(Vertex $endVertex, $edges)
}
} while ($currentVertex !== $this->vertex);

return new Edges(array_reverse($path));
return new Edges(\array_reverse($path));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/ShortestPath/BreadthFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BreadthFirst extends Base
*/
public function getDistance(Vertex $endVertex)
{
return count($this->getEdgesTo($endVertex));
return \count($this->getEdgesTo($endVertex));
}

/**
Expand All @@ -56,12 +56,12 @@ public function getEdgesMap()
$vid = $vertexTarget->getId();
if (!isset($edges[$vid])) {
$vertexQueue []= $vertexTarget;
$edges[$vid] = array_merge($edgesCurrent, array($edge));
$edges[$vid] = \array_merge($edgesCurrent, array($edge));
}
}

// get next from queue
$vertexCurrent = array_shift($vertexQueue);
$vertexCurrent = \array_shift($vertexQueue);
if ($vertexCurrent) {
$edgesCurrent = $edges[$vertexCurrent->getId()];
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getDistanceMap()
{
$ret = array();
foreach ($this->getEdgesMap() as $vid => $edges) {
$ret[$vid] = count($edges);
$ret[$vid] = \count($edges);
}

return $ret;
Expand Down Expand Up @@ -121,7 +121,7 @@ public function getEdges()
$ret = array();
foreach ($this->getEdgesMap() as $edges) {
foreach ($edges as $edge) {
if (!in_array($edge, $ret, true)) {
if (!\in_array($edge, $ret, true)) {
$ret []= $edge;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ShortestPath/Dijkstra.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getEdges()
$isFirst = true;

// Repeat until all vertices have been marked
$totalCountOfVertices = count($this->vertex->getGraph()->getVertices());
$totalCountOfVertices = \count($this->vertex->getGraph()->getVertices());
for ($i = 0; $i < $totalCountOfVertices; ++$i) {
$currentVertex = NULL;
$currentVertexId = NULL;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function getEdges()
if (!isset($usedVertices[$targetVertexId])) {
// calculate new cost to vertex
$newCostsToTargetVertex = $totalCostOfCheapestPathTo[$currentVertexId] + $weight;
if (is_infinite($newCostsToTargetVertex)) {
if (\is_infinite($newCostsToTargetVertex)) {
$newCostsToTargetVertex = $weight;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ShortestPath/MooreBellmanFord.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function bigStep(Edges $edges, array &$totalCostOfCheapestPathTo, array
if (isset($totalCostOfCheapestPathTo[$fromVertex->getId()])) {
// New possible costs of this path
$newCost = $totalCostOfCheapestPathTo[$fromVertex->getId()] + $edge->getWeight();
if (is_infinite($newCost)) {
if (\is_infinite($newCost)) {
$newCost = $edge->getWeight() + 0;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ public function getEdges()
// the usal algorithm says we repeat (n-1) times.
// but because we also want to check for loop edges on the start vertex,
// we have to add an additional step:
$numSteps = count($this->vertex->getGraph()->getVertices());
$numSteps = \count($this->vertex->getGraph()->getVertices());
$edges = $this->vertex->getGraph()->getEdges();
$changed = true;

Expand Down
16 changes: 8 additions & 8 deletions src/TopologicalSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ public function getVertices()
/** @var Vertex $top */
// TODO: avoid having to reverse all vertices multiple times
// pick a node to examine next - assume there are isolated nodes
foreach (array_reverse($this->graph->getVertices()->getVector()) as $top) {
foreach (\array_reverse($this->graph->getVertices()->getVector()) as $top) {
$tid = $top->getId();
if (!isset($visited[$tid])) { // don't examine if already found
array_push($stack, $top);
\array_push($stack, $top);
}

while ($stack) {
/** @var Vertex $current */
$node = end($stack);
$node = \end($stack);
$nid = $node->getId();

$visited[$nid] = false; // temporary mark
$found = false; // new children found during visit to this node

// find the next node to visit
/** @var Vertex $child */
foreach (array_reverse($node->getVerticesEdgeTo()->getVector()) as $child) {
foreach (\array_reverse($node->getVerticesEdgeTo()->getVector()) as $child) {
$cid = $child->getId();
if (!isset($visited[$cid])) {
// found a new node - push it onto the stack
array_push($stack, $child);
\array_push($stack, $child);
$found = true; // move onto the new node
break;
} else if ($visited[$cid] === false) {
Expand All @@ -62,13 +62,13 @@ public function getVertices()
}

if (!$found) {
array_pop($stack); // no new children found - we're done with this node
\array_pop($stack); // no new children found - we're done with this node
$visited[$nid] = true; // mark as visited
array_push($output, $node); // add to results
\array_push($output, $node); // add to results
}
}
}

return new Vertices(array_reverse($output, true));
return new Vertices(\array_reverse($output, true));
}
}
6 changes: 3 additions & 3 deletions src/TravelingSalesmanProblem/Bruteforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function getGraph()
*/
public function getEdges()
{
$this->numEdges = count($this->graph->getVertices());
$this->numEdges = \count($this->graph->getVertices());
if ($this->numEdges < 3) {
throw new UnderflowException('Needs at least 3 vertices');
}
Expand Down Expand Up @@ -152,7 +152,7 @@ private function step(Vertex $vertex, $totalWeight, array $visitedVertices, arra
return NULL;
}
// kreis geschlossen am Ende
if ($vertex === $this->startVertex && count($visitedEdges) === $this->numEdges) {
if ($vertex === $this->startVertex && \count($visitedEdges) === $this->numEdges) {
// new best result
$this->bestWeight = $totalWeight;

Expand Down Expand Up @@ -180,7 +180,7 @@ private function step(Vertex $vertex, $totalWeight, array $visitedVertices, arra
$result = $this->step($target,
$totalWeight + $weight,
$visitedVertices,
array_merge($visitedEdges, array($edge))
\array_merge($visitedEdges, array($edge))
);

// new result found
Expand Down
2 changes: 1 addition & 1 deletion src/TravelingSalesmanProblem/NearestNeighbor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getEdges()
{
$returnEdges = array();

$n = count($this->vertex->getGraph()->getVertices());
$n = \count($this->vertex->getGraph()->getVertices());

$vertex = $this->vertex;
$visitedVertices = array($vertex->getId() => true);
Expand Down
Loading