From 022e686f5b9196559ec8fe3a46cb6d6c89f80368 Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Fri, 17 Oct 2014 20:19:15 +0000 Subject: [PATCH] avl_tree: moving avl_tree implementation in lol/base. --- src/Makefile.am | 6 +++--- src/lol/algorithm/all.h | 1 - src/lol/base/all.h | 1 + src/lol/{algorithm => base}/avl_tree.h | 22 ++++------------------ src/t/Makefile.am | 11 +++-------- src/t/{algorithm => base}/avl_tree.cpp | 0 6 files changed, 11 insertions(+), 30 deletions(-) rename src/lol/{algorithm => base}/avl_tree.h (95%) rename src/t/{algorithm => base}/avl_tree.cpp (100%) diff --git a/src/Makefile.am b/src/Makefile.am index 65471a42..4c64511a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,8 +36,8 @@ liblolcore_headers = \ lol/engine-internal.h lol/engine.h lol/public.h lol/extras.h \ \ lol/base/all.h \ - lol/base/features.h lol/base/tuple.h lol/base/types.h lol/base/array.h \ - lol/base/assert.h lol/base/string.h lol/base/hash.h lol/base/map.h \ + lol/base/avl_tree.h lol/base/features.h lol/base/tuple.h lol/base/types.h \ + lol/base/array.h lol/base/assert.h lol/base/string.h lol/base/hash.h lol/base/map.h \ lol/base/enum.h lol/base/log.h \ \ lol/math/all.h \ @@ -47,7 +47,7 @@ liblolcore_headers = \ lol/math/transform.h \ \ lol/algorithm/all.h \ - lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h lol/algorithm/avl_tree.h \ + lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h \ \ lol/sys/all.h \ lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/timer.h \ diff --git a/src/lol/algorithm/all.h b/src/lol/algorithm/all.h index 2f7e1268..dec445fc 100644 --- a/src/lol/algorithm/all.h +++ b/src/lol/algorithm/all.h @@ -12,6 +12,5 @@ #include #include -#include #include diff --git a/src/lol/base/all.h b/src/lol/base/all.h index 612b13c3..f33f7bb5 100644 --- a/src/lol/base/all.h +++ b/src/lol/base/all.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include #include diff --git a/src/lol/algorithm/avl_tree.h b/src/lol/base/avl_tree.h similarity index 95% rename from src/lol/algorithm/avl_tree.h rename to src/lol/base/avl_tree.h index 7361d172..7abc0207 100644 --- a/src/lol/algorithm/avl_tree.h +++ b/src/lol/base/avl_tree.h @@ -15,6 +15,8 @@ namespace lol { +#include + template class avl_tree { @@ -330,8 +332,8 @@ protected: void update_balance() { - this->m_stairs[0] = this->m_child[0] ? lol::max(this->m_child[0]->m_stairs[0], this->m_child[0]->m_stairs[1]) + 1 : 0; - this->m_stairs[1] = this->m_child[1] ? lol::max(this->m_child[1]->m_stairs[0], this->m_child[1]->m_stairs[1]) + 1 : 0; + this->m_stairs[0] = this->m_child[0] ? (this->m_child[0]->m_stairs[0] > this->m_child[0]->m_stairs[1] ? this->m_child[0]->m_stairs[0] : this->m_child[0]->m_stairs[1]) + 1 : 0; + this->m_stairs[1] = this->m_child[1] ? (this->m_child[1]->m_stairs[0] > this->m_child[1]->m_stairs[1] ? this->m_child[1]->m_stairs[0] : this->m_child[1]->m_stairs[1]) + 1 : 0; } void rebalance_if_needed() @@ -459,8 +461,6 @@ public: Iterator & operator++(int) { - ASSERT(this->m_node); - this->m_node = this->m_node->get_next(); return *this; @@ -468,8 +468,6 @@ public: Iterator & operator--(int) { - ASSERT(this->m_node); - this->m_node = this->m_node->get_previous(); return *this; @@ -477,8 +475,6 @@ public: Iterator operator++() { - ASSERT(this->m_node); - tree_node * ret = this->m_node; this->m_node = this->m_node->get_next(); @@ -487,8 +483,6 @@ public: Iterator operator--() { - ASSERT(this->m_node); - tree_node * ret = this->m_node; this->m_node = this->m_node->get_previous(); @@ -533,8 +527,6 @@ public: ConstIterator & operator++(int) { - ASSERT(this->m_node); - this->m_node = this->m_node->get_next(); return *this; @@ -542,8 +534,6 @@ public: ConstIterator & operator--(int) { - ASSERT(this->m_node); - this->m_node = this->m_node->get_previous(); return *this; @@ -551,8 +541,6 @@ public: ConstIterator operator++() { - ASSERT(this->m_node); - tree_node * ret = this->m_node; this->m_node = this->m_node->get_next(); @@ -561,8 +549,6 @@ public: ConstIterator operator--() { - ASSERT(this->m_node); - tree_node * ret = this->m_node; this->m_node = this->m_node->get_previous(); diff --git a/src/t/Makefile.am b/src/t/Makefile.am index 264860a6..e6d91686 100644 --- a/src/t/Makefile.am +++ b/src/t/Makefile.am @@ -7,17 +7,12 @@ TESTS = $(testsuite) # Conditionally built for now because of STLport issues if !USE_ANDROID -testsuite = test-algorithm test-base test-math test-sys test-image test-entity +testsuite = test-base test-math test-sys test-image test-entity endif -test_algorithm_SOURCES = test-common.cpp \ - algorithm/avl_tree.cpp -test_algorithm_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit -test_algorithm_DEPENDENCIES = @LOL_DEPS@ - test_base_SOURCES = test-common.cpp \ - base/array.cpp base/enum.cpp base/map.cpp base/string.cpp \ - base/types.cpp + base/avl_tree.cpp base/array.cpp base/enum.cpp base/map.cpp \ + base/string.cpp base/types.cpp test_base_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit test_base_DEPENDENCIES = @LOL_DEPS@ diff --git a/src/t/algorithm/avl_tree.cpp b/src/t/base/avl_tree.cpp similarity index 100% rename from src/t/algorithm/avl_tree.cpp rename to src/t/base/avl_tree.cpp