getOrphanNodes method

List<Node<T>> getOrphanNodes()

Gets all nodes that have no connections.

Returns a list of nodes that are neither sources nor targets of any connections. Useful for identifying isolated or unused nodes in the graph.

Returns a list of orphan nodes (may be empty).

Example:

final orphans = controller.getOrphanNodes();
print('Found ${orphans.length} orphan nodes');

Implementation

List<Node<T>> getOrphanNodes() {
  final connectedNodeIds = <String>{};
  for (final connection in _connections) {
    connectedNodeIds.add(connection.sourceNodeId);
    connectedNodeIds.add(connection.targetNodeId);
  }
  return _nodes.values
      .where((node) => !connectedNodeIds.contains(node.id))
      .toList();
}