mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
ReplaceWith and ReplaceChild methods on References
This commit is contained in:
@@ -2,6 +2,32 @@
|
||||
#include "tree_pool.h"
|
||||
#include "expression_node.h"
|
||||
|
||||
// Node operations
|
||||
|
||||
void TreeNode::release() {
|
||||
printf("Release %d(%p)\n", m_identifier, this);
|
||||
m_referenceCounter--;
|
||||
if (m_referenceCounter == 0) {
|
||||
if (numberOfChildren() != 0) {
|
||||
int lastIdentifier = lastChild()->identifier();
|
||||
TreeNode * child = next();
|
||||
bool lastChildReleased = false;
|
||||
while (!lastChildReleased) {
|
||||
lastChildReleased = child->identifier() == lastIdentifier;
|
||||
int nextSiblingIdentifier = lastChildReleased ? -1 : child->nextSibling()->identifier();
|
||||
child->release();
|
||||
if (nextSiblingIdentifier != -1) {
|
||||
child = TreePool::sharedPool()->node(nextSiblingIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Delete %d(%p)\n", m_identifier, this);
|
||||
TreePool::sharedPool()->discardTreeNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Hierarchy
|
||||
|
||||
TreeNode * TreeNode::parentTree() const {
|
||||
// Choose between those two algorithms: the first has complexity O(numberNodes) but uses 0(3maxNumberNodes) space
|
||||
// The second is much clearer for the reader and uses no space, but has complexity 0
|
||||
@@ -130,25 +156,3 @@ bool TreeNode::hasSibling(const TreeNode * e) const {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TreeNode::release() {
|
||||
printf("Release %d(%p)\n", m_identifier, this);
|
||||
m_referenceCounter--;
|
||||
if (m_referenceCounter == 0) {
|
||||
if (numberOfChildren() != 0) {
|
||||
int lastIdentifier = lastChild()->identifier();
|
||||
TreeNode * child = next();
|
||||
bool lastChildReleased = false;
|
||||
while (!lastChildReleased) {
|
||||
lastChildReleased = child->identifier() == lastIdentifier;
|
||||
int nextSiblingIdentifier = lastChildReleased ? -1 : child->nextSibling()->identifier();
|
||||
child->release();
|
||||
if (nextSiblingIdentifier != -1) {
|
||||
child = TreePool::sharedPool()->node(nextSiblingIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Delete %d(%p)\n", m_identifier, this);
|
||||
TreePool::sharedPool()->discardTreeNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user