ms-dag-ts
v1.0.3
Published
Directed Acyclic Graph
Downloads
19
Readme
ms-dag-ts
Just a directed acyclic graph implementation.
Directed Acyclic Graph
Usage
To install, run npm install ms-dag-ts
.
Graph
new Graph()
Instantiates a new instance of graph.
addVertex(...uplinks: Vertex[]): Vertex
Adds a new
Vertex
to the graph, optionally uplinking it to the given vertices.
addEdge(top: Vertex, bottom: Vertex): Edge
Adds a new
Edge
to the graph, creating a downlink fromtop
tobottom
.
availableEdges(): ProtoEdge[]
Returns an array
ProtoEdge
objects which describe eachEdge
that could be connected without breaking the graph.
traverse(cb: TraversalCallback): void
Traverses the graph in order, calling
cb
at eachVertex
.
Vertex
new Vertex(id?: number)
Instantiates a new instance of
Vertex
, optionally assigning itid
.
id+get: number
Gets the id of this
Vertex
.
uplinks+get: Edge[]
Gets the array of
Edge
objects which describe every connection to thisVertex
.
downlinks+get: Edge[]
Gets the array of
Edge
objects which describe every connection from thisVertex
.
first+get: Vertex
Gets the first
Vertex
in the chain.
before+get: Vertex[]
Gets an array of
Vertex
objects which includes only the vertices which appear before thisVertex
in the chain.
previous+get: Vertex
Gets the
Vertex
which appears immediately before thisVertex
in the chain.
next+get: Vertex
Gets the
Vertex
which appears immmediately after thisVertex
in the chain.
after+get: Vertex
Gets an array of
Vertex
objects which include only the vertices which appear after thisVertex
in the chain.
last+get: Vertex
Gets the last
Vertex
in the chain.
remove(): Vertex
Removes this
Vertex
from the chain, stitching together the previous and next vertices and returning thisVertex
.
insertBefore(vertex: Vertex): Vertex
Inserts the given
Vertex
immediately before thisVertex
in the chain.
insertAfter(vertex: Vertex): Vertex
Insert the given
Vertex
immediately after thisVertex
in the chain.
isBefore(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertex
is before the givenVertex
in the chain.
isAfter(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertex
is after the givenVertex
in the chain.
above(): Vertex[]
Returns an array of
Vertex
objects for which thisVertex
is a direct or indirect downlink.
directlyAbove(): Vertex[]
Returns an array of
Vertex
objects for which thisVertex
is a direct downlink.
isAbove(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertex
is a direct or indirect downlink of the givenVertex
.
below(): Vertex[]
Returns an array of
Vertex
objects for which thisVertex
is a direct or indirect uplink.
directlyBelow(): Vertex[]
Returns an array of
Vertex
objects for which thisVertex
is a direct uplink.
isBelow(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertex
is a direct or indirect uplink of the givenVertex
.
connectTo(vertex: Vertex, id?: number): Edge
Connects this
Vertex
to the givenVertex
returning a new instance ofEdge
which defines the relationship and optionally assigning it the given id.
reflow(): void
Moves this
Vertex
up the chain such that it is above all of its downlinks. Callsreflow()
for each uplink.
availableConnections(): ProtoEdge[]
Returns an array of
ProtoEdge
objects which describe every possible connection which could be made without causing a cyclic flow.