-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add visit all capability #16
Conversation
Fixes: #9 |
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 is not my repo so I won't require changes.
treeprint.go
Outdated
@@ -159,6 +169,24 @@ func (n *node) SetMetaValue(meta MetaValue) { | |||
n.Meta = meta | |||
} | |||
|
|||
func (n *node) VisitAll(fn NodeVisitor) { | |||
for _, node := range n.Nodes { | |||
// if len(node.Nodes) == 0 { |
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.
Left over debugging code?
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.
Well, not really. My idea here was to give an example on how to determine if the item you're iterating is a branch or a node. Should I take the comments out and add them as normal text in the docs?
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.
Scratch all that. I was looking at the wrong place. Yeah it was just me testing. 🤦 . Removed it.
|
||
// VisitAll iterates over the tree, branches and nodes. | ||
// If need to iterate over the whole tree, use the root node. | ||
VisitAll(fn NodeVisitor) |
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.
Might be nice to mention here that this is a depth-first walk.
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.
I was never the good regarding algorithm names but since the code is iterating over all items in the current branch first to them head to the next branch, wouldn't this be breadth first? Btw, yeah it could be worth adding that info to the docs, you're right 👍.
Hi! Thanks for providing both PRs. I've merged the first one, as it was very lightweight. This one I guess has reasonable comments from @elliotchance , would you mind adding those changes? :) |
I will have a go I'm a few hours! 🤟 |
04da6b4
to
bd3fae5
Compare
I just rebased this branch so it's nice and easy to merge, removed the debugging code and added a comment regarding the approach taken for the |
No description provided.