2.0.2 • Published 8 years ago

functional-dag v2.0.2

Weekly downloads
1
License
MPL-2.0
Repository
github
Last release
8 years ago

DEPRICATED - GO HERE https://github.com/wanderer/functional-trie

NPM Package Build Status Coverage Status

js-standard-style

This is a Functional Directed Acyclic Graph implementation. generic-digraph is the imperative version.

USAGE

const Vertex = require('functional-dag')

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

// now lets add an edge to the vertex named "bob" that points to another vertex with the value "alice"
vertex = vertex.set('friend', 'alice')

// if paths have more than one name in them they can arrays
vertex = vertex.set(['friend', 'brother'], 'bob')
// now the graph looks like:
// [vertex]---friend--->[alice]---brother-->[bob]

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

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

//you can iterate the graph to get all of its vertices
var vertices = [...vertex]

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

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

API

This has about same API as generic-digraph. With the execption that any operation that changes state returns a new copy with the changes instead of applying them directly. This affects all Set and Delete functions.

batch (operations)

The batch functions should be more effeciant then single operations for functional DAGs
params

  • operations {array} - an array of operation to apply to the graph. Each entry should be in the form of op, path, argument. Where op can be set, del or setValue.

example

var graph = new Vertex()
const pathA = ['a', 'b']
const pathB = ['a^', 'b^']
const commonVertex = new Vertex('common')
const batch = [
  ['set', pathA, commonVertex],
  ['set', pathB, commonVertex]
]

graph = graph.batch(batch)
// the graph should now be
//  ,->o.
// o     o
//  `->o'

LICENSE

MPL-2.0