mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-21 15:21:15 +00:00
Few more cleanup items before opening up to comments
* Tried a "Find" method to reduce repeated code between MxAtomId::Destroy and TreeAdd functions * Renamed the "Successor" function * There is a destructor for the RB tree. I started on one of the companion functions but it is unfinished here.
This commit is contained in:
parent
d80b387490
commit
8afddd3bdb
@ -37,16 +37,8 @@ void MxAtomId::Destroy()
|
|||||||
TreeValue *p = &value;
|
TreeValue *p = &value;
|
||||||
|
|
||||||
// 100ad052
|
// 100ad052
|
||||||
MxBinaryTree *tree = AtomIdTree();
|
|
||||||
TreeNode *root = tree->m_root;
|
|
||||||
|
|
||||||
// should inline Search but NOT TreeValueCompare
|
// should inline Search but NOT TreeValueCompare
|
||||||
TreeNode *node = tree->Search(p);
|
TreeNode *node = AtomIdTree()->Find(p);
|
||||||
|
|
||||||
TreeNode *ass = node;
|
|
||||||
if (node == root->m_parent || TreeValueCompare(p, node->m_value)) {
|
|
||||||
ass = root->m_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
node->m_value->RefCountDec();
|
node->m_value->RefCountDec();
|
||||||
}
|
}
|
||||||
@ -71,7 +63,6 @@ MxAtomId &MxAtomId::operator=(const MxAtomId &atomId)
|
|||||||
TreeValue *MxAtomId::try_to_open(const char *p_str, LookupMode p_mode)
|
TreeValue *MxAtomId::try_to_open(const char *p_str, LookupMode p_mode)
|
||||||
{
|
{
|
||||||
TreeValue *value = new TreeValue(p_str);
|
TreeValue *value = new TreeValue(p_str);
|
||||||
TreeNode *node;
|
|
||||||
|
|
||||||
switch (p_mode) {
|
switch (p_mode) {
|
||||||
case LookupMode_LowerCase:
|
case LookupMode_LowerCase:
|
||||||
@ -84,22 +75,13 @@ TreeValue *MxAtomId::try_to_open(const char *p_str, LookupMode p_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LAB_100ad2a1
|
// LAB_100ad2a1
|
||||||
|
TreeNode *node = AtomIdTree()->Find(value);
|
||||||
|
|
||||||
MxBinaryTree *tree = AtomIdTree();
|
MxBinaryTree *tree = AtomIdTree();
|
||||||
// get the closest node that matches the given value
|
if (node->m_child0 != tree->m_root) {
|
||||||
// should NOT inline
|
// unnecessary check?
|
||||||
node = tree->Search(value);
|
if (value)
|
||||||
|
delete value;
|
||||||
TreeNode *t;
|
|
||||||
|
|
||||||
// is the node an exact match?
|
|
||||||
if (tree->m_root == node || TreeValueCompare(value, node->m_value)) {
|
|
||||||
t = tree->m_root;
|
|
||||||
} else {
|
|
||||||
t = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t->m_child0 != AtomIdTree()->m_root) {
|
|
||||||
delete value;
|
|
||||||
value = node->m_value;
|
value = node->m_value;
|
||||||
} else {
|
} else {
|
||||||
// repeat?
|
// repeat?
|
||||||
|
|||||||
@ -3,11 +3,13 @@
|
|||||||
// 0x101013f0
|
// 0x101013f0
|
||||||
TreeNode *MxBinaryTree::g_Node_Nil = NULL;
|
TreeNode *MxBinaryTree::g_Node_Nil = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
// OFFSET: LEGO1 0x100ad170
|
// OFFSET: LEGO1 0x100ad170
|
||||||
TreeValue::~TreeValue()
|
TreeValue::~TreeValue()
|
||||||
{
|
{
|
||||||
// nothing.
|
// nothing.
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
inline void MxBinaryTree::RightRotate(TreeNode *x)
|
inline void MxBinaryTree::RightRotate(TreeNode *x)
|
||||||
{
|
{
|
||||||
@ -76,8 +78,9 @@ inline TreeNode *minimum(TreeNode *p_node)
|
|||||||
return p_node;
|
return p_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OFFSET: LEGO1 0x100ad480
|
// OFFSET: LEGO1 0x100ad480
|
||||||
void mini_walk(TreeNode* &p_node)
|
void Successor(TreeNode* &p_node)
|
||||||
{
|
{
|
||||||
// I think this is checking whether this is the tree "root" node
|
// I think this is checking whether this is the tree "root" node
|
||||||
// i.e. MxBinaryTree->m_root
|
// i.e. MxBinaryTree->m_root
|
||||||
@ -91,7 +94,6 @@ void mini_walk(TreeNode* &p_node)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// successor?
|
|
||||||
if (p_node->m_child0 != MxBinaryTree::g_Node_Nil) {
|
if (p_node->m_child0 != MxBinaryTree::g_Node_Nil) {
|
||||||
p_node = minimum(p_node->m_child0);
|
p_node = minimum(p_node->m_child0);
|
||||||
return;
|
return;
|
||||||
@ -103,9 +105,9 @@ void mini_walk(TreeNode* &p_node)
|
|||||||
p_node = y;
|
p_node = y;
|
||||||
y = y->m_parent;
|
y = y->m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OFFSET: LEGO1 0x100ad4d0
|
// OFFSET: LEGO1 0x100ad4d0
|
||||||
void MxBinaryTree::Insert(TreeNode **p_output, TreeNode *p_leaf, TreeNode *p_parent, TreeValue *&p_value)
|
void MxBinaryTree::Insert(TreeNode **p_output, TreeNode *p_leaf, TreeNode *p_parent, TreeValue *&p_value)
|
||||||
{
|
{
|
||||||
@ -232,3 +234,24 @@ void TreeValue::RefCountDec()
|
|||||||
if (m_t0)
|
if (m_t0)
|
||||||
m_t0--;
|
m_t0--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OFFSET: LEGO1 0x100af6d0 STUB
|
||||||
|
MxBinaryTree::~MxBinaryTree()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// OFFSET: LEGO1 0x100af7a0
|
||||||
|
void somethingWithNode(TreeNode*& p_node)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
if (p_node->m_child1 != MxBinaryTree::g_Node_Nil) {
|
||||||
|
p_node = minimum(p_node->m_child1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (p_node->m_parent->m_child0 == p_node)
|
||||||
|
p_node = p_node->m_parent;
|
||||||
|
|
||||||
|
if (p_node->m_child1 == p_node->m_parent)
|
||||||
|
p_node = p_node->m_parent;
|
||||||
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ class TreeValue {
|
|||||||
m_str = p_str;
|
m_str = p_str;
|
||||||
m_t0 = 0;
|
m_t0 = 0;
|
||||||
}
|
}
|
||||||
~TreeValue();
|
|
||||||
|
|
||||||
void RefCountInc();
|
void RefCountInc();
|
||||||
void RefCountDec();
|
void RefCountDec();
|
||||||
@ -71,11 +70,13 @@ class MxBinaryTree
|
|||||||
|
|
||||||
m_root = newTreeNode(g_Node_Nil, NODE_COLOR_RED);
|
m_root = newTreeNode(g_Node_Nil, NODE_COLOR_RED);
|
||||||
}
|
}
|
||||||
|
~MxBinaryTree();
|
||||||
|
|
||||||
void LeftRotate(TreeNode *);
|
void LeftRotate(TreeNode *);
|
||||||
void RightRotate(TreeNode *);
|
void RightRotate(TreeNode *);
|
||||||
void Insert(TreeNode **, TreeNode *, TreeNode *, TreeValue *&);
|
void Insert(TreeNode **, TreeNode *, TreeNode *, TreeValue *&);
|
||||||
TreeNode *Search(TreeValue *&);
|
TreeNode *Search(TreeValue *&);
|
||||||
|
TreeNode *Find(TreeValue *&);
|
||||||
|
|
||||||
int m_p0; // +0
|
int m_p0; // +0
|
||||||
TreeNode *m_root; // +4
|
TreeNode *m_root; // +4
|
||||||
@ -83,4 +84,16 @@ class MxBinaryTree
|
|||||||
int m_nodeCount; // +c
|
int m_nodeCount; // +c
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline TreeNode *MxBinaryTree::Find(TreeValue *&p_value)
|
||||||
|
{
|
||||||
|
TreeNode *node = Search(p_value);
|
||||||
|
|
||||||
|
// we should only get the root back if the tree is empty.
|
||||||
|
if (m_root == node || TreeValueCompare(p_value, node->m_value)) {
|
||||||
|
node = m_root; // ??
|
||||||
|
}
|
||||||
|
|
||||||
|
return node->m_child0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif //MXBINARYTREE_H
|
#endif //MXBINARYTREE_H
|
||||||
Loading…
Reference in New Issue
Block a user