Graph
An immutable, directed, optionally-weighted graph over nodes carrying a payload of type T, with edges carrying an optional weight of type W. Iterating a Graph (it implements Iterable) yields its edges.
Being immutable, every structural change (see plus/minus) returns a new Graph rather than mutating the receiver; use toMutable (or build directly via MutableGraph.build) when many changes need to be applied in a row, then MutableGraph.toImmutable the result back. Construct a Graph via Graph.build, Graph.of, or the various node/edge-adding operators on a MutableGraph:
val g = Graph.build<String, Int> {
this += edgeOf(nodeOf("a"), nodeOf("b"), 1)
connect(nodeOf("a"), nodeOf("c"), weight = 2, bidirectional = true)
}Type Parameters
is the type of the payload carried by this graph's nodes
is the type of this graph's edge weights
Inheritors
Properties
The number of edges in this graph.
Whether this graph contains no directed cycles, checked by repeatedly stripping away leaf nodes (nodes with no outgoing edges) from a working copy until either no nodes are left (the original graph is acyclic) or no leaf remains despite nodes still being present (there is a cycle among them). This makes a mutable copy of the whole graph and is therefore O(nodes + edges), not free to call repeatedly on a large graph.
Functions
Traverses this graph starting from initialNode, according to searchStrategy, as an Iterable of Visits (one per traversed node); each traversal of the returned Iterable restarts from scratch.
Same as asIterable, but as a lazy Sequence of Visits.
Same as Sequence.assertItemsAreNotNull, starting from an Iterable rather than a Sequence.
Same as List.permutations, starting from an Iterable rather than a List.
Returns a new Graph, with edge added to it (implicitly adding its endpoints, if missing). Note: as currently implemented, any other outgoing edge that edge.source already had in this graph is discarded in the result, rather than kept alongside edge (unlike MutableGraph.add, which merges the new edge in without discarding existing ones).
Same as Sequence.subsequences, but starting from an Iterable.
Returns a MutableGraph copy of this graph, which can be modified in place.