sead
Loading...
Searching...
No Matches
seadTreeMapImpl.h
Go to the documentation of this file.
1#ifndef SEAD_TREE_MAP_IMPL_H_
2#define SEAD_TREE_MAP_IMPL_H_
3
4#include <basis/seadTypes.h>
5
6namespace sead {
7
8template <typename Key>
10{
11public:
13 {
14 mLeft_ = nullptr;
15 mRight_ = nullptr;
16 mColor_ = cRed_;
17 }
18
19 virtual ~TreeMapNode()
20 {
21 }
22
23 virtual void erase_() = 0;
24
27 bool mColor_;
28 Key mKey_;
29
30 static const bool cRed_ = true;
31 static const bool cBlack_ = false;
32};
33
34template <typename Key>
36{
37public:
38 typedef TreeMapNode<Key> Node;
39
40public:
42 : mRoot(nullptr)
43 {
44 }
45
46 void insert(Node* node)
47 {
48 mRoot = insert(mRoot, node);
49 mRoot->mColor_ = Node::cBlack_;
50 }
51
52 Node* insert(Node* h, Node* node);
53
54 void erase(const Key& key)
55 {
56 mRoot = erase(mRoot, key);
57 if (mRoot != nullptr)
58 mRoot->mColor_ = Node::cBlack_;
59 }
60
61 Node* erase(Node* h, const Key& key);
62
63 Node* find(const Key& key) const
64 {
65 return find(mRoot, key);
66 }
67
68 Node* find(Node* node, const Key& key) const;
69
70 bool contains(const Key& key) const
71 {
72 return find(key) != nullptr;
73 }
74
75 static Node* min(Node* h);
76 static Node* eraseMin(Node* h);
77 static Node* moveRedLeft(Node* h);
78 static Node* moveRedRight(Node* h);
79 static Node* fixUp(Node* h);
80 static Node* rotateLeft(Node* h);
81 static Node* rotateRight(Node* h);
82 static void flipColors(Node* h);
83 static bool isRed(Node* h);
84
85 template <typename T> // T = {*}Delegate1<..., TreeMapNode<Key>*>
86 void forEach(const T& fun) const
87 {
88 if (mRoot != nullptr)
89 forEach(mRoot, fun);
90 }
91
92 template <typename T> // T = {*}Delegate1<..., TreeMapNode<Key>*>
93 static void forEach(Node* node, const T& fun)
94 {
95 if (node->mLeft_ != nullptr)
96 forEach(node->mLeft_, fun);
97
98 fun(node);
99
100 if (node->mRight_ != nullptr)
101 forEach(node->mRight_, fun);
102 }
103
104protected:
106};
107
108} // namespace sead
109
110#ifdef __cplusplus
111
112#include <container/seadTreeMapImpl.hpp>
113
114#endif // __cplusplus
115
116#endif // SEAD_TREE_MAP_IMPL_H_
Definition seadTreeMapImpl.h:36
TreeMapImpl()
Definition seadTreeMapImpl.h:41
void forEach(const T &fun) const
Definition seadTreeMapImpl.h:86
Node * mRoot
Definition seadTreeMapImpl.h:105
static Node * moveRedRight(Node *h)
Definition seadTreeMapImpl.hpp:147
static bool isRed(Node *h)
Definition seadTreeMapImpl.hpp:209
Node * find(const Key &key) const
Definition seadTreeMapImpl.h:63
Node * find(Node *node, const Key &key) const
Definition seadTreeMapImpl.hpp:91
Node * erase(Node *h, const Key &key)
Definition seadTreeMapImpl.hpp:48
static void flipColors(Node *h)
Definition seadTreeMapImpl.hpp:200
static Node * min(Node *h)
Definition seadTreeMapImpl.hpp:108
bool contains(const Key &key) const
Definition seadTreeMapImpl.h:70
void erase(const Key &key)
Definition seadTreeMapImpl.h:54
void insert(Node *node)
Definition seadTreeMapImpl.h:46
static void forEach(Node *node, const T &fun)
Definition seadTreeMapImpl.h:93
static Node * rotateRight(Node *h)
Definition seadTreeMapImpl.hpp:188
TreeMapNode< Key > Node
Definition seadTreeMapImpl.h:38
static Node * eraseMin(Node *h)
Definition seadTreeMapImpl.hpp:118
static Node * moveRedLeft(Node *h)
Definition seadTreeMapImpl.hpp:133
static Node * fixUp(Node *h)
Definition seadTreeMapImpl.hpp:160
static Node * rotateLeft(Node *h)
Definition seadTreeMapImpl.hpp:176
Node * insert(Node *h, Node *node)
Definition seadTreeMapImpl.hpp:7
Definition seadTreeMapImpl.h:10
static const bool cBlack_
Definition seadTreeMapImpl.h:31
TreeMapNode< Key > * mRight_
Definition seadTreeMapImpl.h:26
bool mColor_
Definition seadTreeMapImpl.h:27
virtual void erase_()=0
TreeMapNode()
Definition seadTreeMapImpl.h:12
TreeMapNode< Key > * mLeft_
Definition seadTreeMapImpl.h:25
Key mKey_
Definition seadTreeMapImpl.h:28
static const bool cRed_
Definition seadTreeMapImpl.h:30
virtual ~TreeMapNode()
Definition seadTreeMapImpl.h:19
Definition seadAssert.h:44