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

TreeNode#add side effect leads to inconsistency #32

Closed
MMF2 opened this issue Oct 20, 2014 · 3 comments
Closed

TreeNode#add side effect leads to inconsistency #32

MMF2 opened this issue Oct 20, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@MMF2
Copy link

MMF2 commented Oct 20, 2014

If a TreeNode n with parent p within a tree t1 is added as a child of p' within another tree t2, then n remains a child of p within t1 but inconsistently reports its parent to be p' (by calling TreeNode#parent).

I suggest to change behavior in one of the following two ways:
Change possibility 1: Adding n to p' gets a 'move' semantics, i.e. n is removed from p by adding n to p'.
Change possibility 2: Duplicate n, then add the copy to p' and leave t1 untouched.

Example:
t1 = Tree::TreeNode.new('1')
t1 << Tree::TreeNode.new('2') << Tree::TreeNode.new('4')
t1 << Tree::TreeNode.new('3') << Tree::TreeNode.new('5')
t['3'] << Tree::TreeNode.new('6')

t2 = t1.dup

t2['3'] << t1['2']['4']

t1['2']['4'].parent.name # => '3' !

@MMF2
Copy link
Author

MMF2 commented Oct 22, 2014

Sorry bug in code example:
It is
t1['3'] << Tree::TreeNode.new('6')
not
t['3'] << Tree::TreeNode.new('6')

@evolve75 evolve75 added the Bug label Oct 22, 2014
@evolve75 evolve75 added this to the 0.9.5 milestone Oct 22, 2014
@evolve75 evolve75 self-assigned this Oct 22, 2014
@evolve75
Copy link
Owner

Thanks for identifying this. Will check and update in the master branch shortly.

evolve75 added a commit that referenced this issue Jan 1, 2015
The Tree::TreeNode#add method now moves the child node from its old parent, if a
parent node exists for the child prior to adding it to the new location.
@evolve75
Copy link
Owner

evolve75 commented Jan 1, 2015

@MMF2,

The issue has been fixed in commit d3b2bf0 (release 0.9.5pre5). I will be releasing the gem this week.

@evolve75 evolve75 closed this as completed Jan 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants