Skip to content
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

Merged
merged 1 commit into from
Jan 31, 2021

Conversation

migueleliasweb
Copy link
Contributor

No description provided.

@migueleliasweb
Copy link
Contributor Author

Fixes: #9

Copy link

@elliotchance elliotchance left a 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over debugging code?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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)

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.

Copy link
Contributor Author

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 👍.

@xlab
Copy link
Owner

xlab commented Jan 30, 2021

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? :)

@migueleliasweb
Copy link
Contributor Author

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! 🤟

@migueleliasweb
Copy link
Contributor Author

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 VisitAll. Could you have a look again, @elliotchance ?

@xlab xlab merged commit 50b6107 into xlab:master Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants