Browse Source

avl_tree: bug fixes

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
ff006e29a3
1 changed files with 22 additions and 16 deletions
  1. +22
    -16
      src/lol/base/avl_tree.h

+ 22
- 16
src/lol/base/avl_tree.h View File

@@ -264,7 +264,7 @@ protected:
delete this;
return true;
}
else if (m_child[i]->erase(key))
else if (m_child[i] && m_child[i]->erase(key))
{
rebalance_if_needed();
return true;
@@ -406,22 +406,28 @@ protected:

void replace_chain(tree_node * replacement)
{
for (int i = 0 ; i < 2 ; ++i)
if (replacement)
{
if (replacement->m_chain[0])
replacement->m_chain[0]->m_chain[1] = replacement->m_chain[1];

if (replacement->m_chain[1])
replacement->m_chain[1]->m_chain[0] = replacement->m_chain[0];

replacement->m_chain[0] = m_chain[0];
replacement->m_chain[1] = m_chain[1];

if (replacement->m_chain[0])
replacement->m_chain[0]->m_chain[1] = replacement;
if (replacement->m_chain[1])
replacement->m_chain[1]->m_chain[0] = replacement;
}
else
{
if (replacement)
{
if (replacement->m_chain[i])
replacement->m_chain[i]->m_chain[i ? 0 : 1] = replacement->m_chain[i ? 0 : 1];

replacement->m_chain[i] = m_chain[i];
if (replacement->m_chain[i])
replacement->m_chain[i]->m_chain[i ? 0 : 1] = replacement;
}
else
{
if (m_chain[i])
m_chain[i]->m_chain[i ? 0 : 1] = m_chain[i ? 0 : 1];
}
if (m_chain[0])
m_chain[0]->m_chain[1] = m_chain[1];
if (m_chain[1])
m_chain[1]->m_chain[0] = m_chain[0];
}
}



Loading…
Cancel
Save