MutableGraph
A mutable variant of Graph: add/remove (and their operator aliases plusAssign/minusAssign) change this instance in place, unlike the copy-on-write Graph.plus/Graph.minus. This is the type to reach for when building up a graph incrementally, or when applying many changes in a row without paying the cost of a defensive copy for each of them (as Graph.plus/Graph.minus would); see Graph.build and MutableGraph.build to construct one via a builder block:
val g = MutableGraph.build<String, Int> {
this += nodeOf("a")
connect(nodeOf("a"), nodeOf("b"), weight = 1, 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
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
Adds edge to this graph, in place (implicitly adding its endpoints, if missing), merging it with any other outgoing edge edge.source already has (unlike the immutable Graph.plus, which currently discards them).
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.
Returns an independent, mutable copy of this graph (further changes to either do not affect the other).
Operator alias for remove(edge).
Operator alias for remove(node).
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).
Operator alias for add(edge).
Operator alias for add(node).
Same as Sequence.subsequences, but starting from an Iterable.
Returns an immutable Graph snapshot of this graph's current content.
Returns a MutableGraph copy of this graph, which can be modified in place.