addEdge method
void
addEdge(
- T vertex,
- T connectedVertex,
- W weight
Adds a new weighted edge pointing from vertex
to connectedVertex
.
If the edge (vertex, connectedVertex
) exists,
the edge weight
is updated.
Implementation
void addEdge(T vertex, T connectedVertex, W weight) {
if (_edges.containsKey(vertex)) {
_edges[vertex]![connectedVertex] = weight;
} else {
_edges[vertex] = {connectedVertex: weight};
}
// Add any new vertices to the graph:
_edges[connectedVertex] ??= <T, W>{};
}