Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eknkc/tsort
node.js topological sort utility
https://github.com/eknkc/tsort
Last synced: 9 days ago
JSON representation
node.js topological sort utility
- Host: GitHub
- URL: https://github.com/eknkc/tsort
- Owner: eknkc
- Created: 2013-02-28T14:24:13.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-28T17:59:54.000Z (almost 12 years ago)
- Last Synced: 2024-12-17T01:34:17.388Z (17 days ago)
- Homepage:
- Size: 99.6 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tsort - node.js topological sort utility
npm install tsort
## usage
```js
var tsort = require('tsort');// create an empty graph
var graph = tsort();// add nodes
graph.add('a', 'b');
graph.add('b', 'c');
graph.add('0', 'a');// outputs: [ '0', 'a', 'b', 'c' ]
console.dir(graph.sort());// can add more than one node
graph.add('1', '2', '3', 'a');
// outputs: [ '0', '1', '2', '3', 'a', 'b', 'c' ]
console.dir(graph.sort());// can add in array form
graph.add(['1', '1.5']);
graph.add(['1.5', 'a']);
// outputs: [ '0', '1', '2', '3', '1.5', 'a', 'b', 'c' ]
console.dir(graph.sort());// detects cycles
graph.add('first', 'second');
graph.add('second', 'third', 'first');
// throws: Error: There is a cycle in the graph. It is not possible to derive a topological sort.
graph.sort();
```#license
MIT