Debian Codegraph @

internal/graph/scc.go

raw symbols SCIP
1 // Copyright 2026 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/
6
7 import "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/"
8
9 // SCCs computes the strongly connected components of the graph g.
10 func SCCsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/SCCs().[NodeID comparable](g Graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Graph#[NodeID]) [][]NodeID {
11 // Use Kosaraju's algorithm. Tarjan is overkill here.
12
13 // Forward pass
14 S := Postorderscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Postorder().(g)
15
16 // Reverse pass
17 gt := Transposescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Transpose().(g)
18 seen := make(map[NodeID]bool)
19 var scc []NodeID
20 var sccs [][]NodeID
21 var rvisit func(NodeID)
22 rvisit = func(u NodeID) {
23 if !seen[u] {
24 seen[u] = true
25 scc = append(scc, u)
26 for v := range gt.Outscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Graph#Out.(u) {
27 rvisit(v)
28 }
29 }
30 }
31 for _, root := range slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Backwardscip-go gomod github.com/golang/go/src go1.25.0 slices/Backward().(S) {
32 if !seen[root] {
33 scc = nil
34 rvisit(root)
35 sccs = append(sccs, scc)
36 }
37 }
38 return sccs
39 }