The implementation is also useful as a fast priority queue.\r
\r
Copyright (C) 2014, Red Hat, Inc.\r
+ Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
\r
- This program and the accompanying materials are licensed and made available\r
- under the terms and conditions of the BSD License that accompanies this\r
- distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
- WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
**/\r
\r
#include <Library/OrderedCollectionLib.h>\r
return Node->UserStruct;\r
}\r
\r
+/**\r
+ A slow function that asserts that the tree is a valid red-black tree, and\r
+ that it orders user structures correctly.\r
+\r
+ Read-only operation.\r
\r
-//\r
-// Forward declaration of internal, unit test helper function. See\r
-// specification and function definition later.\r
-//\r
-STATIC\r
+ This function uses the stack for recursion and is not recommended for\r
+ "production use".\r
+\r
+ @param[in] Tree The tree to validate.\r
+**/\r
VOID\r
RedBlackTreeValidate (\r
IN CONST RED_BLACK_TREE *Tree\r
IN CONST RED_BLACK_TREE *Tree\r
)\r
{\r
- return Tree->Root == NULL;\r
+ return (BOOLEAN)(Tree->Root == NULL);\r
}\r
\r
\r
the root of the tree), then the function stores the\r
new root node of the tree in NewRoot.\r
**/\r
-STATIC\r
VOID\r
RedBlackTreeRotateRight (\r
IN OUT RED_BLACK_TREE_NODE *Pivot,\r
OUT RED_BLACK_TREE_NODE **NewRoot\r
)\r
{\r
- RED_BLACK_TREE_NODE *Parent, *LeftChild, *LeftRightChild;\r
+ RED_BLACK_TREE_NODE *Parent;\r
+ RED_BLACK_TREE_NODE *LeftChild;\r
+ RED_BLACK_TREE_NODE *LeftRightChild;\r
\r
Parent = Pivot->Parent;\r
LeftChild = Pivot->Left;\r
the root of the tree), then the function stores the\r
new root node of the tree in NewRoot.\r
**/\r
-STATIC\r
VOID\r
RedBlackTreeRotateLeft (\r
IN OUT RED_BLACK_TREE_NODE *Pivot,\r
OUT RED_BLACK_TREE_NODE **NewRoot\r
)\r
{\r
- RED_BLACK_TREE_NODE *Parent, *RightChild, *RightLeftChild;\r
+ RED_BLACK_TREE_NODE *Parent;\r
+ RED_BLACK_TREE_NODE *RightChild;\r
+ RED_BLACK_TREE_NODE *RightLeftChild;\r
\r
Parent = Pivot->Parent;\r
RightChild = Pivot->Right;\r
IN VOID *UserStruct\r
)\r
{\r
- RED_BLACK_TREE_NODE *Tmp, *Parent;\r
+ RED_BLACK_TREE_NODE *Tmp;\r
+ RED_BLACK_TREE_NODE *Parent;\r
INTN Result;\r
RETURN_STATUS Status;\r
RED_BLACK_TREE_NODE *NewRoot;\r
\r
NewRoot = Tree->Root;\r
while (Tmp != NewRoot && Parent->Color == RedBlackTreeRed) {\r
- RED_BLACK_TREE_NODE *GrandParent, *Uncle;\r
+ RED_BLACK_TREE_NODE *GrandParent;\r
+ RED_BLACK_TREE_NODE *Uncle;\r
\r
//\r
// Tmp is not the root node. Tmp is red. Tmp's parent is red. (Breaking\r
\r
@return If Node is NULL or colored black.\r
**/\r
-\r
-STATIC\r
BOOLEAN\r
NodeIsNullOrBlack (\r
IN CONST RED_BLACK_TREE_NODE *Node\r
)\r
{\r
- return Node == NULL || Node->Color == RedBlackTreeBlack;\r
+ return (BOOLEAN)(Node == NULL || Node->Color == RedBlackTreeBlack);\r
}\r
\r
\r
)\r
{\r
RED_BLACK_TREE_NODE *NewRoot;\r
- RED_BLACK_TREE_NODE *OrigLeftChild, *OrigRightChild, *OrigParent;\r
- RED_BLACK_TREE_NODE *Child, *Parent;\r
+ RED_BLACK_TREE_NODE *OrigLeftChild;\r
+ RED_BLACK_TREE_NODE *OrigRightChild;\r
+ RED_BLACK_TREE_NODE *OrigParent;\r
+ RED_BLACK_TREE_NODE *Child;\r
+ RED_BLACK_TREE_NODE *Parent;\r
RED_BLACK_TREE_COLOR ColorOfUnlinked;\r
\r
NewRoot = Tree->Root;\r
// C <--- ToRelink\r
//\r
Parent->Left = Child;\r
- if (Child) {\r
+ if (Child != NULL) {\r
Child->Parent = Parent;\r
}\r
\r
// Rotations in the loop preserve property #4.\r
//\r
while (Child != NewRoot && NodeIsNullOrBlack (Child)) {\r
- RED_BLACK_TREE_NODE *Sibling, *LeftNephew, *RightNephew;\r
+ RED_BLACK_TREE_NODE *Sibling;\r
+ RED_BLACK_TREE_NODE *LeftNephew;\r
+ RED_BLACK_TREE_NODE *RightNephew;\r
\r
if (Child == Parent->Left) {\r
Sibling = Parent->Right;\r
\r
@retval The black-height of Node's parent.\r
**/\r
-STATIC\r
UINT32\r
RedBlackTreeRecursiveCheck (\r
IN CONST RED_BLACK_TREE_NODE *Node\r
)\r
{\r
- UINT32 LeftHeight, RightHeight;\r
+ UINT32 LeftHeight;\r
+ UINT32 RightHeight;\r
\r
//\r
// property #2\r
\r
@param[in] Tree The tree to validate.\r
**/\r
-STATIC\r
VOID\r
RedBlackTreeValidate (\r
IN CONST RED_BLACK_TREE *Tree\r
)\r
{\r
UINT32 BlackHeight;\r
- UINT32 ForwardCount, BackwardCount;\r
- CONST RED_BLACK_TREE_NODE *Last, *Node;\r
+ UINT32 ForwardCount;\r
+ UINT32 BackwardCount;\r
+ CONST RED_BLACK_TREE_NODE *Last;\r
+ CONST RED_BLACK_TREE_NODE *Node;\r
\r
DEBUG ((DEBUG_VERBOSE, "%a: Tree=%p\n", __FUNCTION__, Tree));\r
\r