Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Bugfix in Tree::remove(...) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/trees/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ vector<shared_ptr<TreeNode const>> Tree::calcLeaves() const
void Tree::remove(const shared_ptr<TreeNode> thisNode, const shared_ptr<TreeNode> otherNode)
{
thisNode->deleteNode();

for (shared_ptr<TreeEdge> e : *thisNode->getChildren())
{
int edgeCounter = 0; // number of edges already checked (don't have to be checked again, if getChildren() changes)
for (std::vector<shared_ptr<TreeEdge>>::const_iterator it = thisNode->getChildren()->cbegin(); it != thisNode->getChildren()->cend();) {
size_t oldSize = thisNode->getChildren()->size();
shared_ptr<TreeEdge> e = *it;
shared_ptr<TreeEdge> eOther = otherNode->hasEdge(e);
if (eOther != nullptr)
{
remove(e->getTarget(), eOther->getTarget());
}
// size of getChildren() can change if children are deleted and removed. In this case we need a new iterator pointing to the same address.
if (oldSize != thisNode->getChildren()->size()) {
it = thisNode->getChildren()->cbegin() + edgeCounter;
}
else {
++edgeCounter;
++it;
}
}
}

Expand Down