Fix some methods

This commit is contained in:
Léa Saviot
2018-06-21 14:39:48 +02:00
parent b81d491644
commit b201e82cdd
2 changed files with 24 additions and 14 deletions

View File

@@ -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;

View File

@@ -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 {