// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dag

// Transpose reverses all edges in g.
func ( *Graph) () {
	 := .edges

	.edges = make(map[string]map[string]bool)
	for ,  := range .Nodes {
		.edges[] = make(map[string]bool)
	}

	for ,  := range  {
		for  := range  {
			.edges[][] = true
		}
	}
}

// Topo returns a topological sort of g. This function is deterministic.
func ( *Graph) () []string {
	 := make([]string, 0, len(.Nodes))
	 := make(map[string]bool)

	var  func( string)
	 = func( string) {
		if [] {
			return
		}
		for ,  := range .Edges() {
			()
		}
		[] = true
		 = append(, )
	}
	for ,  := range .Nodes {
		()
	}
	for ,  := 0, len()-1;  < ; ,  = +1, -1 {
		[], [] = [], []
	}
	return 
}

// TransitiveReduction removes edges from g that are transitively
// reachable. g must be transitively closed.
func ( *Graph) () {
	// For i -> j -> k, if i -> k exists, delete it.
	for ,  := range .Nodes {
		for ,  := range .Nodes {
			if .HasEdge(, ) {
				for ,  := range .Nodes {
					if .HasEdge(, ) {
						.DelEdge(, )
					}
				}
			}
		}
	}
}