giraph v1.0.5
Giraph
Immutable graph data structures

Install
npm install -S giraph
bower install -S giraphUsage
require('giraph')()
.add('a', { my: 'data' })
.add('b')
.add('c')
.connect('a', 'b', 3)
.connect('a', 'c')Docs
Giraph comes with a number of different graph types:
Undirected Graph
Exported as a factory function on the root namespace:
.([options])
Options and defaults
{
immutable: true
}require('giraph')() // => empty graphThe undirected graph has the following members
Property: .map: {}
Hashes vertices by id.
Property: .options
Instance options
Property: .length
The number of vertices
.add( id[, data] )
Returns a new instance with Vertex(id[, data]) added to it.
.get( id )
Gets the Vertex at id.
.remove( id )
Returns a new instance with id removed.
.connect( a, b, edgeWeight )
Returns a new instance with a and b connected.
.contains( String|Vertex id )
Returns a boolean indicating whether or not id is in the graph.
Note: if passing in a String, is equivalent to checking id in graph.map.
.merge( a[, b[, ...]] )
Returns a new instance with all other graphs merged into the current.
Note: merging takes Left-to-right precedence. If a and b both contain the same node, c, but have different data attached, b will take precedence.
.each( Function iterator )
Iterates through each vertex. The iterator argument has the following signature:
function( Vertex v, Number i, Graph g )Returns this
.reduce( Function iterator, Mixed initialValue )
Iterates through the graph, producing a single value. iterator has the following signature
function( Mixed currentValue, Vertex V, Number i, Graph g )Returns Value of reduction
.instance()
Returns this instance or a clone() depending on options.immutable.
.edges([id])
Returns an array of edges with the following structure:
{ vertices: ['a', 'b'], weight: 10 }Optionally, pass a vertex ID to only get edges touching that vertex.
.clone()
Returns a new instance of the graph
.weight()
Returns The total weight of all edges in the graph
.mutate(handler)
Allows mutation to occur on an immutable graph for a single turn of the event loop.
Returns the original instance
require('giraph')()
.mutate(function( g ){
// Batch operations here
g.add('a').add('b').add('c');
}).mst()
Returns a Minimum Spanning Tree represented as a Graph.
Directed Graph
TODO
Directed Acyclic Graph
TODO
Vertex
A vertex is essentially an Identifier with data attached and connections to other vertices.
It's available under .vertex( id[, data[, options]]).
.id String
ID of the vertex
.data Mixed
Optional attached data
.options Object
Optional options:
{
immutable: true
}.clone()
Returns a new instance of the vertex
TODO
- Topological Sorting
- Cliques and maximum cliques
- Planarism
- Creating sub-graphs and walks