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

Comments

Projects
None yet
2 participants
@MMF2

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

This comment has been minimized.

Show comment
Hide comment
@MMF2

MMF2 Oct 22, 2014

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

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

This comment has been minimized.

Show comment
Hide comment
@evolve75

evolve75 Oct 22, 2014

Owner

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

Owner

evolve75 commented Oct 22, 2014

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

evolve75 added a commit that referenced this issue Jan 1, 2015

Fixed Issue #32 by adding 'move' semantics to TreeNode#add.
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

This comment has been minimized.

Show comment
Hide comment
@evolve75

evolve75 Jan 1, 2015

Owner

@MMF2,

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

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 Jan 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment