OpenMediaVault  0.6 (Kralizec)
The open network attached storage solution
 All Classes Functions Variables Groups Pages
Public Member Functions | List of all members
OMVToplogicalSort Class Reference

Public Member Functions

 clean ()
 
 add ($node, $deps=array())
 
 sort ($ignoreMissing=TRUE)
 

Detailed Description

Sorts a series of dependencies in linear order (topological sort).

$tsort = new OMVToplogicalSort;
$tsort->add("node1", array());
$tsort->add("node2", "node1");
$tsort->add("node4", array("node2"));
$tsort->add("node5", array("node4", "node3"));
print_r($tsort->sort(TRUE));
The result will be:
Array
(
[0] => node1
[1] => node2
[2] => node4
[3] => node5
)

Member Function Documentation

OMVToplogicalSort::add (   $node,
  $deps = array() 
)

Add a node and its dependencies.

Parameters
nodeThe node.
depsThe node dependencies. This can be an array or string. Defaults to an empty array.
Returns
TRUE if successful, otherwise FALSE.
OMVToplogicalSort::clean ( )

Cleanup the internal structures.

OMVToplogicalSort::sort (   $ignoreMissing = TRUE)
Parameters
ignoreMissingIgnore dependency nodes that do not exist. Defaults to TRUE.
Returns
Returns the sorted nodes based on the given dependencies, otherwise FALSE if the dependencies can not be solved.

The documentation for this class was generated from the following file: