5#ifndef DCPP_MAP_HPP_INCLUDED 
    6#define DCPP_MAP_HPP_INCLUDED 
    8#include <duckcpp/core/engine/dcpp_types.hpp> 
    9#include <duckcpp/core/engine/irrMath.hpp> 
   17template <
class KeyType, 
class ValueType>
 
   21    template <
class KeyTypeRB, 
class ValueTypeRB>
 
   27            : LeftChild(0), RightChild(0), Parent(0), Key(
k),
 
   28                Value(v), IsRed(
true) {}
 
   30        void setLeftChild(RBTree* 
p)
 
   37        void setRightChild(RBTree* 
p)
 
   44        void setParent(RBTree* 
p) { Parent=
p; }
 
   48        void setRed() { IsRed = 
true; }
 
   49        void setBlack() { IsRed = 
false; }
 
   51        RBTree* getLeftChild()
 const { 
return LeftChild; }
 
   52        RBTree* getRightChild()
 const { 
return RightChild; }
 
   53        RBTree* getParent()
 const { 
return Parent; }
 
   75        bool isLeftChild()
 const 
   77            return (Parent != 0) && (Parent->getLeftChild()==
this);
 
   80        bool isRightChild()
 const 
   82            return (Parent!=0) && (Parent->getRightChild()==
this);
 
   87            return (LeftChild==0) && (RightChild==0);
 
   90        unsigned int getLevel()
 const 
   95                return getParent()->getLevel() + 1;
 
  156        Node* getNode()
 const 
  178            DCPP_DEBUG_BREAK_IF(atEnd()) 
 
  187            while(
n && 
n->getLeftChild())
 
  188                n = 
n->getLeftChild();
 
  194            while(
n && 
n->getRightChild())
 
  195                n = 
n->getRightChild();
 
  205            if (Cur->getRightChild())
 
  209                Cur = getMin(Cur->getRightChild());
 
  211            else if (Cur->isLeftChild())
 
  215                Cur = Cur->getParent();
 
  224                while(Cur->isRightChild())
 
  225                    Cur = Cur->getParent();
 
  226                Cur = Cur->getParent();
 
  236            if (Cur->getLeftChild())
 
  240                Cur = getMax(Cur->getLeftChild());
 
  242            else if (Cur->isRightChild())
 
  246                Cur = Cur->getParent();
 
  256                while(Cur->isLeftChild())
 
  257                    Cur = Cur->getParent();
 
  258                Cur = Cur->getParent();
 
 
  296        const Node* getNode()
 const 
  311        const Node* operator->()
 
  316        const Node& operator*()
 
  318            DCPP_DEBUG_BREAK_IF(atEnd()) 
 
  327            while(
n && 
n->getLeftChild())
 
  328                n = 
n->getLeftChild();
 
  334            while(
n && 
n->getRightChild())
 
  335                n = 
n->getRightChild();
 
  345            if (Cur->getRightChild())
 
  349                Cur = getMin(Cur->getRightChild());
 
  351            else if (Cur->isLeftChild())
 
  355                Cur = Cur->getParent();
 
  364                while(Cur->isRightChild())
 
  365                    Cur = Cur->getParent();
 
  366                Cur = Cur->getParent();
 
  376            if (Cur->getLeftChild())
 
  380                Cur = getMax(Cur->getLeftChild());
 
  382            else if (Cur->isRightChild())
 
  386                Cur = Cur->getParent();
 
  396                while(Cur->isLeftChild())
 
  397                    Cur = Cur->getParent();
 
  398                Cur = Cur->getParent();
 
 
  450        DCPP_DEBUG_BREAK_IF(atEnd()) 
 
  464        if (Cur->getLeftChild())
 
  466            Cur = Cur->getLeftChild();
 
  468        else if (Cur->getRightChild())
 
  471            Cur = Cur->getRightChild();
 
  483                if (Cur->isLeftChild() && Cur->getParent()->getRightChild())
 
  485                    Cur = Cur->getParent()->getRightChild();
 
  488                Cur = Cur->getParent();
 
 
  542            DCPP_DEBUG_BREAK_IF(atEnd()) 
 
  550            while(
n!=0 && (
n->getLeftChild()!=0 || 
n->getRightChild()!=0))
 
  552                if (
n->getLeftChild())
 
  553                    n = 
n->getLeftChild();
 
  555                    n = 
