Changeset cacb5d0 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:22Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
647b756
Parents:
af0fbaac
git-author:
Dzejrou <dzejrou@…> (2018-04-30 19:48:15)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
Message:

cpp: added more node operations, changed swap to value swap instead of link swap which was buggy and probably slower when move semantics are in the play

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/rbtree_node.hpp

    raf0fbaac rcacb5d0  
    124124        }
    125125
     126        const rbtree_node* find_smallest() const
     127        {
     128            auto res = this;
     129            while (res->left)
     130                res = res->left;
     131
     132            return res;
     133        }
     134
    126135        rbtree_node* find_largest()
    127136        {
     
    133142        }
    134143
    135         rbtree_node* successor()
     144        const rbtree_node* find_largest() const
     145        {
     146            auto res = this;
     147            while (res->right)
     148                res = res->right;
     149
     150            return res;
     151        }
     152
     153        rbtree_node* successor() const
    136154        {
    137155            if (right)
     
    167185        void swap(rbtree_node* other)
    168186        {
    169             /**
    170              * Parent can be null so we check both ways.
    171              */
    172             if (is_left_child())
    173                 parent->left = other;
    174             else if (is_right_child())
    175                 parent->right = other;
    176 
    177             if (other->is_left_child())
    178                 other->parent->left = this;
    179             else if (other->is_right_child())
    180                 other->parent->right = this;
    181 
    182             if (left)
    183                 left->parent = other;
    184             if (right)
    185                 right->parent = other;
    186             if (other->left)
    187                 other->left->parent = this;
    188             if (other->right)
    189                 other->right->parent = this;
    190 
    191             std::swap(parent, other->parent);
    192             std::swap(left, other->left);
    193             std::swap(right, other->right);
     187            std::swap(value, other->value);
    194188        }
    195189
Note: See TracChangeset for help on using the changeset viewer.