summaryrefslogtreecommitdiff
path: root/core/map.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/map.h')
-rw-r--r--core/map.h46
1 files changed, 0 insertions, 46 deletions
diff --git a/core/map.h b/core/map.h
index 621b6c2842..f9321f90b3 100644
--- a/core/map.h
+++ b/core/map.h
@@ -39,7 +39,6 @@
template <class K, class V, class C = Comparator<K>, class A = DefaultAllocator>
class Map {
-
enum Color {
RED,
BLACK
@@ -48,7 +47,6 @@ class Map {
public:
class Element {
-
private:
friend class Map<K, V, C, A>;
int color = RED;
@@ -63,19 +61,15 @@ public:
public:
const Element *next() const {
-
return _next;
}
Element *next() {
-
return _next;
}
const Element *prev() const {
-
return _prev;
}
Element *prev() {
-
return _prev;
}
const K &key() const {
@@ -98,7 +92,6 @@ public:
private:
struct _Data {
-
Element *_root = nullptr;
Element *_nil;
int size_cache = 0;
@@ -114,14 +107,12 @@ private:
}
void _create_root() {
-
_root = memnew_allocator(Element, A);
_root->parent = _root->left = _root->right = _nil;
_root->color = BLACK;
}
void _free_root() {
-
if (_root) {
memdelete_allocator<Element, A>(_root);
_root = nullptr;
@@ -129,7 +120,6 @@ private:
}
~_Data() {
-
_free_root();
#ifdef GLOBALNIL_DISABLED
@@ -141,13 +131,11 @@ private:
_Data _data;
inline void _set_color(Element *p_node, int p_color) {
-
ERR_FAIL_COND(p_node == _data._nil && p_color == RED);
p_node->color = p_color;
}
inline void _rotate_left(Element *p_node) {
-
Element *r = p_node->right;
p_node->right = r->left;
if (r->left != _data._nil)
@@ -163,7 +151,6 @@ private:
}
inline void _rotate_right(Element *p_node) {
-
Element *l = p_node->left;
p_node->left = l->right;
if (l->right != _data._nil)
@@ -179,18 +166,15 @@ private:
}
inline Element *_successor(Element *p_node) const {
-
Element *node = p_node;
if (node->right != _data._nil) {
-
node = node->right;
while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
} else {
-
while (node == node->parent->right) {
node = node->parent;
}
@@ -205,14 +189,12 @@ private:
Element *node = p_node;
if (node->left != _data._nil) {
-
node = node->left;
while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
} else {
-
while (node == node->parent->left) {
node = node->parent;
}
@@ -224,7 +206,6 @@ private:
}
Element *_find(const K &p_key) const {
-
Element *node = _data._root->left;
C less;
@@ -241,7 +222,6 @@ private:
}
Element *_find_closest(const K &p_key) const {
-
Element *node = _data._root->left;
Element *prev = nullptr;
C less;
@@ -267,7 +247,6 @@ private:
}
void _insert_rb_fix(Element *p_new_node) {
-
Element *node = p_new_node;
Element *nparent = node->parent;
Element *ngrand_parent;
@@ -316,13 +295,11 @@ private:
}
Element *_insert(const K &p_key, const V &p_value) {
-
Element *new_parent = _data._root;
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
-
new_parent = node;
if (less(p_key, node->_key))
@@ -362,7 +339,6 @@ private:
}
void _erase_fix_rb(Element *p_node) {
-
Element *root = _data._root->left;
Element *node = _data._nil;
Element *sibling = p_node;
@@ -424,7 +400,6 @@ private:
}
void _erase(Element *p_node) {
-
Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next;
Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
@@ -445,7 +420,6 @@ private:
}
if (rp != p_node) {
-
ERR_FAIL_COND(rp == _data._nil);
rp->left = p_node->left;
@@ -475,7 +449,6 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
-
if (p_element == _data._nil)
return;
@@ -487,7 +460,6 @@ private:
}
void _cleanup_tree(Element *p_element) {
-
if (p_element == _data._nil)
return;
@@ -497,18 +469,15 @@ private:
}
void _copy_from(const Map &p_map) {
-
clear();
// not the fastest way, but safeset to write.
for (Element *I = p_map.front(); I; I = I->next()) {
-
insert(I->key(), I->value());
}
}
public:
const Element *find(const K &p_key) const {
-
if (!_data._root)
return nullptr;
@@ -517,7 +486,6 @@ public:
}
Element *find(const K &p_key) {
-
if (!_data._root)
return nullptr;
@@ -526,7 +494,6 @@ public:
}
const Element *find_closest(const K &p_key) const {
-
if (!_data._root)
return nullptr;
@@ -535,7 +502,6 @@ public:
}
Element *find_closest(const K &p_key) {
-
if (!_data._root)
return nullptr;
@@ -544,19 +510,16 @@ public:
}
bool has(const K &p_key) const {
-
return find(p_key) != nullptr;
}
Element *insert(const K &p_key, const V &p_value) {
-
if (!_data._root)
_data._create_root();
return _insert(p_key, p_value);
}
void erase(Element *p_element) {
-
if (!_data._root || !p_element)
return;
@@ -566,7 +529,6 @@ public:
}
bool erase(const K &p_key) {
-
if (!_data._root)
return false;
@@ -581,7 +543,6 @@ public:
}
const V &operator[](const K &p_key) const {
-
CRASH_COND(!_data._root);
const Element *e = find(p_key);
CRASH_COND(!e);
@@ -589,7 +550,6 @@ public:
}
V &operator[](const K &p_key) {
-
if (!_data._root)
_data._create_root();
@@ -601,7 +561,6 @@ public:
}
Element *front() const {
-
if (!_data._root)
return nullptr;
@@ -616,7 +575,6 @@ public:
}
Element *back() const {
-
if (!_data._root)
return nullptr;
@@ -644,7 +602,6 @@ public:
}
void clear() {
-
if (!_data._root)
return;
@@ -655,19 +612,16 @@ public:
}
void operator=(const Map &p_map) {
-
_copy_from(p_map);
}
Map(const Map &p_map) {
-
_copy_from(p_map);
}
_FORCE_INLINE_ Map() {}
~Map() {
-
clear();
}
};