generic-digraph

a generic directed graph implementation

Usage no npm install needed!

<script type="module">
  import genericDigraph from 'https://cdn.skypack.dev/generic-digraph';
</script>

README

SYNOPSIS

NPM Package Build Status Coverage Status

js-standard-style

This is a generic directional graph implementation. It makes use of ES6 iterators for graph traversal.

USAGE

const Digraph = require('generic-digraph')

// to start with the graph is just a single vertex
var vertex = new Digraph()

// now lets add an edge named 'friend' to the vertex with the value 'alice'
vertex.set('friend', 'alice')

vertex.set(['friend', 'brother'], 'bob')
// now the graph looks like:
// [vertex]---friend--->[alice]---brother-->[bob]

//path names and vertex values can be anything
vertex.set([new Buffer('friend'), 5, true, {}, new Date()], Array())

// edges are stored in a Map
vertex.edges // Map{}

// to get an array of all of the vertices
var vertices = [...vertex]

// you can also iterate a path
vertices = [...vertex.iteratePath(['friend', 'brother'])]

// getting a vertex works like setting
var friendsBotherVertex = vertex.set(['friend', 'brother'])
friendsBotherVertex.getValue() // "bob"

// delete an edge
vertex.del('friend')
// now the vertex is empty
vertex.isEmpty()

More Examples
./examples/

API

./docs/

Notes on iterate

when decsending the graph, accumulate!
when asecending the graph, aggergate!

do you wish to not decsend futher?
then using continue, do consider

accumlate, continue, aggergate, repeat
accumlate, continue, aggergate, repeat

EXTENDING

This was module was built so that it could be easly extended.

LICENSE

MPL-2.0