DirectedGraph<T extends Object> constructor

DirectedGraph<T extends Object>(
  1. Map<T, Set<T>> edges, {
  2. Comparator<T>? comparator,
})

Constructs a directed graph.

  • edges: a map of type Map<T, Set<T>>,
  • comparator: a function with typedef Comparator<T> used to sort the graph vertices.

Implementation

DirectedGraph(
  Map<T, Set<T>> edges, {
  Comparator<T>? comparator,
}) : super(comparator) {
  edges.forEach((vertex, connectedVertices) {
    _edges[vertex] = Set<T>.of(connectedVertices);
    for (final connectedVertex in connectedVertices) {
      _edges[connectedVertex] ??= <T>{};
    }
  });
}