Directed acyclic graph.

see Wikipedia.

Constructor Summary

Public Constructors
public
DAG( )

Directed acyclic graph.

Property Summary

Public Properties
public final

Array of all known vertex names.

public final

Hash of vertices keyed by name.

Method Summary

Public Methods
public
add(name): Object | Undefined

Adds a new vertex to the graph.

public
addEdge(fromName, toName)

Adds an edge between two vertices.

public
addEdges(name, value, before, after)

Assigns value to the vertex named name and creates the edges defined by before and after.

public
map(name, value)

Assigns value to the vertex named name.

public
topsort(fn)

Traverses the graph depth-first.

Public Constructors

lib/utilities/DAG.js:27

public DAG( )

Public Properties

lib/utilities/DAG.js:36

public final names: Array

Array of all known vertex names.

lib/utilities/DAG.js:45

public final vertices: Object

Hash of vertices keyed by name.

Public Methods

lib/utilities/DAG.js:55

public add(name): Object | Undefined

Adds a new vertex to the graph.

Parameters:

Name Type Attribute Description
name String

Name of the vertex

Return:

Object | Undefined

The new vertex or the already existing vertex with the same name

lib/utilities/DAG.js:93

public addEdge(fromName, toName)

Adds an edge between two vertices.

Parameters:

Name Type Attribute Description
fromName Object

Name of the from vertex

toName Object

Name of the to vertex

Throws:

lib/utilities/DAG.js:142

public addEdges(name, value, before, after)

Assigns value to the vertex named name and creates the edges defined by before and after.

Parameters:

Name Type Attribute Description
name String

Name of the vertex

value Any

Value of the vertex

before String | Array

Adds edges from name to each of before

after String | Array

Adds edges from each of after to name

lib/utilities/DAG.js:80

public map(name, value)

Assigns value to the vertex named name.

Creates a new vertex if a vertex named name does not exist yet.

Parameters:

Name Type Attribute Description
name String

Name of the vertex

value Any

Value of the vertex

lib/utilities/DAG.js:120

public topsort(fn)

Traverses the graph depth-first.

Each vertex will only be visited once even if it has multiple parent vertices.

Parameters:

Name Type Attribute Description
fn Function

Function that is called with each vertex and the path to it