graphology-dag
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -0,1 +1,2 @@ | ||
export {default as hasCycle} from './has-cycle'; | ||
export {default as willCreateCycle} from './will-create-cycle'; |
@@ -0,1 +1,2 @@ | ||
exports.hasCycle = require('./has-cycle.js'); | ||
exports.willCreateCycle = require('./will-create-cycle.js'); |
{ | ||
"name": "graphology-dag", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Directed acyclic graph functions for graphology.", | ||
"main": "index.js", | ||
"files": [ | ||
"has-cycle.js", | ||
"index.js", | ||
@@ -8,0 +9,0 @@ "will-create-cycle.js", |
@@ -13,4 +13,30 @@ # Graphology DAG | ||
- [hasCycle](#hascycle) | ||
- [willCreateCycle](#willcreatecycle) | ||
### hasCycle | ||
Function returning whether the given directed graph contains at least one cycle. | ||
Note that this function will also work with a disconnected graph. | ||
```js | ||
import {hasCycle} from 'graphology-dag'; | ||
// Alternatively, to load only the relevant code: | ||
import hasCycle from 'graphology-dag/has-cycle'; | ||
const graph = new DirectedGraph(); | ||
graph.mergeEdge(0, 1); | ||
graph.mergeEdge(1, 2); | ||
graph.mergeEdge(2, 3); | ||
hasCycle(graph); | ||
>>> false | ||
graph.mergeEdge(3, 0); | ||
hasCycle(graph); | ||
>>> true | ||
``` | ||
### willCreateCycle | ||
@@ -22,2 +48,4 @@ | ||
Note finally that this function will also work with DAG forests (sets of disconnected DAGs living in the same graph instance). | ||
```js | ||
@@ -24,0 +52,0 @@ import {willCreateCycle} from 'graphology-dag'; |
7695
9
113
64