From 7f54caf3c69b5a4ccb145f14a8bd0fb8b48f01f0 Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Wed, 8 Oct 2014 19:55:44 +0000 Subject: [PATCH] avl_tree: moving file in algorithm, adding empty test file and fixing compilation --- src/Makefile.am | 2 +- src/lol/algorithm/all.h | 1 + src/lol/{base => algorithm}/avl_tree.h | 18 +++++++++--------- src/t/Makefile.am | 7 ++++++- 4 files changed, 17 insertions(+), 11 deletions(-) rename src/lol/{base => algorithm}/avl_tree.h (93%) diff --git a/src/Makefile.am b/src/Makefile.am index 54f07269..65471a42 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h lol/algorithm/avl_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 dec445fc..2f7e1268 100644 --- a/src/lol/algorithm/all.h +++ b/src/lol/algorithm/all.h @@ -12,5 +12,6 @@ #include #include +#include #include diff --git a/src/lol/base/avl_tree.h b/src/lol/algorithm/avl_tree.h similarity index 93% rename from src/lol/base/avl_tree.h rename to src/lol/algorithm/avl_tree.h index 6fafa636..8bf47848 100644 --- a/src/lol/base/avl_tree.h +++ b/src/lol/algorithm/avl_tree.h @@ -56,9 +56,9 @@ private: m_key(key), m_value(value), m_lo(0), - m_hi(0) + m_hi(0), m_stairs_lo(0), - m_stairs_hi(0), + m_stairs_hi(0) { } @@ -89,9 +89,9 @@ private: int path_update_balance(K const & key) { if (key < this->m_key) - this->m_stairs_lo = lol::max(this->m_lo->path_update_balance(node), this->m_stairs_lo); + this->m_stairs_lo = lol::max(this->m_lo->path_update_balance(key), this->m_stairs_lo); else if (this->m_key < key) - this->m_stairs_hi = lol::max(this->m_hi->path_update_balance(node), this->m_stairs_hi); + this->m_stairs_hi = lol::max(this->m_hi->path_update_balance(key), this->m_stairs_hi); return lol::max(this->m_stairs_lo, this->m_stairs_hi) + 1; } @@ -104,7 +104,7 @@ private: if (node) { this->m_lo = node; - --this->m_lo; + --this->m_stairs_lo; } } else if (this->m_key < key) @@ -113,7 +113,7 @@ private: if (node) { this->m_hi = node; - --this->m_hi; + --this->m_stairs_hi; } } @@ -142,7 +142,7 @@ private: this->m_lo = lo_hi; this->compute_balance(); - lo_hi->compute_balance(); + lo->compute_balance(); return lo; } @@ -155,9 +155,9 @@ private: this->m_hi = hi_lo; this->compute_balance(); - hi_lo->compute_balance(); + hi->compute_balance(); - return lo; + return hi; } return 0; diff --git a/src/t/Makefile.am b/src/t/Makefile.am index 273b79af..264860a6 100644 --- a/src/t/Makefile.am +++ b/src/t/Makefile.am @@ -7,9 +7,14 @@ TESTS = $(testsuite) # Conditionally built for now because of STLport issues if !USE_ANDROID -testsuite = test-base test-math test-sys test-image test-entity +testsuite = test-algorithm 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