removeEdge method

Graph removeEdge(
  1. Edge edge
)

Removes the given edge from the graph. If the graph is undirected, the method also removes the opponent edge.

Implementation

Graph removeEdge(Edge edge ) {
	// delete the edge from the node's edge list
	final edges = _edges[edge.from];

	if ( edges != null ) {
		final index = edges.indexOf( edge );
		edges.removeAt( index );

		// if the graph is not directed, delete the edge connecting the node in the opposite direction
		if ( digraph == false ) {
			final edges = _edges[edge.to];

			for ( int i = 0, l = (edges?.length ?? 0); i < l; i ++ ) {
				final e = edges![ i ];

				if ( e.to == edge.from ) {
					final index = edges.indexOf( e );
					edges.removeAt( index );
					break;
				}
			}
		}
	}

	return this;
}