WeightedDirectedGraph<T extends Object, W extends Comparable> constructor
WeightedDirectedGraph<T extends Object, W extends Comparable> (
- Map<
T, Map< edges, {T, W> > - required Summation<
W> summation, - required W zero,
- Comparator<
T> ? comparator,
Constructs a weighted directed graph with vertices of type T
and associates to each graph edge a weight of type W
.
edges
: The weighted edges of the graph. An empty map may be used to create an empty graph.- zero: The weight of an empty path. It represents the additive
identity of the type
W
. - summation: The function used to sum edge weights.
- Note:
W
must extend Comparable.
Implementation
WeightedDirectedGraph(
Map<T, Map<T, W>> edges, {
required this.summation,
required this.zero,
Comparator<T>? comparator,
}) : super(comparator) {
edges.forEach((vertex, connectedVerticeWeights) {
_edges[vertex] = Map.of(connectedVerticeWeights);
for (final connectedVertex in connectedVerticeWeights.keys) {
_edges[connectedVertex] ??= <T, W>{};
}
});
}