HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/go-1.22/src/internal/dag/alg.go
// 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 (g *Graph) Transpose() {
	old := g.edges

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

	for from, tos := range old {
		for to := range tos {
			g.edges[to][from] = true
		}
	}
}

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

	var visit func(n string)
	visit = func(n string) {
		if marks[n] {
			return
		}
		for _, to := range g.Edges(n) {
			visit(to)
		}
		marks[n] = true
		topo = append(topo, n)
	}
	for _, root := range g.Nodes {
		visit(root)
	}
	for i, j := 0, len(topo)-1; i < j; i, j = i+1, j-1 {
		topo[i], topo[j] = topo[j], topo[i]
	}
	return topo
}

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