MdePkg: BaseOrderedCollectionRedBlackTreeLib: improve coding style

- The edk2 coding style prefers each variable declaration to stand on
  its own line.
- Internal linkage (ie. STATIC) functions have caused problems with
  source level debugging before, so we generally avoid STATIC in MdePkg.
- Even forward declarations of functions should carry full comment
  blocks.
- Nullity checks in controlling expressions should be spelled out
  explicitly, as (Ptr != NULL).

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15843 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Eric Dong 2014-08-20 02:06:12 +00:00 committed by ydong10
parent 30cad98e5f
commit 64fabae54b
1 changed files with 36 additions and 22 deletions

View File

@ -11,6 +11,7 @@
The implementation is also useful as a fast priority queue. The implementation is also useful as a fast priority queue.
Copyright (C) 2014, Red Hat, Inc. Copyright (C) 2014, Red Hat, Inc.
Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this under the terms and conditions of the BSD License that accompanies this
@ -75,12 +76,17 @@ OrderedCollectionUserStruct (
return Node->UserStruct; return Node->UserStruct;
} }
/**
A slow function that asserts that the tree is a valid red-black tree, and
that it orders user structures correctly.
// Read-only operation.
// Forward declaration of internal, unit test helper function. See
// specification and function definition later. This function uses the stack for recursion and is not recommended for
// "production use".
STATIC
@param[in] Tree The tree to validate.
**/
VOID VOID
RedBlackTreeValidate ( RedBlackTreeValidate (
IN CONST RED_BLACK_TREE *Tree IN CONST RED_BLACK_TREE *Tree
@ -417,14 +423,15 @@ OrderedCollectionPrev (
the root of the tree), then the function stores the the root of the tree), then the function stores the
new root node of the tree in NewRoot. new root node of the tree in NewRoot.
**/ **/
STATIC
VOID VOID
RedBlackTreeRotateRight ( RedBlackTreeRotateRight (
IN OUT RED_BLACK_TREE_NODE *Pivot, IN OUT RED_BLACK_TREE_NODE *Pivot,
OUT RED_BLACK_TREE_NODE **NewRoot OUT RED_BLACK_TREE_NODE **NewRoot
) )
{ {
RED_BLACK_TREE_NODE *Parent, *LeftChild, *LeftRightChild; RED_BLACK_TREE_NODE *Parent;
RED_BLACK_TREE_NODE *LeftChild;
RED_BLACK_TREE_NODE *LeftRightChild;
Parent = Pivot->Parent; Parent = Pivot->Parent;
LeftChild = Pivot->Left; LeftChild = Pivot->Left;
@ -481,14 +488,15 @@ RedBlackTreeRotateRight (
the root of the tree), then the function stores the the root of the tree), then the function stores the
new root node of the tree in NewRoot. new root node of the tree in NewRoot.
**/ **/
STATIC
VOID VOID
RedBlackTreeRotateLeft ( RedBlackTreeRotateLeft (
IN OUT RED_BLACK_TREE_NODE *Pivot, IN OUT RED_BLACK_TREE_NODE *Pivot,
OUT RED_BLACK_TREE_NODE **NewRoot OUT RED_BLACK_TREE_NODE **NewRoot
) )
{ {
RED_BLACK_TREE_NODE *Parent, *RightChild, *RightLeftChild; RED_BLACK_TREE_NODE *Parent;
RED_BLACK_TREE_NODE *RightChild;
RED_BLACK_TREE_NODE *RightLeftChild;
Parent = Pivot->Parent; Parent = Pivot->Parent;
RightChild = Pivot->Right; RightChild = Pivot->Right;
@ -582,7 +590,8 @@ OrderedCollectionInsert (
IN VOID *UserStruct IN VOID *UserStruct
) )
{ {
RED_BLACK_TREE_NODE *Tmp, *Parent; RED_BLACK_TREE_NODE *Tmp;
RED_BLACK_TREE_NODE *Parent;
INTN Result; INTN Result;
RETURN_STATUS Status; RETURN_STATUS Status;
RED_BLACK_TREE_NODE *NewRoot; RED_BLACK_TREE_NODE *NewRoot;
@ -671,7 +680,8 @@ OrderedCollectionInsert (
NewRoot = Tree->Root; NewRoot = Tree->Root;
while (Tmp != NewRoot && Parent->Color == RedBlackTreeRed) { while (Tmp != NewRoot && Parent->Color == RedBlackTreeRed) {
RED_BLACK_TREE_NODE *GrandParent, *Uncle; RED_BLACK_TREE_NODE *GrandParent;
RED_BLACK_TREE_NODE *Uncle;
// //
// Tmp is not the root node. Tmp is red. Tmp's parent is red. (Breaking // Tmp is not the root node. Tmp is red. Tmp's parent is red. (Breaking
@ -831,8 +841,6 @@ Done:
@return If Node is NULL or colored black. @return If Node is NULL or colored black.
**/ **/
STATIC
BOOLEAN BOOLEAN
NodeIsNullOrBlack ( NodeIsNullOrBlack (
IN CONST RED_BLACK_TREE_NODE *Node IN CONST RED_BLACK_TREE_NODE *Node
@ -916,8 +924,11 @@ OrderedCollectionDelete (
) )
{ {
RED_BLACK_TREE_NODE *NewRoot; RED_BLACK_TREE_NODE *NewRoot;
RED_BLACK_TREE_NODE *OrigLeftChild, *OrigRightChild, *OrigParent; RED_BLACK_TREE_NODE *OrigLeftChild;
RED_BLACK_TREE_NODE *Child, *Parent; RED_BLACK_TREE_NODE *OrigRightChild;
RED_BLACK_TREE_NODE *OrigParent;
RED_BLACK_TREE_NODE *Child;
RED_BLACK_TREE_NODE *Parent;
RED_BLACK_TREE_COLOR ColorOfUnlinked; RED_BLACK_TREE_COLOR ColorOfUnlinked;
NewRoot = Tree->Root; NewRoot = Tree->Root;
@ -1024,7 +1035,7 @@ OrderedCollectionDelete (
// C <--- ToRelink // C <--- ToRelink
// //
Parent->Left = Child; Parent->Left = Child;
if (Child) { if (Child != NULL) {
Child->Parent = Parent; Child->Parent = Parent;
} }
@ -1124,7 +1135,9 @@ OrderedCollectionDelete (
// Rotations in the loop preserve property #4. // Rotations in the loop preserve property #4.
// //
while (Child != NewRoot && NodeIsNullOrBlack (Child)) { while (Child != NewRoot && NodeIsNullOrBlack (Child)) {
RED_BLACK_TREE_NODE *Sibling, *LeftNephew, *RightNephew; RED_BLACK_TREE_NODE *Sibling;
RED_BLACK_TREE_NODE *LeftNephew;
RED_BLACK_TREE_NODE *RightNephew;
if (Child == Parent->Left) { if (Child == Parent->Left) {
Sibling = Parent->Right; Sibling = Parent->Right;
@ -1337,13 +1350,13 @@ OrderedCollectionDelete (
@retval The black-height of Node's parent. @retval The black-height of Node's parent.
**/ **/
STATIC
UINT32 UINT32
RedBlackTreeRecursiveCheck ( RedBlackTreeRecursiveCheck (
IN CONST RED_BLACK_TREE_NODE *Node IN CONST RED_BLACK_TREE_NODE *Node
) )
{ {
UINT32 LeftHeight, RightHeight; UINT32 LeftHeight;
UINT32 RightHeight;
// //
// property #2 // property #2
@ -1387,15 +1400,16 @@ RedBlackTreeRecursiveCheck (
@param[in] Tree The tree to validate. @param[in] Tree The tree to validate.
**/ **/
STATIC
VOID VOID
RedBlackTreeValidate ( RedBlackTreeValidate (
IN CONST RED_BLACK_TREE *Tree IN CONST RED_BLACK_TREE *Tree
) )
{ {
UINT32 BlackHeight; UINT32 BlackHeight;
UINT32 ForwardCount, BackwardCount; UINT32 ForwardCount;
CONST RED_BLACK_TREE_NODE *Last, *Node; UINT32 BackwardCount;
CONST RED_BLACK_TREE_NODE *Last;
CONST RED_BLACK_TREE_NODE *Node;
DEBUG ((DEBUG_VERBOSE, "%a: Tree=%p\n", __FUNCTION__, Tree)); DEBUG ((DEBUG_VERBOSE, "%a: Tree=%p\n", __FUNCTION__, Tree));