removeEdges method

void removeEdges(
  1. Vertex<T> vertex,
  2. [List<Vertex<T>> connectedVertices]
)

Removes edges (connections) pointing from vertex to connectedVertices. If connectedVertices is not specified all outgoing edges are removed from the graph.

Implementation

void removeEdges(Vertex<T> vertex, [List<Vertex<T>> connectedVertices]) {
  // Handle default case: Remove all outgoing edges if
  // connectedVertices is not specified.
  if (connectedVertices == null) {
    // Update inDegreeMap.
    for (final connectedVertex in _edges[vertex] ?? []) {
      _inDegreeMap[connectedVertex] -= 1;
    }
    _edges.remove(vertex);
  } else {
    if (_edges[vertex] == null) return;
    for (final connectedVertex in connectedVertices) {
      // Check if connectedVertex is indeed connected to vertex.
      if (_edges[vertex].remove(connectedVertex)) {
        _inDegreeMap[connectedVertex] -= 1;
      }
    }
    // Remove entry if vertex has no outgoing edges.
    if (_edges[vertex].isEmpty) {
      _edges.remove(vertex);
    }
  }
  _updateLazyFields();
}