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

<xtree> : Is this determine statement redundant? #1913

Closed
Kamichanw opened this issue May 6, 2021 · 1 comment · Fixed by #4749
Closed

<xtree> : Is this determine statement redundant? #1913

Kamichanw opened this issue May 6, 2021 · 1 comment · Fixed by #4749
Labels
enhancement Something can be improved fixed Something works now, yay!

Comments

@Kamichanw
Copy link

template <class _Moveit>
_Nodeptr _Copy_nodes(_Nodeptr _Rootnode, _Nodeptr _Wherenode, _Moveit _Movefl) {
    // copy entire subtree, recursively
    const auto _Scary = _Get_scary();
    _Nodeptr _Newroot = _Scary->_Myhead; // point at nil node

    if (!_Rootnode->_Isnil) { // copy or move a node, then any subtrees
        bool_constant<is_same_v<key_type, value_type>> _Is_set;
        _Nodeptr _Pnode = _Copy_or_move(_Rootnode->_Myval, _Movefl, _Is_set);
        _Pnode->_Parent = _Wherenode;
        _Pnode->_Color  = _Rootnode->_Color;
        if (_Newroot->_Isnil) {
            _Newroot = _Pnode; // memorize new root
        }

        _TRY_BEGIN
        _Pnode->_Left  = _Copy_nodes(_Rootnode->_Left, _Pnode, _Movefl);
        _Pnode->_Right = _Copy_nodes(_Rootnode->_Right, _Pnode, _Movefl);
        _CATCH_ALL
        _Scary->_Erase_tree_and_orphan(_Getal(), _Newroot); // subtree copy failed, bail out
        _RERAISE;
        _CATCH_END
    }

    return _Newroot; // return newly constructed tree
}

In function _Copy_nodes which is applied to copy a tree, _Newroot->_Isnil is always true, but here:

if (_Newroot->_Isnil) {
            _Newroot = _Pnode; // memorize new root
}

why still determine if it is nil?

@Kamichanw Kamichanw added the question Further information is requested label May 6, 2021
@StephanTLavavej
Copy link
Member

We'll need to look into this and get back to you with an answer - thanks for bringing this to our attention.

@StephanTLavavej StephanTLavavej added the decision needed We need to choose something before working on this label Aug 30, 2022
@StephanTLavavej StephanTLavavej removed the decision needed We need to choose something before working on this label May 17, 2023
@StephanTLavavej StephanTLavavej added enhancement Something can be improved fixed Something works now, yay! and removed question Further information is requested labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants