addEdge method
void
addEdge(
- E edge
Implementation
void addEdge(E edge) {
// Ensure the nodes exist in the graph
if (!nodes.containsKey(edge.from.id) || !nodes.containsKey(edge.to.id)) {
throw ArgumentError(
'Both nodes of the edge must already exist in the graph.');
}
// Add the edge
edges.putIfAbsent(edge.from.id, () => {});
assert(
!edges[edge.from.id]!.containsKey(edge.to.id),
'An edge from ${edge.from.id} to ${edge.to.id} already exists.',
);
edges[edge.from.id]![edge.to.id] = edge;
assert(
edges[edge.from.id]!.containsKey(edge.to.id),
'The edge from ${edge.from.id} to ${edge.to.id} was not added.',
);
}