class SS_DAG implements IteratorAggregate (View source)

A Directed Acyclic Graph - used for doing topological sorts on dependencies, such as the before/after conditions in config yaml fragments

Properties

protected array|null $data

The nodes/vertices in the graph. Should be a numeric sequence of items (no string keys, no gaps).

protected array $dag

The edges in the graph, in $to_idx => [$from_idx1, $from_idx2, ...] format

Methods

public
__construct($data = null)

No description

public
additem($item)

Add another node/vertex

public
addedge($from, $to)

Add an edge from one vertex to another.

public
array
sort()

Sort graph so that each node (a) comes before any nodes (b) where an edge exists from a to b

public
getIterator()

No description

Details

__construct($data = null)

No description

Parameters

$data

additem($item)

Add another node/vertex

Parameters

$item

anything - The item to add to the graph

addedge($from, $to)

Add an edge from one vertex to another.

When passing actual nodes (as opposed to indexes), uses array_search with strict = true to find

Parameters

$from

integer|any The index in $data of the node/vertex, or the node/vertex itself, that the edge goes from

$to

integer|any - The index in $data of the node/vertex, or the node/vertex itself, that the edge goes to

array sort()

Sort graph so that each node (a) comes before any nodes (b) where an edge exists from a to b

Return Value

array
  • The nodes

Exceptions

Exception

getIterator()

No description