]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: BaseOrderedCollectionRedBlackTreeLib: improve coding style
authorEric Dong <eric.dong@intel.com>
Wed, 20 Aug 2014 02:06:12 +0000 (02:06 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 20 Aug 2014 02:06:12 +0000 (02:06 +0000)
- 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

MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.c

index b37caf239aa589092c7842fd337bbb7ec968433f..8d18a4b2bf78519b531fe2fbd3389aabed0eef80 100644 (file)
@@ -11,6 +11,7 @@
   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
@@ -75,12 +76,17 @@ OrderedCollectionUserStruct (
   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
-//\r
-// Forward declaration of internal, unit test helper function. See\r
-// specification and function definition later.\r
-//\r
-STATIC\r
+  Read-only operation.\r
+\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
@@ -417,14 +423,15 @@ OrderedCollectionPrev (
                           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
@@ -481,14 +488,15 @@ RedBlackTreeRotateRight (
                           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
@@ -582,7 +590,8 @@ OrderedCollectionInsert (
   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
@@ -671,7 +680,8 @@ OrderedCollectionInsert (
 \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
@@ -831,8 +841,6 @@ Done:
 \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
@@ -916,8 +924,11 @@ OrderedCollectionDelete (
   )\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
@@ -1024,7 +1035,7 @@ OrderedCollectionDelete (
       //                                 C <--- ToRelink\r
       //\r
       Parent->Left = Child;\r
-      if (Child) {\r
+      if (Child != NULL) {\r
         Child->Parent = Parent;\r
       }\r
 \r
@@ -1124,7 +1135,9 @@ OrderedCollectionDelete (
     // 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
@@ -1337,13 +1350,13 @@ OrderedCollectionDelete (
 \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
@@ -1387,15 +1400,16 @@ RedBlackTreeRecursiveCheck (
 \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