| 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 ( |
| 8 | "iterscip-go gomod github.com/golang/go/src go1.25.0 iter/" |
| 9 | "mapsscip-go gomod github.com/golang/go/src go1.25.0 maps/" |
| 10 | "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/" |
| 11 | ) |
| 12 | |
| 13 | // testGraph is a simple adjacency list implementation of [CompactGraph] for testing. |
| 14 | type testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph# struct { |
| 15 | nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#nodes. int |
| 16 | edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#edges. map[int][]int |
| 17 | } |
| 18 | |
| 19 | // newTestGraph builds a testGraph from an adjacency list represented as a map. |
| 20 | func newTestGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/newTestGraph().(n int, adj map[int][]int) *testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph# { |
| 21 | return &testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#{ |
| 22 | nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#nodes.: int(n), |
| 23 | edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#edges.: adj, |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func (g *testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#) Nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#Nodes().() iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[int] { |
| 28 | return func(yield func(int) bool) { |
| 29 | for i := range g.nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#nodes. { |
| 30 | if !yield(i) { |
| 31 | break |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func (g *testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#) NumNodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#NumNodes().() int { |
| 38 | return g.nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#nodes. |
| 39 | } |
| 40 | |
| 41 | func (g *testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#) Outscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#Out().(u int) iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[int] { |
| 42 | return slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Valuesscip-go gomod github.com/golang/go/src go1.25.0 slices/Values().(g.edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#edges.[u]) |
| 43 | } |
| 44 | |
| 45 | func (g *testGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#) IsCompactscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/testGraph#IsCompact().() {} |
| 46 | |
| 47 | // stringGraph implements Graph[string]. |
| 48 | type stringGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph# map[string][]string |
| 49 | |
| 50 | func (g stringGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#) Nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#Nodes().() iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[string] { |
| 51 | return mapsscip-go gomod github.com/golang/go/src go1.25.0 maps/.Keysscip-go gomod github.com/golang/go/src go1.25.0 maps/Keys().(g) |
| 52 | } |
| 53 | |
| 54 | func (g stringGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#) NumNodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#NumNodes().() int { |
| 55 | return len(g) |
| 56 | } |
| 57 | |
| 58 | func (g stringGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#) Outscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/stringGraph#Out().(node string) iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[string] { |
| 59 | return func(yield func(string) bool) { |
| 60 | for _, succ := range g[node] { |
| 61 | if !yield(succ) { |
| 62 | return |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |