-
Notifications
You must be signed in to change notification settings - Fork 91
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
Unique node names #24
Comments
+1 |
2 similar comments
+1 |
+1 |
+1 |
2 similar comments
+1 |
+1 |
The current code was too restrictive about duplicate nodes in the tree, whereas the implementation requires only sibling node names to be unique. Note that the uniqueness is defined (currently) by the node name.
Thanks for highlighting this issue. Mea culpa. I had myself put in the comment about the possibility of code already using duplicates. I have pushed out a fix with a test case (0.9.3pre, f7f6377) into the
This check does need to be configurable though, as there might be scenarios (ref #9) where a truly unique node set is required in the tree. Any ideas appreciated. I was thinking about a
While it should be possible to implement the comparison within the tree's context (i.e., taking into account the parent node, parentage/edges, etc.), it might make the system too restrictive (similar to what happened here). The Any thoughts on the above? |
@evolve75 Thanks for jumping on this so quickly. I'm not convinced it does need to be configurable. PR #9 did not actually claim to have a use case for globally unique node names, he just said he was making the behavior consistent with the documentation. In fact, I posit that configurable behavior is incorrect: the node names should not be globally unique. A node in a tree is defined by the combination of its name and its position in the tree: ie, its "path". "root->one->deep" simply has nothing to do with "root->two->deep" despite the same leaf node name.
And there is no scenario in which comparing an entire node that is not in a tree to a node that already is in a tree makes sense. Before a node has been added to the tree, it is not "equal" to a node in the tree that happens to have the same name. "root->one->deep" is not equal to "root->two->deep" OR to "someothertree->deep" OR to "deep". And finally, I would say that having For example, say you have the tree we're talking about:
And you call |
Thanks for the detailed feedback. I have released the For the Also, this will necessarily have a particular traversal mechanism imposed on the sort, and we will also need to traverse the tree (at least for the edges and parentage involved for the two nodes) to address arbitrary node compares. Any thoughts? |
I just fired up my old code which is using siblings with same name, is there any way to reenable this again? So "root->one" is not the same as "root->one->one" Could we get this "feature" back? |
I have released R0.9.3 which fixes this issue. The node names are no longer required to be globally unique. They will need to be unique between siblings though. Please update to the latest version and let me know if the behavior is as expected. The new release takes care of the issue globally unique node names. I am working out the comparison operator logic for the nodes ( |
Pull request #9 changed the behavior of node name uniqueness, and this went out in release 0.9.3.
In the discussion on that pull request (#9 (comment)), it was pointed out "there is existing code which is using duplicate node names already, and this fix will break that code", which is true and broke my code which was using version 0.8.3.
From what I can tell, the reasoning behind the fix was twofold:
I propose that a tree that looks like this should be perfectly valid:
The fact that there are two nodes with the name "deep" in this tree is irrelevant. They are not the same node, they just happen to have the same name.
Conceptually, when you retrieve nodes out of the tree, you do it like so:
If we expected all node names to be unique and used as a key within the entire tree, then we would expect this to work:
But it doesn't, and it shouldn't.
It's worth noting that a node's name is used as an implicit id in two ways:
@children_hash
, which implies that the name is unique only among its siblings#<=>
, which would then sort all the nodes in the tree by their name alone, which seems wrongRather than fundamentally changing the behavior of the tree to match the documentation, I think the following changes should be made:
Tree::TreeNode#<=>
so that the comparison is not based only on the node's name, but on a combination of the node's parent (or parentage array, if you prefer) and the node's nameThoughts?
The text was updated successfully, but these errors were encountered: