Parcourir la source

avl_tree: memory released, valgrind says “no leaks are possible”

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> il y a 10 ans
Parent
révision
b73bb8d901
2 fichiers modifiés avec 25 ajouts et 0 suppressions
  1. +24
    -0
      src/lol/algorithm/avl_tree.h
  2. +1
    -0
      src/t/algorithm/avl_tree.cpp

+ 24
- 0
src/lol/algorithm/avl_tree.h Voir le fichier

@@ -52,6 +52,15 @@ public:
return this->m_root->exists(key);
}

virtual ~avl_tree()
{
if (this->m_root)
{
this->m_root->cascade_delete();
delete this->m_root;
}
}

protected:

class tree_node
@@ -169,6 +178,21 @@ protected:
return false;
}

void cascade_delete()
{
if (this->m_child[0])
{
this->m_child[0]->cascade_delete();
delete this->m_child[0];
}

if (this->m_child[1])
{
this->m_child[1]->cascade_delete();
delete this->m_child[1];
}
}

int get_balance()
{
return this->m_stairs[1] - this->m_stairs[0];


+ 1
- 0
src/t/algorithm/avl_tree.cpp Voir le fichier

@@ -20,6 +20,7 @@ namespace lol
class test_tree : public avl_tree<int, int>
{
public:
virtual ~test_tree() {}

int get_root_balance()
{


Chargement…
Annuler
Enregistrer