From 621f53700fa3e6d84bfca3de0a36db31683427ae Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 25 May 2020 00:49:37 +0200 Subject: [PATCH] AVLTree: Add convenience LeftMost/RightMost with no arguments. They return the left and right most nodes of the entire tree, i.e. starting from the root node. Change-Id: I651a9db6d12308aef4c2ed71484958428e58c9bc Reviewed-on: https://review.haiku-os.org/c/haiku/+/2838 Reviewed-by: waddlesplash --- headers/private/kernel/util/AVLTree.h | 20 ++++++++++++++++++++ headers/private/kernel/util/AVLTreeBase.h | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/headers/private/kernel/util/AVLTree.h b/headers/private/kernel/util/AVLTree.h index f0e27f83db..c59021e8a8 100644 --- a/headers/private/kernel/util/AVLTree.h +++ b/headers/private/kernel/util/AVLTree.h @@ -47,7 +47,9 @@ public: Value* Previous(Value* value) const; Value* Next(Value* value) const; + Value* LeftMost() const; Value* LeftMost(Value* value) const; + Value* RightMost() const; Value* RightMost(Value* value) const; inline Iterator GetIterator(); @@ -258,6 +260,15 @@ AVLTree::Next(Value* value) const } +template +inline typename AVLTree::Value* +AVLTree::LeftMost() const +{ + AVLTreeNode* node = fTree.LeftMost(); + return node != NULL ? _GetValue(node) : NULL; +} + + template inline typename AVLTree::Value* AVLTree::LeftMost(Value* value) const @@ -270,6 +281,15 @@ AVLTree::LeftMost(Value* value) const } +template +inline typename AVLTree::Value* +AVLTree::RightMost() const +{ + AVLTreeNode* node = fTree.RightMost(); + return node != NULL ? _GetValue(node) : NULL; +} + + template inline typename AVLTree::Value* AVLTree::RightMost(Value* value) const diff --git a/headers/private/kernel/util/AVLTreeBase.h b/headers/private/kernel/util/AVLTreeBase.h index ea9c91de5e..26ce613065 100644 --- a/headers/private/kernel/util/AVLTreeBase.h +++ b/headers/private/kernel/util/AVLTreeBase.h @@ -46,7 +46,9 @@ public: inline AVLTreeNode* Root() const { return fRoot; } + inline AVLTreeNode* LeftMost() const; AVLTreeNode* LeftMost(AVLTreeNode* node) const; + inline AVLTreeNode* RightMost() const; AVLTreeNode* RightMost(AVLTreeNode* node) const; AVLTreeNode* Previous(AVLTreeNode* node) const; @@ -190,11 +192,25 @@ protected: }; +inline AVLTreeNode* +AVLTreeBase::LeftMost() const +{ + return LeftMost(fRoot); +} + + +inline AVLTreeNode* +AVLTreeBase::RightMost() const +{ + return RightMost(fRoot); +} + + // GetIterator inline AVLTreeIterator AVLTreeBase::GetIterator() const { - return AVLTreeIterator(this, NULL, LeftMost(fRoot)); + return AVLTreeIterator(this, NULL, LeftMost()); }