unionAll<V, E> static method
void
unionAll<V, E>(})
Merges others
into result
. edgeMerge
specifies how parallel edges
are merged, if unspecified the last one is used.
Implementation
static void unionAll<V, E>(Graph<V, E> result, Iterable<Graph<V, E>> others,
{E Function(V source, V target, E a, E b)? edgeMerge}) {
for (final graph in others) {
// Create all vertices present in any graph.
for (final vertex in graph.vertices) {
result.addVertex(vertex);
}
// Create all edges present in any graph.
for (final vertex in graph.vertices) {
for (final edge in graph.outgoingEdgesOf(vertex)) {
final existing = result.getEdge(edge.source, edge.target);
final value = existing == null || edgeMerge == null
? edge.value
: edgeMerge(edge.source, edge.target, existing.value, edge.value);
result.addEdge(edge.source, edge.target, value: value);
}
}
}
}