From a9e67e2cc1f3ff9a0efe319a84bca9cbe21bf85e Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Thu, 16 Oct 2014 16:20:34 +0000 Subject: [PATCH] avl_tree: tiny fixes + iterator features. --- src/lol/algorithm/avl_tree.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lol/algorithm/avl_tree.h b/src/lol/algorithm/avl_tree.h index 9b524325..624aea5d 100644 --- a/src/lol/algorithm/avl_tree.h +++ b/src/lol/algorithm/avl_tree.h @@ -76,8 +76,8 @@ public: if (this->m_root) { this->m_root->get_min(min_node); - key_ptr = &min_node->m_key; - value_ptr = &min_node->m_value; + key_ptr = &min_node->get_key(); + value_ptr = &min_node->get_value(); return true; } @@ -92,7 +92,8 @@ public: if (this->m_root) { this->m_root->get_max(max_node); - value_ptr = &max_node->value; + key_ptr = &max_node->get_key(); + value_ptr = &max_node->get_value(); return true; } @@ -100,6 +101,29 @@ public: return false; } + class Iterator; + class ConstIterator; + + Iterator get_iterator() + { + tree_node * node = nullptr; + + if (this->m_root) + node = this->m_root->get_min(); + + return Iterator(node); + } + + ConstIterator get_iterator() const + { + tree_node * node = nullptr; + + if (this->m_root) + node = this->m_root->get_min(); + + return ConstIterator(node); + } + protected: class tree_node