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 <[email protected]>
This commit is contained in:
Michael Lotz
2020-05-30 01:47:40 +00:00
committed by waddlesplash
parent 928d780bc9
commit 621f53700f
2 changed files with 37 additions and 1 deletions
+20
View File
@@ -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<Definition>::Next(Value* value) const
}
template<typename Definition>
inline typename AVLTree<Definition>::Value*
AVLTree<Definition>::LeftMost() const
{
AVLTreeNode* node = fTree.LeftMost();
return node != NULL ? _GetValue(node) : NULL;
}
template<typename Definition>
inline typename AVLTree<Definition>::Value*
AVLTree<Definition>::LeftMost(Value* value) const
@@ -270,6 +281,15 @@ AVLTree<Definition>::LeftMost(Value* value) const
}
template<typename Definition>
inline typename AVLTree<Definition>::Value*
AVLTree<Definition>::RightMost() const
{
AVLTreeNode* node = fTree.RightMost();
return node != NULL ? _GetValue(node) : NULL;
}
template<typename Definition>
inline typename AVLTree<Definition>::Value*
AVLTree<Definition>::RightMost(Value* value) const
+17 -1
View File
@@ -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());
}