// AddEdge add en edge between FromNode and ToNode.
// make sure both FromNode and ToNode are already inside the graph.
// NOTE: for a undirected graph, this func will add both from-to and to-from into the graph.
// Invoker should make sure the edge is not in the graph before call this func.
AddEdge add en edge between FromNode and ToNode.
make sure both FromNode and ToNode are already inside the graph.
NOTE: for a undirected graph, this func will add both from-to and to-from into the graph.
Invoker should make sure the edge is not in the graph before call this func.
// AddEdge add en edge between FromNode and ToNode . // make sure both FromNode and ToNode are already inside the graph . // NOTE : for a undirected graph this func will add both from - to and to - from into the graph . // Invoker should make sure the edge is not in the graph before call this func .
func (g adjacencyListGraph) AddEdge(from, to NodeID) error {
	if !g.IsNodeValid(from) || !g.IsNodeValid(to) {
		return fmt.Errorf("From node %v or To node %v invalid", from, to)
	}
	g.adjList[from] = append(g.adjList[from], to)
	if !g.directed {
		g.adjList[to] = append(g.adjList[to], from)
	}
	return nil
}
func ( g adjacencyListGraph ) AddEdge ( from , to NodeID ) error { if ! g . IsNodeValid ( from ) || ! g . IsNodeValid ( to ) { return fmt . Errorf ( " " , from , to ) } g . adjList [ from ] = append ( g . adjList [ from ] , to ) if ! g . directed { g . adjList [ to ] = append ( g . adjList [ to ] , from ) } return nil }
AddEdge add en edge between FromNode and ToNode.
AddEdge add en edge between FromNode and ToNode .
// for undirected graph, add both from-to and to-from into the graph