mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
TreeNode::parent algorithm
This commit is contained in:
@@ -2,6 +2,35 @@
|
||||
#include "tree_pool.h"
|
||||
#include "expression_node.h"
|
||||
|
||||
TreeNode * TreeNode::parent() const {
|
||||
int cursor = -1;
|
||||
TreeNode * parentsHistory[TreePool::MaxNumberOfNodes];
|
||||
int numberOfChildrenHistory[TreePool::MaxNumberOfNodes];
|
||||
int childrenVisitedCountHistory[TreePool::MaxNumberOfNodes];
|
||||
for (TreeNode * node : TreePool::sharedPool()->allNodes()) {
|
||||
if (node->identifier() == m_identifier) {
|
||||
printf("Parent of %d is %d\n", m_identifier, cursor >= 0 ? parentsHistory[cursor]->identifier() : -1);
|
||||
return cursor >= 0 ? parentsHistory[cursor] : nullptr;
|
||||
}
|
||||
if (cursor >= 0) {
|
||||
childrenVisitedCountHistory[cursor] = childrenVisitedCountHistory[cursor]+1;
|
||||
}
|
||||
int nodeChildrenCount = node->numberOfChildren();
|
||||
if (nodeChildrenCount > 0) {
|
||||
cursor++;
|
||||
parentsHistory[cursor] = node;
|
||||
numberOfChildrenHistory[cursor] = nodeChildrenCount;
|
||||
childrenVisitedCountHistory[cursor] = 0;
|
||||
} else {
|
||||
if (cursor >= 0 && (numberOfChildrenHistory[cursor] == childrenVisitedCountHistory[cursor])) {
|
||||
cursor--;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TreeNode::release() {
|
||||
printf("Release %d(%p)\n", m_identifier, this);
|
||||
m_referenceCounter--;
|
||||
|
||||
Reference in New Issue
Block a user