-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve private/buf/dag #2240
Improve private/buf/dag #2240
Conversation
@@ -195,6 +241,34 @@ func (g *Graph[Key]) DOTString(keyToString func(Key) string) (string, error) { | |||
); err != nil { | |||
return "", err | |||
} | |||
// We also want to pick up any nodes that do not have edges, and display them. | |||
if err := g.WalkNodes( | |||
func(key Key, inboundEdges []Key, outboundEdges []Key) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func(key Key, inboundEdges []Key, outboundEdges []Key) error { | |
func(key Key, inboundEdges, outboundEdges []Key) error { |
// We also want to pick up any nodes that do not have edges, and display them. | ||
if err := g.WalkNodes( | ||
func(key Key, inboundEdges []Key, outboundEdges []Key) error { | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// |
@@ -180,9 +180,9 @@ func TestWalk2(t *testing.T) { | |||
) | |||
} | |||
|
|||
func TestWalk3(t *testing.T) { | |||
func TestWalkEdges3(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: test names should be more descriptive instead of Test<Num>
// f is called for each directed edge. The first argument is the source | ||
// node, the second is the destination node. | ||
// | ||
// Returns a *CycleError if there is a cycle in the graph. | ||
func (g *Graph[Key]) Walk(f func(Key, Key) error) error { | ||
func (g *Graph[Key]) WalkEdges(f func(Key, Key) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be in the func signature instead of the doc
// f is called for each directed edge. The first argument is the source | |
// node, the second is the destination node. | |
// | |
// Returns a *CycleError if there is a cycle in the graph. | |
func (g *Graph[Key]) Walk(f func(Key, Key) error) error { | |
func (g *Graph[Key]) WalkEdges(f func(Key, Key) error) error { | |
// f is called for each directed edge. | |
// | |
// Returns a *CycleError if there is a cycle in the graph. | |
func (g *Graph[Key]) WalkEdges(f func(sourceNode Key, destinationNode Key) error) error { |
NumNodes
to return the number of nodes.NumEdges
to return the number of edges.Walk
toWalkEdges
WalkEdges
incorrectly returned an error when there were only nodes in the graph with no edges.WalkNodes
that walks the nodes. This allows access to nodes with no edges.DOTString
to print nodes without edges.