addEdges method

void addEdges(
  1. Vertex<T> vertex,
  2. List<Vertex<T>> connectedVertices
)

Adds edges (connections) pointing from vertex to connectedVertices. If the graph does not contain vertex it will be added.

Implementation

void addEdges(Vertex<T> vertex, List<Vertex<T>> connectedVertices) {
  // Check if vertex exists.
  if (_edges[vertex] == null) {
    _edges[vertex] = connectedVertices;
  } else {
    _edges[vertex].addAll(connectedVertices);
  }
  // Update inDegreeMap
  for (final connectedVertex in connectedVertices) {
    _inDegreeMap[connectedVertex] = (_inDegreeMap[connectedVertex] == null)
        ? 1
        : _inDegreeMap[connectedVertex] + 1;
  }
  // Check if [vertex] is new to the graph.
  if (_inDegreeMap[vertex] == null) {
    _inDegreeMap[vertex] = 0;
  }
  // Update lazy fields
  _updateLazyFields();
}