// 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)varfunc( 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(, ) } } } } }}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.