26} RED_BLACK_TREE_COLOR;
40 RED_BLACK_TREE_USER_COMPARE UserStructCompare;
41 RED_BLACK_TREE_KEY_COMPARE KeyCompare;
49 RED_BLACK_TREE_COLOR Color;
69 return Node->UserStruct;
110 IN RED_BLACK_TREE_USER_COMPARE UserStructCompare,
111 IN RED_BLACK_TREE_KEY_COMPARE KeyCompare
122 Tree->UserStructCompare = UserStructCompare;
123 Tree->KeyCompare = KeyCompare;
149 return (BOOLEAN)(Tree->Root ==
NULL);
201 while (Node !=
NULL) {
204 Result = Tree->KeyCompare (StandaloneKey, Node->UserStruct);
209 Node = (Result < 0) ? Node->Left : Node->Right;
241 while (Node->Left !=
NULL) {
274 while (Node->Right !=
NULL) {
314 while (Walk->Left !=
NULL) {
326 Walk =
Child->Parent;
327 while (Walk !=
NULL &&
Child == Walk->Right) {
329 Walk =
Child->Parent;
368 while (Walk->Right !=
NULL) {
380 Walk =
Child->Parent;
381 while (Walk !=
NULL &&
Child == Walk->Left) {
383 Walk =
Child->Parent;
431 Parent = Pivot->Parent;
432 LeftChild = Pivot->Left;
433 LeftRightChild = LeftChild->Right;
435 Pivot->Left = LeftRightChild;
436 if (LeftRightChild !=
NULL) {
437 LeftRightChild->Parent = Pivot;
440 LeftChild->Parent = Parent;
441 if (Parent ==
NULL) {
442 *NewRoot = LeftChild;
444 if (Pivot == Parent->Left) {
445 Parent->Left = LeftChild;
447 Parent->Right = LeftChild;
451 LeftChild->Right = Pivot;
452 Pivot->Parent = LeftChild;
497 Parent = Pivot->Parent;
498 RightChild = Pivot->Right;
499 RightLeftChild = RightChild->Left;
501 Pivot->Right = RightLeftChild;
502 if (RightLeftChild !=
NULL) {
503 RightLeftChild->Parent = Pivot;
506 RightChild->Parent = Parent;
507 if (Parent ==
NULL) {
508 *NewRoot = RightChild;
510 if (Pivot == Parent->Left) {
511 Parent->Left = RightChild;
513 Parent->Right = RightChild;
517 RightChild->Left = Pivot;
518 Pivot->Parent = RightChild;
593 RETURN_STATUS Status;
604 while (Tmp !=
NULL) {
605 Result = Tree->UserStructCompare (UserStruct, Tmp->UserStruct);
611 Tmp = (Result < 0) ? Tmp->Left : Tmp->Right;
639 Tmp->UserStruct = UserStruct;
645 Tmp->Parent = Parent;
648 if (Parent ==
NULL) {
650 Tmp->Color = RedBlackTreeBlack;
661 Tmp->Color = RedBlackTreeRed;
683 NewRoot = Tree->Root;
684 while (Tmp != NewRoot && Parent->Color == RedBlackTreeRed) {
698 GrandParent = Parent->Parent;
700 if (Parent == GrandParent->Left) {
701 Uncle = GrandParent->Right;
702 if ((Uncle !=
NULL) && (Uncle->Color == RedBlackTreeRed)) {
711 Parent->Color = RedBlackTreeBlack;
712 Uncle->Color = RedBlackTreeBlack;
713 GrandParent->Color = RedBlackTreeRed;
732 Parent = Tmp->Parent;
739 if (Tmp == Parent->Right) {
755 Parent = Tmp->Parent;
767 ASSERT (GrandParent == Parent->Parent);
770 Parent->Color = RedBlackTreeBlack;
771 GrandParent->Color = RedBlackTreeRed;
804 Uncle = GrandParent->Left;
805 if ((Uncle !=
NULL) && (Uncle->Color == RedBlackTreeRed)) {
806 Parent->Color = RedBlackTreeBlack;
807 Uncle->Color = RedBlackTreeBlack;
808 GrandParent->Color = RedBlackTreeRed;
810 Parent = Tmp->Parent;
812 if (Tmp == Parent->Left) {
815 Parent = Tmp->Parent;
816 ASSERT (GrandParent == Parent->Parent);
819 Parent->Color = RedBlackTreeBlack;
820 GrandParent->Color = RedBlackTreeRed;
826 NewRoot->Color = RedBlackTreeBlack;
827 Tree->Root = NewRoot;
852 return (BOOLEAN)(Node ==
NULL || Node->Color == RedBlackTreeBlack);
925 OUT VOID **UserStruct OPTIONAL
934 RED_BLACK_TREE_COLOR ColorOfUnlinked;
936 NewRoot = Tree->Root;
937 OrigLeftChild = Node->Left,
938 OrigRightChild = Node->Right,
939 OrigParent = Node->Parent;
941 if (UserStruct !=
NULL) {
942 *UserStruct = Node->UserStruct;
952 if ((OrigLeftChild ==
NULL) || (OrigRightChild ==
NULL)) {
960 Child = (OrigLeftChild !=
NULL) ? OrigLeftChild : OrigRightChild;
961 ColorOfUnlinked = Node->Color;
964 Child->Parent = Parent;
967 if (OrigParent ==
NULL) {
970 if (Node == OrigParent->Left) {
971 OrigParent->Left =
Child;
973 OrigParent->Right =
Child;
992 ToRelink = OrigRightChild;
993 if (ToRelink->Left ==
NULL) {
1005 Parent = OrigRightChild;
1006 Child = OrigRightChild->Right;
1009 ToRelink = ToRelink->Left;
1010 }
while (ToRelink->Left !=
NULL);
1024 Parent = ToRelink->Parent;
1025 Child = ToRelink->Right;
1040 Parent->Left =
Child;
1042 Child->Parent = Parent;
1058 ToRelink->Right = OrigRightChild;
1059 OrigRightChild->Parent = ToRelink;
1078 ToRelink->Left = OrigLeftChild;
1079 OrigLeftChild->Parent = ToRelink;
1084 ColorOfUnlinked = ToRelink->Color;
1085 ToRelink->Color = Node->Color;
1102 ToRelink->Parent = OrigParent;
1103 if (OrigParent ==
NULL) {
1106 if (Node == OrigParent->Left) {
1107 OrigParent->Left = ToRelink;
1109 OrigParent->Right = ToRelink;
1122 if (ColorOfUnlinked == RedBlackTreeBlack) {
1145 if (
Child == Parent->Left) {
1146 Sibling = Parent->Right;
1160 ASSERT (Sibling !=
NULL);
1161 if (Sibling->Color == RedBlackTreeRed) {
1174 Sibling->Color = RedBlackTreeBlack;
1175 Parent->Color = RedBlackTreeRed;
1177 Sibling = Parent->Right;
1181 ASSERT (Sibling !=
NULL);
1188 ASSERT (Sibling->Color == RedBlackTreeBlack);
1189 LeftNephew = Sibling->Left;
1190 RightNephew = Sibling->Right;
1212 Sibling->Color = RedBlackTreeRed;
1214 Parent = Parent->Parent;
1242 LeftNephew->Color = RedBlackTreeBlack;
1243 Sibling->Color = RedBlackTreeRed;
1245 Sibling = Parent->Right;
1246 RightNephew = Sibling->Right;
1256 ASSERT (RightNephew !=
NULL);
1257 ASSERT (RightNephew->Color == RedBlackTreeRed);
1258 ASSERT (Sibling !=
NULL);
1259 ASSERT (Sibling->Color == RedBlackTreeBlack);
1286 Sibling->Color = Parent->Color;
1287 Parent->Color = RedBlackTreeBlack;
1288 RightNephew->Color = RedBlackTreeBlack;
1299 Sibling = Parent->Left;
1300 ASSERT (Sibling !=
NULL);
1301 if (Sibling->Color == RedBlackTreeRed) {
1302 Sibling->Color = RedBlackTreeBlack;
1303 Parent->Color = RedBlackTreeRed;
1305 Sibling = Parent->Left;
1306 ASSERT (Sibling !=
NULL);
1309 ASSERT (Sibling->Color == RedBlackTreeBlack);
1310 RightNephew = Sibling->Right;
1311 LeftNephew = Sibling->Left;
1315 Sibling->Color = RedBlackTreeRed;
1317 Parent = Parent->Parent;
1320 RightNephew->Color = RedBlackTreeBlack;
1321 Sibling->Color = RedBlackTreeRed;
1323 Sibling = Parent->Left;
1324 LeftNephew = Sibling->Left;
1327 ASSERT (LeftNephew !=
NULL);
1328 ASSERT (LeftNephew->Color == RedBlackTreeRed);
1329 ASSERT (Sibling !=
NULL);
1330 ASSERT (Sibling->Color == RedBlackTreeBlack);
1331 Sibling->Color = Parent->Color;
1332 Parent->Color = RedBlackTreeBlack;
1333 LeftNephew->Color = RedBlackTreeBlack;
1341 Child->Color = RedBlackTreeBlack;
1345 Tree->Root = NewRoot;
1377 ASSERT (Node->Color == RedBlackTreeRed || Node->Color == RedBlackTreeBlack);
1382 if (Node->Color == RedBlackTreeRed) {
1392 ASSERT (LeftHeight == RightHeight);
1394 return (Node->Color == RedBlackTreeBlack) + LeftHeight;
1414 UINT32 ForwardCount;
1415 UINT32 BackwardCount;
1419 DEBUG ((DEBUG_VERBOSE,
"%a: Tree=%p\n", __func__, Tree));
1435 ForwardCount = (Last !=
NULL);
1439 ASSERT (Tree->UserStructCompare (Last->UserStruct, Node->UserStruct) < 0);
1448 BackwardCount = (Last !=
NULL);
1452 ASSERT (Tree->UserStructCompare (Last->UserStruct, Node->UserStruct) > 0);
1457 ASSERT (ForwardCount == BackwardCount);
1461 "%a: Tree=%p BlackHeight=%Ld Count=%Ld\n",
RED_BLACK_TREE *EFIAPI OrderedCollectionInit(IN RED_BLACK_TREE_USER_COMPARE UserStructCompare, IN RED_BLACK_TREE_KEY_COMPARE KeyCompare)
UINT32 RedBlackTreeRecursiveCheck(IN CONST RED_BLACK_TREE_NODE *Node)
VOID *EFIAPI OrderedCollectionUserStruct(IN CONST RED_BLACK_TREE_NODE *Node)
RED_BLACK_TREE_NODE *EFIAPI OrderedCollectionPrev(IN CONST RED_BLACK_TREE_NODE *Node)
BOOLEAN EFIAPI OrderedCollectionIsEmpty(IN CONST RED_BLACK_TREE *Tree)
VOID RedBlackTreeValidate(IN CONST RED_BLACK_TREE *Tree)
RED_BLACK_TREE_NODE *EFIAPI OrderedCollectionMin(IN CONST RED_BLACK_TREE *Tree)
VOID EFIAPI OrderedCollectionDelete(IN OUT RED_BLACK_TREE *Tree, IN RED_BLACK_TREE_NODE *Node, OUT VOID **UserStruct OPTIONAL)
VOID RedBlackTreeRotateRight(IN OUT RED_BLACK_TREE_NODE *Pivot, OUT RED_BLACK_TREE_NODE **NewRoot)
BOOLEAN NodeIsNullOrBlack(IN CONST RED_BLACK_TREE_NODE *Node)
VOID EFIAPI OrderedCollectionUninit(IN RED_BLACK_TREE *Tree)
VOID RedBlackTreeRotateLeft(IN OUT RED_BLACK_TREE_NODE *Pivot, OUT RED_BLACK_TREE_NODE **NewRoot)
RED_BLACK_TREE_NODE *EFIAPI OrderedCollectionMax(IN CONST RED_BLACK_TREE *Tree)
RETURN_STATUS EFIAPI OrderedCollectionInsert(IN OUT RED_BLACK_TREE *Tree, OUT RED_BLACK_TREE_NODE **Node OPTIONAL, IN VOID *UserStruct)
RED_BLACK_TREE_NODE *EFIAPI OrderedCollectionFind(IN CONST RED_BLACK_TREE *Tree, IN CONST VOID *StandaloneKey)
RED_BLACK_TREE_NODE *EFIAPI OrderedCollectionNext(IN CONST RED_BLACK_TREE_NODE *Node)
NODE Child(IN NODE LoopVar6, IN UINT8 LoopVar5)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define RETURN_OUT_OF_RESOURCES
#define RETURN_ALREADY_STARTED
#define DEBUG(Expression)
INTN(EFIAPI * ORDERED_COLLECTION_USER_COMPARE)(IN CONST VOID *UserStruct1, IN CONST VOID *UserStruct2)
INTN(EFIAPI * ORDERED_COLLECTION_KEY_COMPARE)(IN CONST VOID *StandaloneKey, IN CONST VOID *UserStruct)
#define FeaturePcdGet(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)