diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 903c993c..2b80779f 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -122,6 +122,9 @@ toBeSorted/bitwise_flag_helper.cpp: c/c_list.cpp: .text start:0x802E08C0 end:0x802E0A10 +c/c_tree.cpp: + .text start:0x802E0E70 end:0x802E1140 + f/f_base.cpp: .text start:0x802E12F0 end:0x802E2680 .ctors start:0x804DB8C0 end:0x804DB8C4 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 7b943c29..ca84c0a2 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17295,7 +17295,7 @@ fn_802E0DC0 = .text:0x802E0DC0; // type:function size:0x48 fn_802E0E10 = .text:0x802E0E10; // type:function size:0xC fn_802E0E20 = .text:0x802E0E20; // type:function size:0x44 __ct__9cTreeNd_cFv = .text:0x802E0E70; // type:function size:0x30 -fn_802E0EA0 = .text:0x802E0EA0; // type:function size:0x18 +forcedClear__9cTreeNd_cFv = .text:0x802E0EA0; // type:function size:0x18 addTreeNode__9cTreeMg_cFP9cTreeNd_cP9cTreeNd_c = .text:0x802E0EC0; // type:function size:0x94 removeTreeNode__9cTreeMg_cFP9cTreeNd_c = .text:0x802E0F60; // type:function size:0x98 insertTreeNode__9cTreeMg_cFP9cTreeNd_cP9cTreeNd_c = .text:0x802E1000; // type:function size:0xBC diff --git a/configure.py b/configure.py index fc454981..19ee950f 100644 --- a/configure.py +++ b/configure.py @@ -275,6 +275,7 @@ config.libs = [ Object(NonMatching, "toBeSorted/flag_space.cpp"), Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), Object(Matching, "c/c_list.cpp"), + Object(Matching, "c/c_tree.cpp"), Object(Matching, "d/d_base.cpp"), Object(NonMatching, "d/d_heap.cpp"), Object(NonMatching, "d/d_stage.cpp"), diff --git a/src/c/c_tree.cpp b/src/c/c_tree.cpp new file mode 100644 index 00000000..a413761f --- /dev/null +++ b/src/c/c_tree.cpp @@ -0,0 +1,114 @@ +#include + +cTreeNd_c::cTreeNd_c() { + this->forcedClear(); +} + +void cTreeNd_c::forcedClear() { + this->mpParent = nullptr; + this->mpChild = nullptr; + this->mpPrev = nullptr; + this->mpNext = nullptr; +} + +bool cTreeMg_c::addTreeNode(cTreeNd_c *node, cTreeNd_c *parent) { + if (node != nullptr) { + if (parent != nullptr) { + node->mpParent = parent; + if (parent->mpChild == nullptr) { + parent->mpChild = node; + } else { + cTreeNd_c *cursor; + for (cursor = parent->mpChild; cursor->mpNext != nullptr; cursor = cursor->mpNext) {} + cursor->mpNext = node; + node->mpPrev = cursor; + } + } else { + cTreeNd_c *cursor = this->mpRootNode; + if (cursor != nullptr) { + for (; cursor->mpNext != nullptr; cursor = cursor->mpNext) {} + cursor->mpNext = node; + node->mpPrev = cursor; + } else { + this->mpRootNode = node; + } + } + } else { + return false; + } + return true; +} + +bool cTreeMg_c::removeTreeNode(cTreeNd_c *node) { + if (node != nullptr) { + if (node->mpChild != nullptr) { + return false; + } + if (node->mpPrev != nullptr) { + node->mpPrev->mpNext = node->mpNext; + } else if (node->mpParent != nullptr) { + node->mpParent->mpChild = node->mpNext; + } else if (node == this->mpRootNode) { + this->mpRootNode = node->mpNext; + } + + if (node->mpNext != nullptr) { + node->mpNext->mpPrev = node->mpPrev; + } + + node->mpPrev = nullptr; + node->mpNext = nullptr; + node->mpParent = nullptr; + } else { + return false; + } + return true; +} + +bool cTreeMg_c::insertTreeNode(cTreeNd_c *node, cTreeNd_c *parent) { + cTreeNd_c *cursor; + + for (cursor = parent; cursor != nullptr; cursor = cursor->mpParent) { + if (cursor == node) { + return false; + } + } + + if (node != nullptr) { + cTreeNd_c *child = node->mpChild; + node->mpChild = nullptr; + if (!this->removeTreeNode(node)) { + node->mpChild = child; + return false; + } else { + node->mpChild = child; + return this->addTreeNode(node, parent); + } + } + + return false; +} + +cTreeNd_c *cTreeNd_c::getTreeNext() const { + cTreeNd_c *child = this->mpChild; + if (child != nullptr) { + return child; + } else { + return this->getTreeNextNotChild(); + } +} + +cTreeNd_c *cTreeNd_c::getTreeNextNotChild() const { + if (this->mpNext != nullptr) { + return this->mpNext; + } + + cTreeNd_c *parent; + + for (parent = this->mpParent; parent != nullptr; parent = parent->mpParent) { + if (parent->mpNext != nullptr) { + return parent->mpNext; + } + } + return nullptr; +}