Skip to content

Commit

Permalink
Merge pull request #172 from clue-labs/docs
Browse files Browse the repository at this point in the history
Minor documentation updates
  • Loading branch information
clue authored Oct 1, 2019
2 parents b744a33 + 290ed9f commit 9bf3cf9
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 37 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

GraPHP is the mathematical graph/network library written in PHP.

**Table of contents**

* [Quickstart examples](#quickstart-examples)
* [Features](#features)
* [Components](#components)
* [Graph drawing](#graph-drawing)
* [Common algorithms](#common-algorithms)
* [Install](#install)
* [Tests](#tests)
* [Contributing](#contributing)
* [License](#license)

## Quickstart examples

Once [installed](#install), let's initialize a sample graph:

````php
```php
<?php
require_once 'vendor/autoload.php';

use \Fhaculty\Graph\Graph as Graph;

require_once 'vendor/autoload.php';

$graph = new Graph();

// create some cities
Expand All @@ -24,15 +37,16 @@ $cologne->createEdgeTo($madrid);
$madrid->createEdgeTo($rome);
// create loop
$rome->createEdgeTo($rome);
````
```

Let's see which city (Vertex) has a road (i.e. an edge pointing) to Rome:

Let's see which city (Vertex) has road (i.e. an edge pointing) to Rome
````php
```php
foreach ($rome->getVerticesEdgeFrom() as $vertex) {
echo $vertex->getId().' leads to rome'.PHP_EOL;
// result: Madrid and Rome itself
}
````
```

## Features

Expand Down
6 changes: 3 additions & 3 deletions src/Edge/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract public function getVerticesStart();
* return true if this edge is an outgoing edge of the given vertex (i.e. the given vertex is a valid start vertex of this edge)
*
* @param Vertex $startVertex
* @return boolean
* @return bool
* @uses Vertex::getVertexToFrom()
*/
abstract public function hasVertexStart(Vertex $startVertex);
Expand All @@ -68,7 +68,7 @@ abstract public function hasVertexStart(Vertex $startVertex);
* return true if this edge is an ingoing edge of the given vertex (i . e. the given vertex is a valid end vertex of this edge)
*
* @param Vertex $targetVertex
* @return boolean
* @return bool
* @uses Vertex::getVertexFromTo()
*/
abstract function hasVertexTarget(Vertex $targetVertex);
Expand All @@ -78,7 +78,7 @@ abstract public function isConnection(Vertex $from, Vertex $to);
/**
* returns whether this edge is actually a loop
*
* @return boolean
* @return bool
*/
abstract public function isLoop();

Expand Down
12 changes: 6 additions & 6 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getEdges()
* create a new Vertex in the Graph
*
* @param int|NULL $id new vertex ID to use (defaults to NULL: use next free numeric ID)
* @param boolean $returnDuplicate normal operation is to throw an exception if given id already exists. pass true to return original vertex instead
* @param bool $returnDuplicate normal operation is to throw an exception if given id already exists. pass true to return original vertex instead
* @return Vertex (chainable)
* @throws InvalidArgumentException if given vertex $id is invalid
* @throws OverflowException if given vertex $id already exists and $returnDuplicate is not set
Expand Down Expand Up @@ -308,7 +308,7 @@ public function getVertex($id)
* checks whether given vertex ID exists in this graph
*
* @param int|string $id identifier of Vertex
* @return boolean
* @return bool
*/
public function hasVertex($id)
{
Expand All @@ -320,7 +320,7 @@ public function hasVertex($id)
*
* @param Vertex $vertex instance of the new Vertex
* @return void
* @private
* @internal
* @see self::createVertex() instead!
*/
public function addVertex(Vertex $vertex)
Expand All @@ -336,7 +336,7 @@ public function addVertex(Vertex $vertex)
*
* @param Edge $edge instance of the new Edge
* @return void
* @private
* @internal
* @see Vertex::createEdge() instead!
*/
public function addEdge(Edge $edge)
Expand All @@ -350,7 +350,7 @@ public function addEdge(Edge $edge)
* @param Edge $edge
* @return void
* @throws InvalidArgumentException if given edge does not exist (should not ever happen)
* @private
* @internal
* @see Edge::destroy() instead!
*/
public function removeEdge(Edge $edge)
Expand All @@ -369,7 +369,7 @@ public function removeEdge(Edge $edge)
* @param Vertex $vertex
* @return void
* @throws InvalidArgumentException if given vertex does not exist (should not ever happen)
* @private
* @internal
* @see Vertex::destroy() instead!
*/
public function removeVertex(Vertex $vertex)
Expand Down
2 changes: 1 addition & 1 deletion src/Set/DualAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Fhaculty\Graph\Set;

/**
* DualAggregate provides access to both its Vertices and its Edges
* A DualAggregate provides access to both its Vertices and its Edges
*
* This is the simple base interface for any Graph-like structure / data type
* which contains a Set of Edges and a Set of Vertices, such as the Graph class
Expand Down
10 changes: 5 additions & 5 deletions src/Set/Edges.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function getEdgeMatch($callbackCheck)
* checks whethere there's an Edge that matches the given callback filter function
*
* @param callable $callbackCheck
* @return boolean
* @return bool
* @see self::getEdgeMatch() to return the Edge instance that matches the given callback filter function
* @uses self::getEdgeMatchOrNull()
*/
Expand All @@ -209,7 +209,7 @@ public function hasEdgeMatch($callbackCheck)
/**
* get a new set of Edges that match the given callback filter function
*
* This only keeps Edge elements if the $callbackCheck returns a boolean
* This only keeps Edge elements if the $callbackCheck returns a bool
* true and filters out everything else.
*
* Edge index positions will be left unchanged.
Expand All @@ -229,7 +229,7 @@ public function getEdgesMatch($callbackCheck)
* Edge index positions will be left unchanged.
*
* @param int $orderBy criterium to sort by. see self::ORDER_WEIGHT, etc.
* @param boolean $desc whether to return biggest first (true) instead of smallest first (default:false)
* @param bool $desc whether to return biggest first (true) instead of smallest first (default:false)
* @return Edges a new Edges set ordered by the given $orderBy criterium
* @throws InvalidArgumentException if criterium is unknown
*/
Expand Down Expand Up @@ -273,7 +273,7 @@ public function getEdgesOrder($orderBy, $desc = false)
* get first edge ordered by given criterium $orderBy
*
* @param int $orderBy criterium to sort by. see self::ORDER_WEIGHT, etc.
* @param boolean $desc whether to return biggest (true) instead of smallest (default:false)
* @param bool $desc whether to return biggest (true) instead of smallest (default:false)
* @return Edge
* @throws InvalidArgumentException if criterium is unknown
* @throws UnderflowException if no edges exist
Expand Down Expand Up @@ -394,7 +394,7 @@ public function count()
* A Set if empty if no single Edge instance is added. This is faster
* than calling `count() === 0`.
*
* @return boolean
* @return bool
*/
public function isEmpty()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Set/EdgesAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Fhaculty\Graph\Set;

/**
* Basic interface for every class that provides access to its Set of Edges
* A basic interface for every class that provides access to its Set of Edges
*/
interface EdgesAggregate
{
Expand Down
14 changes: 7 additions & 7 deletions src/Set/Vertices.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getVertexId($id)
* checks whether given vertex ID exists in this set of vertices
*
* @param int|string $id identifier of Vertex
* @return boolean
* @return bool
* @uses self::hasVertexMatch()
*/
public function hasVertexId($id)
Expand Down Expand Up @@ -199,7 +199,7 @@ public function getVertexMatch($callbackCheck)
* checks whether there's a Vertex that matches the given callback filter function
*
* @param callable $callbackCheck
* @return boolean
* @return bool
* @see self::getVertexMatch() to return the Vertex instance that matches the given callback filter function
* @uses self::getVertexMatchOrNull()
*/
Expand All @@ -211,7 +211,7 @@ public function hasVertexMatch($callbackCheck)
/**
* get a new set of Vertices that match the given callback filter function
*
* This only keeps Vertex elements if the $callbackCheck returns a boolean
* This only keeps Vertex elements if the $callbackCheck returns a bool
* true and filters out everything else.
*
* Vertex index positions will be left unchanged, so if you call this method
Expand All @@ -233,7 +233,7 @@ public function getVerticesMatch($callbackCheck)
* on a VerticesMap, it will also return a VerticesMap.
*
* @param int $orderBy criterium to sort by. see Vertex::ORDER_ID, etc.
* @param boolean $desc whether to return biggest first (true) instead of smallest first (default:false)
* @param bool $desc whether to return biggest first (true) instead of smallest first (default:false)
* @return Vertices a new Vertices set ordered by the given $orderBy criterium
* @throws InvalidArgumentException if criterium is unknown
* @see self::getVertexOrder()
Expand Down Expand Up @@ -311,7 +311,7 @@ public function getVerticesIntersection($otherVertices)
* get first vertex (optionally ordered by given criterium $by) from given array of vertices
*
* @param int $orderBy criterium to sort by. see Vertex::ORDER_ID, etc.
* @param boolean $desc whether to return biggest (true) instead of smallest (default:false)
* @param bool $desc whether to return biggest (true) instead of smallest (default:false)
* @return Vertex
* @throws InvalidArgumentException if criterium is unknown
* @throws UnderflowException if no vertices exist
Expand Down Expand Up @@ -422,7 +422,7 @@ public function count()
* A Set if empty if no single Vertex instance is added. This is faster
* than calling `count() === 0`.
*
* @return boolean
* @return bool
*/
public function isEmpty()
{
Expand All @@ -432,7 +432,7 @@ public function isEmpty()
/**
* check whether this set contains any duplicate vertex instances
*
* @return boolean
* @return bool
* @uses self::getMap()
*/
public function hasDuplicates()
Expand Down
8 changes: 4 additions & 4 deletions src/Vertex.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function createEdge(Vertex $vertex)
*
* @param Edge $edge
* @return void
* @private
* @internal
* @see self::createEdge() instead!
*/
public function addEdge(Edge $edge)
Expand All @@ -171,7 +171,7 @@ public function addEdge(Edge $edge)
* @param Edge $edge
* @return void
* @throws InvalidArgumentException if given edge does not exist
* @private
* @internal
* @see Edge::destroy() instead!
*/
public function removeEdge(Edge $edge)
Expand All @@ -187,7 +187,7 @@ public function removeEdge(Edge $edge)
* check whether this vertex has a direct edge to given $vertex
*
* @param Vertex $vertex
* @return boolean
* @return bool
* @uses Edge::hasVertexTarget()
*/
public function hasEdgeTo(Vertex $vertex)
Expand All @@ -203,7 +203,7 @@ public function hasEdgeTo(Vertex $vertex)
* check whether the given vertex has a direct edge to THIS vertex
*
* @param Vertex $vertex
* @return boolean
* @return bool
* @uses Vertex::hasEdgeTo()
*/
public function hasEdgeFrom(Vertex $vertex)
Expand Down
8 changes: 4 additions & 4 deletions src/Walk.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function factoryFromEdges($edges, Vertex $startVertex)
*
* @param Vertices|Vertex[] $vertices
* @param int|null $by
* @param boolean $desc
* @param bool $desc
* @return Walk
* @throws UnderflowException if no vertices were given
* @see Edges::getEdgeOrder() for parameters $by and $desc
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function factoryFromVertices($vertices, $by = null, $desc = false)
* @param Vertex[] $predecessors map of vid => predecessor vertex instance
* @param Vertex $vertex start vertex to search predecessors from
* @param int|null $by
* @param boolean $desc
* @param bool $desc
* @return Walk
* @throws UnderflowException
* @see Edges::getEdgeOrder() for parameters $by and $desc
Expand Down Expand Up @@ -130,7 +130,7 @@ public static function factoryCycleFromPredecessorMap(array $predecessors, Verte
*
* @param Vertex[]|Vertices $vertices
* @param int|null $by
* @param boolean $desc
* @param bool $desc
* @return Walk
* @throws UnderflowException if no vertices were given
* @see Edges::getEdgeOrder() for parameters $by and $desc
Expand Down Expand Up @@ -283,7 +283,7 @@ public function getAlternatingSequence()
/**
* check to make sure this walk is still valid (i.e. source graph still contains all vertices and edges)
*
* @return boolean
* @return bool
* @uses Walk::getGraph()
* @uses Graph::getVertices()
* @uses Graph::getEdges()
Expand Down

0 comments on commit 9bf3cf9

Please sign in to comment.