Skip to content

Commit 61f085e

Browse files
committed
Add abstract BaseGraph, BaseSet and BaseVertex algorithm base classes
1 parent 9f19839 commit 61f085e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

src/BaseGraph.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Fhaculty\Graph\Algorithm;
4+
5+
use Fhaculty\Graph\Algorithm\Base;
6+
use Fhaculty\Graph\Graph;
7+
8+
/**
9+
* Abstract base class for algorithms that operate on a given Graph instance
10+
*/
11+
abstract class BaseGraph extends Base
12+
{
13+
/**
14+
* Graph to operate on
15+
*
16+
* @var Graph
17+
*/
18+
protected $graph;
19+
20+
/**
21+
* instantiate new algorithm
22+
*
23+
* @param Graph $graph Graph to operate on
24+
*/
25+
public function __construct(Graph $graph)
26+
{
27+
$this->graph = $graph;
28+
}
29+
}

src/BaseSet.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Fhaculty\Graph\Algorithm;
4+
5+
use Fhaculty\Graph\Algorithm\Base;
6+
use Fhaculty\Graph\Set;
7+
use Fhaculty\Graph\Graph;
8+
use Fhaculty\Graph\Walk;
9+
10+
/**
11+
* Abstract base class for algorithms that operate on a given Set instance
12+
*
13+
* @see Set
14+
*/
15+
abstract class BaseSet extends Base
16+
{
17+
/**
18+
* Set to operate on
19+
*
20+
* @var Set
21+
*/
22+
protected $set;
23+
24+
/**
25+
* instantiate new algorithm
26+
*
27+
* @param Graph|Walk|Set $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
28+
*/
29+
public function __construct(Set $graphOrWalk)
30+
{
31+
$this->set = $graphOrWalk;
32+
}
33+
}

src/BaseVertex.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Fhaculty\Graph\Algorithm;
4+
5+
use Fhaculty\Graph\Algorithm\Base;
6+
use Fhaculty\Graph\Vertex;
7+
8+
/**
9+
* Abstract base class for algorithms that operate on a given Vertex instance
10+
*/
11+
abstract class BaseVertex extends Base
12+
{
13+
/**
14+
* Vertex to operate on
15+
*
16+
* @var Vertex
17+
*/
18+
protected $vertex;
19+
20+
/**
21+
* instantiate new algorithm
22+
*
23+
* @param Vertex $vertex Vertex to operate on
24+
*/
25+
public function __construct(Vertex $vertex)
26+
{
27+
$this->vertex = $vertex;
28+
}
29+
}

0 commit comments

Comments
 (0)