mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 01:00:50 +01:00
Fix some methods
This commit is contained in:
@@ -7,18 +7,17 @@ void TreeNode::release() {
|
||||
m_referenceCounter--;
|
||||
if (m_referenceCounter == 0) {
|
||||
if (numberOfChildren() != 0) {
|
||||
int lastIdentifier = lastDescendant()->identifier();
|
||||
int lastIdentifier = lastChild()->identifier();
|
||||
TreeNode * child = next();
|
||||
do {
|
||||
bool childWillBeDeleted = (child->m_referenceCounter == 1);
|
||||
bool lastChildReleased = false;
|
||||
while (!lastChildReleased) {
|
||||
lastChildReleased = child->identifier() == lastIdentifier;
|
||||
int nextSiblingIdentifier = lastChildReleased ? -1 : child->nextSibling()->identifier();
|
||||
child->release();
|
||||
if (!childWillBeDeleted) {
|
||||
printf("Incrementing iterator\n");
|
||||
child = child->next();
|
||||
} else {
|
||||
printf("Keeping iterator\n");
|
||||
if (nextSiblingIdentifier != -1) {
|
||||
child = TreePool::sharedPool()->node(nextSiblingIdentifier);
|
||||
}
|
||||
} while (child->identifier() != lastIdentifier);
|
||||
}
|
||||
}
|
||||
printf("Delete %d(%p)\n", m_identifier, this);
|
||||
int identifier = m_identifier;
|
||||
|
||||
21
tree_node.h
21
tree_node.h
@@ -131,17 +131,17 @@ public:
|
||||
}
|
||||
|
||||
TreeNode * nextSibling() const {
|
||||
TreeNode * node = const_cast<TreeNode *>(this);
|
||||
int remainingNodesToVisit = 0;
|
||||
do {
|
||||
int remainingNodesToVisit = numberOfChildren();
|
||||
TreeNode * node = const_cast<TreeNode *>(this)->next();
|
||||
while (remainingNodesToVisit > 0) {
|
||||
remainingNodesToVisit += node->numberOfChildren();
|
||||
node = node->next();
|
||||
remainingNodesToVisit--;
|
||||
} while (remainingNodesToVisit > 0);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
TreeNode * lastDescendant() const {
|
||||
/*TreeNode * lastDescendant() const {
|
||||
TreeNode * node = const_cast<TreeNode *>(this);
|
||||
int remainingNodesToVisit = node->numberOfChildren();
|
||||
while (remainingNodesToVisit > 0) {
|
||||
@@ -150,6 +150,17 @@ public:
|
||||
remainingNodesToVisit += node->numberOfChildren();
|
||||
}
|
||||
return node;
|
||||
}*/
|
||||
|
||||
TreeNode * lastChild() const {
|
||||
if (numberOfChildren() == 0) {
|
||||
return const_cast<TreeNode *>(this);
|
||||
}
|
||||
TreeNode * node = next();
|
||||
for (int i = 0; i < numberOfChildren() - 1; i++) {
|
||||
node = node->nextSibling();
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
size_t deepSize() const {
|
||||
|
||||
Reference in New Issue
Block a user