Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A graph data-structure
JavaScript
tag: 0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
.npmignore
License
Makefile
Readme.md
component.json
index.js
package.json

Readme.md

topograph

Stores a graph of nodes and provides topological sorting. Basically just an OO API for toposort so you can build your graph incrementally.

Installation

With packin or component

$ packin add jkroso/graph

then in your app:

var graph = require('graph')

API

Graph()

Graph class

Graph.addNode(node)

add node if not already in the graph

Graph.addEdge(from, to)

add two nodes with a relationship

Graph.addRelationship(from, to)

add a relationship between two existing nodes

Graph.toArray()

convert to a topologically sorted array

Graph.clone()

clone this Graph

Example

new Graph(['c', 'a', 'd', 'b'])
  .addRelationship('a', 'b')
  .addRelationship('b', 'c')
  .addRelationship('c', 'd')
  .toArray() // => ['a', 'b', 'c', 'd']

Running the tests

Just run make and navigate your browser to the test directory.

Something went wrong with that request. Please try again.