n->getRightChild();
 
  571            if (Cur->isLeftChild() && Cur->getParent()->getRightChild())
 
  573                Cur = getMin(Cur->getParent()->getRightChild());
 
  576                Cur = Cur->getParent();
 
 
  610            DCPP_DEBUG_BREAK_IF(
node==0) 
 
  612            return node->getValue();
 
 
  627    map() : Root(0), Size(0) {}
 
  636    using key_type = KeyType;
 
  637    using value_type = ValueType;
 
  661            if (
newNode->getParent()->isLeftChild())
 
  668                    newNode->getParent()->setBlack();
 
  670                    newNode->getParent()->getParent()->setRed();
 
  685                    newNode->getParent()->setBlack();
 
  686                    newNode->getParent()->getParent()->setRed();
 
  687                    rotateRight(
newNode->getParent()->getParent());
 
  697                    newNode->getParent()->setBlack();
 
  699                    newNode->getParent()->getParent()->setRed();
 
  714                    newNode->getParent()->setBlack();
 
  715                    newNode->getParent()->getParent()->setRed();
 
  716                    rotateLeft(
newNode->getParent()->getParent());
 
 
  750        while(
p->getRightChild())
 
  759        if (
p->isLeftChild())
 
  760            p->getParent()->setLeftChild(
left);
 
  762        else if (
p->isRightChild())
 
  763            p->getParent()->setRightChild(
left);
 
 
  798        while(
p->getRightChild())
 
  807        if (
p->isLeftChild())
 
  808            p->getParent()->setLeftChild(
left);
 
  810        else if (
p->isRightChild())
 
  811            p->getParent()->setRightChild(
left);
 
 
  835            Node* 
p = i.getNode();
 
 
  982    bool insert(Node* newNode)
 
  994            const KeyType& keyNew = newNode->getKey();
 
  997                const KeyType& key=pNode->getKey();
 
 1004                else if (keyNew < key)
 
 1006                    if (pNode->getLeftChild() == 0)
 
 1008                        pNode->setLeftChild(newNode);
 
 1012                        pNode = pNode->getLeftChild();
 
 1016                    if (pNode->getRightChild()==0)
 
 1018                        pNode->setRightChild(newNode);
 
 1023                        pNode = pNode->getRightChild();
 
 1037    void rotateLeft(Node* p)
 
 1039        Node* right = p->getRightChild();
 
 1041        p->setRightChild(right->getLeftChild());
 
 1043        if (p->isLeftChild())
 
 1044            p->getParent()->setLeftChild(right);
 
 1045        else if (p->isRightChild())
 
 1046            p->getParent()->setRightChild(right);
 
 1050        right->setLeftChild(p);
 
 1055    void rotateRight(Node* p)
 
 1057        Node* left = p->getLeftChild();
 
 1059        p->setLeftChild(left->getRightChild());
 
 1061        if (p->isLeftChild())
 
 1062            p->getParent()->setLeftChild(left);
 
 1063        else if (p->isRightChild())
 
 1064            p->getParent()->setRightChild(left);
 
 1068        left->setRightChild(p);
 
 
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
 
Definition irrMap.hpp:591
 
Const Iterator.
Definition irrMap.hpp:268
 
Normal Iterator.
Definition irrMap.hpp:131
 
Parent First Iterator.
Definition irrMap.hpp:413
 
Parent Last Iterator.
Definition irrMap.hpp:505
 
map template for associative arrays using a red-black tree
Definition irrMap.hpp:19
 
Node * delink(const KeyType &k)
Removes a node from the tree and returns it.
Definition irrMap.hpp:742
 
Iterator getIterator() const
Returns an iterator.
Definition irrMap.hpp:909
 
dcpp::uint32_kt size() const
Returns the number of nodes in the tree.
Definition irrMap.hpp:888
 
void swap(map< KeyType, ValueType > &other)
Swap the content of this map container with the content of another map.
Definition irrMap.hpp:898
 
Node * getRoot() const
Definition irrMap.hpp:882
 
ConstIterator getConstIterator() const
Returns a Constiterator.
Definition irrMap.hpp:916
 
bool remove(const KeyType &k)
Removes a node from the tree and deletes it.
Definition irrMap.hpp:781
 
ParentFirstIterator getParentFirstIterator() const
Definition irrMap.hpp:927
 
void set(const KeyType &k, const ValueType &v)
Replaces the value if the key already exists, otherwise inserts a new element.
Definition irrMap.hpp:729
 
ParentLastIterator getParentLastIterator() const
Definition irrMap.hpp:938
 
bool empty() const
Definition irrMap.hpp:846
 
DCPP_DEPRECATED bool isEmpty() const
Definition irrMap.hpp:852
 
Node * find(const KeyType &keyToFind) const
Definition irrMap.hpp:860
 
void clear()
Clear the entire tree.
Definition irrMap.hpp:829
 
bool remove(Node *p)
Removes a node from the tree and deletes it.
Definition irrMap.hpp:789
 
AccessClass operator[](const KeyType &k)
operator [] for access to elements
Definition irrMap.hpp:950
 
bool insert(const KeyType &keyNew, const ValueType &v)
Inserts a new node into the tree.
Definition irrMap.hpp:648
 
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition irrMath.hpp:175
 
As of Duckcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
 
unsigned int uint32_kt
32 bit unsigned variable.
Definition irrTypes.hpp:64