Skip to content

Commit 99150ed

Browse files
committed
readme: document topological sort
1 parent 5675528 commit 99150ed

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
# Xi Algorithm
22

3+
A collection of miscellaneous algorithms.
4+
35
## Luhn
46

57
Usage:
68

7-
```
9+
```php
810
use Xi\Algorithm\Luhn;
911

1012
$luhn = new Luhn();
1113
$luhn->generate(123); // 1230
1214
```
1315

16+
## Topological sort
17+
18+
Sorts the nodes of an acyclic graph so that if node X points to node Y then Y appears before X in the list. [Read more.](http://en.wikipedia.org/wiki/Topological_sorting)
19+
20+
Basically, it's useful for resolving a dependency graph.
21+
22+
Usage:
23+
24+
```php
25+
// A description of a graph:
26+
$edges = array(
27+
'B' => array('C', 'D'), // Node B points to nodes C and D
28+
'A' => array('B'), // Node A points to node B
29+
'C' => array('D'), // Node C points to node D
30+
);
31+
32+
$nodesSorted = \Xi\Algorithm\TopologicalSort::apply($edges);
33+
// $nodesSorted is now array('D', 'C', 'B', 'A')
34+
```
35+
36+
1437
## Running the tests
1538

1639
No dependencies to other libraries exist, but in order to generate an autoloader

0 commit comments

Comments
 (0)