Changeset 49fbfb5 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:
f8bbaa0
Parents:
be9eb15
git-author:
Dzejrou <dzejrou@…> (2018-04-29 19:22:10)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
Message:

cpp: added some more functionality to rbtree_node

File:
1 edited

Legend:

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

    rbe9eb15 r49fbfb5  
    3030#define LIBCPP_INTERNAL_RBTREE_NODE
    3131
     32#include <utility>
     33
    3234namespace std::aux
    3335{
     
    9597        }
    9698
     99        bool is_right_child() const
     100        {
     101            if (parent)
     102                return parent->right == this;
     103            else
     104                return false;
     105        }
     106
    97107        void rotate_left()
    98108        {
     
    123133        }
    124134
     135        rbtree_node* successor()
     136        {
     137            if (right)
     138                return right->find_smallest();
     139            else
     140            {
     141                auto current = this;
     142                while (!current->is_left_child())
     143                    current = current->parent;
     144
     145                return current->parent;
     146            }
     147        }
     148
    125149        void add_left_child(rbtree_node* node)
    126150        {
     
    141165        }
    142166
     167        void swap(rbtree_node* other)
     168        {
     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);
     194        }
     195
     196        void unlink()
     197        {
     198            if (is_left_child())
     199                parent->left = nullptr;
     200            else if (is_right_child())
     201                parent->right = nullptr;
     202        }
     203
    143204        ~rbtree_node()
    144205        {
Note: See TracChangeset for help on using the changeset viewer.