T
is the node type of the graph. Nodes can be anything in all the included examples they are simple objects.
Caches if the graph contains a cycle. If undefined
then it is unknown.
Add a directed edge to the graph.
The identity string of the node the edge should run from.
The identity string of the node the edge should run to.
This boolean indicates if the cache of the cyclicality of the graph should be updated.
If false
is passed the cached will be invalidated because we can not assure that a cycle has not been created.
Depth first search to see if one node is reachable from another following the directed edges.
Caveat: This will return false if startNode
and endNode
are the same node and the is not a cycle or a loop edge connecting them.
The string identity of the node to start at.
The string identity of the node we are attempting to reach.
Returns a specific node given the node identity returned from the insert
function
This simply returns all the nodes stored in the graph
An optional function that indicates the sort order of the returned array
Given a starting node this returns a new DirectedGraph
containing all the nodes that can be reached.
Throws a NodeDoesntExistError
if the start node does not exist.
The string identity of the node from which the subgraph search should start.
The indegree of a node is the number of edges that point to it. This will always be an integer.
Throws a NodeDoesntExistError
the node does not exist.
The string of the node identity of the node to calculate indegree for.
Add a node to the graph if it doesn't already exist. If it does, throw a NodeAlreadyExistsError
.
The node to be added
A string
that is the identity of the newly inserted node. This is created by applying the nodeIdentity
.
Returns true
if there are no cycles in the graph.
This relies on a cached value so calling it multiple times without adding edges to the graph should be O(1) after the first call.
Non-cached calls are potentially expensive, the implementation is based on Kahn's algorithim which is O(|EdgeCount| + |NodeCount|).
This replaces an existing node in the graph with an updated version.
Throws a [[NodeDoesNotExistsError
]] if no node with the same identity already exists.
__Caveat_:_ The default identity function means that this will never work since if the node changes it will have a different hash
.
The new node that is replacing the old one.
The node to insert or update
The identity string of the node inserted or updated.
Checks if adding the specified edge would create a cycle.
Returns true in O(1) if the graph already contains a known cycle, or if fromNodeIdentity
and toNodeIdentity
are the same.
The string identity of the node the edge is from.
The string identity of the node the edge is to.
Generated using TypeDoc
DirectedGraph
A DirectedGraph is similar a
Graph
but with additional functionality.