directed-graph
Advanced tools
+2
-2
| { | ||
| "name": "directed-graph", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "node package for weighted directed graphs", | ||
| "main": "src", | ||
| "main": "src/graph.js", | ||
| "scripts": { | ||
@@ -7,0 +7,0 @@ "test": "mocha test" |
+39
-3
@@ -1,10 +0,46 @@ | ||
| graph.js | ||
| ======== | ||
| directed-graph | ||
| ============== | ||
| node package for weighted directed graphs | ||
| ###Installation | ||
| ###Running Tests | ||
| `npm install directed-graph --save` | ||
| ##Quickstart | ||
| ```javascript | ||
| var Graph = require('directed-graph'); | ||
| // Either initialize and fill an empty graph | ||
| var graphA = new Graph(); | ||
| graphA.addVertex('A'); | ||
| graphA.addVertex('B'); | ||
| graphA.addVertex('C'); | ||
| graphA.addEdge('A', 'B'); | ||
| graphA.addEdge('A', 'C'); | ||
| graphA.addEdge('B', 'A'); | ||
| graphA.addEdge('B', 'C'); | ||
| graphA.addEdge('C', 'A'); | ||
| graphA.addEdge('C', 'B'); | ||
| // Or predefine a new graph | ||
| var graphB = new Graph({ | ||
| 'A': ['B', 'C'], | ||
| 'B': ['A', 'C'], | ||
| 'C': ['A', 'B'], | ||
| }); | ||
| // Both graphA and graphB function the same | ||
| graphA.setWeight('A', 'B', 10); | ||
| graphA.setWeight('B', 'A', 10); | ||
| graphA.addVertex('D'); | ||
| graphA.addEdge('A', 'D'); | ||
| console.log(graphA.pathExists('B', 'D')); | ||
| ``` | ||
| ##Running Tests | ||
| Make sure to have mocha installed: `npm install -g mocha` | ||
| In project root directory, run: `mocha test` |
6182
13.97%47
327.27%