WeightedDirectedGraph<T extends Object, W extends Comparable> constructor

WeightedDirectedGraph<T extends Object, W extends Comparable>(
  1. Map<T, Map<T, W>> edges, {
  2. required Summation<W> summation,
  3. required W zero,
  4. 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>{};
    }
  });
}