removeNode method

bool removeNode(
  1. String id
)

Removes a node and all incident edges.

Returns true when the node existed.

Implementation

bool removeNode(String id) {
  requireNonEmpty(id, 'id');

  final TaeraeNode? node = _nodes.remove(id);
  if (node == null) {
    return false;
  }

  _removeNodeIndexes(node);

  final Set<String> incidentEdgeIds = <String>{};
  final Set<String>? outgoing = _outgoingEdgeIdsByNode.remove(id);
  if (outgoing != null) {
    incidentEdgeIds.addAll(outgoing);
  }

  final Set<String>? incoming = _incomingEdgeIdsByNode.remove(id);
  if (incoming != null) {
    incidentEdgeIds.addAll(incoming);
  }

  for (final String edgeId in incidentEdgeIds) {
    _removeEdgeInternal(edgeId);
  }

  return true;
}