Attention needed from Alan Donovan
Austin Clements has uploaded the change for review![Open in Gerrit]()
Austin Clements would like Alan Donovan to review this change.
Commit message
cmd/digraph: implement graph.Graph interface
Change-Id: I2050c2cebd6ea0c9d6412e5219ea690bf7234cb9
Change diff
diff --git a/cmd/digraph/digraph.go b/cmd/digraph/digraph.go
index 3f9c767..1086fc5 100644
--- a/cmd/digraph/digraph.go
+++ b/cmd/digraph/digraph.go
@@ -17,12 +17,18 @@
"flag"
"fmt"
"io"
+ "maps"
"os"
+ "slices"
"sort"
"strconv"
"strings"
"unicode"
"unicode/utf8"
+
+ "iter"
+
+ "golang.org/x/tools/internal/graph"
)
func usage() {
@@ -89,6 +95,17 @@
// A digraph maps nodes to the non-nil set of their immediate successors.
type digraph map[string]nodeset
+func (g digraph) All() iter.Seq[string] {
+ return slices.Values(slices.Sorted(maps.Keys(g)))
+}
+
+func (g digraph) Out(node string) iter.Seq2[int, string] {
+ // Out must be deterministic.
+ return slices.All(slices.Sorted(maps.Keys(g[node])))
+}
+
+var _ graph.Graph[string] = digraph{}
+
func (g digraph) addNode(node string) nodeset {
edges := g[node]
if edges == nil {
@@ -107,11 +124,7 @@
}
func (g digraph) nodelist() nodelist {
- nodes := make(nodeset)
- for node := range g {
- nodes[node] = true
- }
- return nodes.sort()
+ return nodelist(slices.Collect(g.All()))
}
func (g digraph) reachableFrom(roots nodeset) nodeset {
Change information
Change size: S
Delta: 1 file changed, 18 insertions(+), 5 deletions(-)
Open in GerritRelated details
Attention is currently required from:
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I2050c2cebd6ea0c9d6412e5219ea690bf7234cb9
Gerrit-Change-Number: 747363
Gerrit-PatchSet: 1