// Transpose generate a new transposed graph from current graph.
// NOTE: only directed graph can have transpose graph, since it's only reverse all edges.
Transpose generate a new transposed graph from current graph.
NOTE: only directed graph can have transpose graph, since it's only reverse all edges.
// Transpose generate a new transposed graph from current graph . // NOTE : only directed graph can have transpose graph since it ' s only reverse all edges .
func Transpose(g Graph, newGraphFunc func(int, bool) Graph) (Graph, error) {
	if !g.Directed() {
		return nil, fmt.Errorf("input graph is not a directed graph")
	}
	newGraph := newGraphFunc(g.NodeCount(), g.Directed())
	g.IterateAllNodes(func(u NodeID) {
		g.IterateAdjacencyNodes(u, func(v NodeID) {
			newGraph.AddEdge(v, u)
		})
	})
	return newGraph, nil
}
func Transpose ( g Graph , newGraphFunc func ( int , bool ) Graph ) ( Graph , error ) { if ! g . Directed ( ) { return nil , fmt . Errorf ( " " ) } newGraph := newGraphFunc ( g . NodeCount ( ) , g . Directed ( ) ) g . IterateAllNodes ( func ( u NodeID ) { g . IterateAdjacencyNodes ( u , func ( v NodeID ) { newGraph . AddEdge ( v , u ) } ) } ) return newGraph , nil }
Transpose generate a new transposed graph from current graph.
Transpose generate a new transposed graph from current graph .
// means u->v exist in current graph