Iterate over all the vertices connected to context
vertex
Returns true if a->b or b->a
Iterates over vertices from a starting vertex in an bread-first-search
Clones the graph. Uses shallow clone, because it's all immutable
Connect from -> to. Same as connectWithEdges, but this version just returns the graph.
Make a connection between two vertices with a given weight. It returns the new graph as wll as the created edge.
Connect from -> to. Same as connect except you get back the edges as well.
Create a vertex with given id
Iterates over vertices from a starting vertex in an depth-first-search
Returns a mutation of graph
, with a given edge removed.
Returns the weight of an edge, or 1 if undefined.
Default distance computer. Uses weight
property of edge, or 1
if not found.
Return a string representation of the graph for debug inspection
Iterate over all the edges in the graph
Returns Vertex under key
, or undefined
if not found.
Get all the cycles ('strongly-connected-components') within the graph Read more
Gets a vertex by id, creating it if it does not exist.
Gets a vertex by id, throwing an error if it does not exist
Create a graph
Create a graph from an iterable of vertices
Returns true if graph contains key
.
Returns true if vertex
has no outgoing connections
Returns true if vertex
only has the given list of vertices.
Returns false early if the length of the list does not match up with vertex.out
Returns true if vertex
has an outgoing connection to the given vertex.
Returns true if the graph contains is acyclic - that is, it has no loops
Compute shortest distance from the source vertex to the rest of the graph.
Returns the graph connections as an adjacency matrix
Topological sort using Kahn's algorithm. Returns a new graph that is sorted
Returns a new graph which is transitively reduced. That is, redundant edges are removed
Updates a vertex by returning a mutated graph
Returns true if vertex
has an outgoing connection to
the supplied id or vertex.
Iterate over all the vertices of the graph
Options for connecting vertices
Directed graph. Immutable.
Edge. Immutable.
Vertex. These are the nodes of the graph. Immutable.
Directed graphs
Graph vertices (ie. nodes) connect to each other along edges. This is 'directed' in that connections are not necessarily mutual. A can connect to B without B connecting to A.
Connections can have an optional weight, defaulting to 1.
Example: Creating a directed graph A connects to B and C; B connects to C. C has edges.
Graphs do not store data directly, only the relation between vertices. Each vertex has an id, so to associate data, use a map along with the graph.