Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib
- Timestamp:
- Apr 14, 2023 3:17:44 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 156854
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.c
r80721 r99404 31 31 // the implementation closely. 32 32 // 33 typedef ORDERED_COLLECTION RED_BLACK_TREE;34 typedef ORDERED_COLLECTION_ENTRY RED_BLACK_TREE_NODE;35 typedef ORDERED_COLLECTION_USER_COMPARE RED_BLACK_TREE_USER_COMPARE;36 typedef ORDERED_COLLECTION_KEY_COMPARE RED_BLACK_TREE_KEY_COMPARE;33 typedef ORDERED_COLLECTION RED_BLACK_TREE; 34 typedef ORDERED_COLLECTION_ENTRY RED_BLACK_TREE_NODE; 35 typedef ORDERED_COLLECTION_USER_COMPARE RED_BLACK_TREE_USER_COMPARE; 36 typedef ORDERED_COLLECTION_KEY_COMPARE RED_BLACK_TREE_KEY_COMPARE; 37 37 38 38 struct ORDERED_COLLECTION { 39 RED_BLACK_TREE_NODE *Root;40 RED_BLACK_TREE_USER_COMPARE UserStructCompare;41 RED_BLACK_TREE_KEY_COMPARE KeyCompare;39 RED_BLACK_TREE_NODE *Root; 40 RED_BLACK_TREE_USER_COMPARE UserStructCompare; 41 RED_BLACK_TREE_KEY_COMPARE KeyCompare; 42 42 }; 43 43 44 44 struct ORDERED_COLLECTION_ENTRY { 45 VOID *UserStruct;46 RED_BLACK_TREE_NODE *Parent;47 RED_BLACK_TREE_NODE *Left;48 RED_BLACK_TREE_NODE *Right;49 RED_BLACK_TREE_COLOR Color;45 VOID *UserStruct; 46 RED_BLACK_TREE_NODE *Parent; 47 RED_BLACK_TREE_NODE *Left; 48 RED_BLACK_TREE_NODE *Right; 49 RED_BLACK_TREE_COLOR Color; 50 50 }; 51 52 51 53 52 /** … … 65 64 EFIAPI 66 65 OrderedCollectionUserStruct ( 67 IN CONST RED_BLACK_TREE_NODE *Node66 IN CONST RED_BLACK_TREE_NODE *Node 68 67 ) 69 68 { … … 84 83 VOID 85 84 RedBlackTreeValidate ( 86 IN CONST RED_BLACK_TREE *Tree85 IN CONST RED_BLACK_TREE *Tree 87 86 ); 88 89 87 90 88 /** … … 110 108 EFIAPI 111 109 OrderedCollectionInit ( 112 IN RED_BLACK_TREE_USER_COMPARE UserStructCompare,113 IN RED_BLACK_TREE_KEY_COMPARE KeyCompare114 ) 115 { 116 RED_BLACK_TREE *Tree;110 IN RED_BLACK_TREE_USER_COMPARE UserStructCompare, 111 IN RED_BLACK_TREE_KEY_COMPARE KeyCompare 112 ) 113 { 114 RED_BLACK_TREE *Tree; 117 115 118 116 Tree = AllocatePool (sizeof *Tree); … … 128 126 RedBlackTreeValidate (Tree); 129 127 } 128 130 129 return Tree; 131 130 } 132 133 131 134 132 /** … … 146 144 EFIAPI 147 145 OrderedCollectionIsEmpty ( 148 IN CONST RED_BLACK_TREE *Tree146 IN CONST RED_BLACK_TREE *Tree 149 147 ) 150 148 { 151 149 return (BOOLEAN)(Tree->Root == NULL); 152 150 } 153 154 151 155 152 /** … … 168 165 EFIAPI 169 166 OrderedCollectionUninit ( 170 IN RED_BLACK_TREE *Tree167 IN RED_BLACK_TREE *Tree 171 168 ) 172 169 { … … 174 171 FreePool (Tree); 175 172 } 176 177 173 178 174 /** … … 196 192 EFIAPI 197 193 OrderedCollectionFind ( 198 IN CONST RED_BLACK_TREE *Tree,199 IN CONST VOID *StandaloneKey200 ) 201 { 202 RED_BLACK_TREE_NODE *Node;194 IN CONST RED_BLACK_TREE *Tree, 195 IN CONST VOID *StandaloneKey 196 ) 197 { 198 RED_BLACK_TREE_NODE *Node; 203 199 204 200 Node = Tree->Root; 205 201 while (Node != NULL) { 206 INTN Result;202 INTN Result; 207 203 208 204 Result = Tree->KeyCompare (StandaloneKey, Node->UserStruct); … … 210 206 break; 211 207 } 208 212 209 Node = (Result < 0) ? Node->Left : Node->Right; 213 210 } 211 214 212 return Node; 215 213 } 216 217 214 218 215 /** … … 232 229 EFIAPI 233 230 OrderedCollectionMin ( 234 IN CONST RED_BLACK_TREE *Tree235 ) 236 { 237 RED_BLACK_TREE_NODE *Node;231 IN CONST RED_BLACK_TREE *Tree 232 ) 233 { 234 RED_BLACK_TREE_NODE *Node; 238 235 239 236 Node = Tree->Root; … … 241 238 return NULL; 242 239 } 240 243 241 while (Node->Left != NULL) { 244 242 Node = Node->Left; 245 243 } 244 246 245 return Node; 247 246 } 248 249 247 250 248 /** … … 264 262 EFIAPI 265 263 OrderedCollectionMax ( 266 IN CONST RED_BLACK_TREE *Tree267 ) 268 { 269 RED_BLACK_TREE_NODE *Node;264 IN CONST RED_BLACK_TREE *Tree 265 ) 266 { 267 RED_BLACK_TREE_NODE *Node; 270 268 271 269 Node = Tree->Root; … … 273 271 return NULL; 274 272 } 273 275 274 while (Node->Right != NULL) { 276 275 Node = Node->Right; 277 276 } 277 278 278 return Node; 279 279 } 280 281 280 282 281 /** … … 297 296 EFIAPI 298 297 OrderedCollectionNext ( 299 IN CONST RED_BLACK_TREE_NODE *Node300 ) 301 { 302 RED_BLACK_TREE_NODE *Walk;303 CONST RED_BLACK_TREE_NODE *Child;298 IN CONST RED_BLACK_TREE_NODE *Node 299 ) 300 { 301 RED_BLACK_TREE_NODE *Walk; 302 CONST RED_BLACK_TREE_NODE *Child; 304 303 305 304 if (Node == NULL) { … … 316 315 Walk = Walk->Left; 317 316 } 317 318 318 return Walk; 319 319 } … … 324 324 // 325 325 Child = Node; 326 Walk = Child->Parent;326 Walk = Child->Parent; 327 327 while (Walk != NULL && Child == Walk->Right) { 328 328 Child = Walk; 329 Walk = Child->Parent; 330 } 329 Walk = Child->Parent; 330 } 331 331 332 return Walk; 332 333 } 333 334 334 335 335 /** … … 350 350 EFIAPI 351 351 OrderedCollectionPrev ( 352 IN CONST RED_BLACK_TREE_NODE *Node353 ) 354 { 355 RED_BLACK_TREE_NODE *Walk;356 CONST RED_BLACK_TREE_NODE *Child;352 IN CONST RED_BLACK_TREE_NODE *Node 353 ) 354 { 355 RED_BLACK_TREE_NODE *Walk; 356 CONST RED_BLACK_TREE_NODE *Child; 357 357 358 358 if (Node == NULL) { … … 369 369 Walk = Walk->Right; 370 370 } 371 371 372 return Walk; 372 373 } … … 377 378 // 378 379 Child = Node; 379 Walk = Child->Parent;380 Walk = Child->Parent; 380 381 while (Walk != NULL && Child == Walk->Left) { 381 382 Child = Walk; 382 Walk = Child->Parent; 383 } 383 Walk = Child->Parent; 384 } 385 384 386 return Walk; 385 387 } 386 387 388 388 389 /** … … 420 421 VOID 421 422 RedBlackTreeRotateRight ( 422 IN OUT RED_BLACK_TREE_NODE *Pivot,423 OUT RED_BLACK_TREE_NODE **NewRoot424 ) 425 { 426 RED_BLACK_TREE_NODE *Parent;427 RED_BLACK_TREE_NODE *LeftChild;428 RED_BLACK_TREE_NODE *LeftRightChild;423 IN OUT RED_BLACK_TREE_NODE *Pivot, 424 OUT RED_BLACK_TREE_NODE **NewRoot 425 ) 426 { 427 RED_BLACK_TREE_NODE *Parent; 428 RED_BLACK_TREE_NODE *LeftChild; 429 RED_BLACK_TREE_NODE *LeftRightChild; 429 430 430 431 Parent = Pivot->Parent; … … 436 437 LeftRightChild->Parent = Pivot; 437 438 } 439 438 440 LeftChild->Parent = Parent; 439 441 if (Parent == NULL) { … … 446 448 } 447 449 } 450 448 451 LeftChild->Right = Pivot; 449 Pivot->Parent = LeftChild; 450 } 451 452 Pivot->Parent = LeftChild; 453 } 452 454 453 455 /** … … 485 487 VOID 486 488 RedBlackTreeRotateLeft ( 487 IN OUT RED_BLACK_TREE_NODE *Pivot,488 OUT RED_BLACK_TREE_NODE **NewRoot489 ) 490 { 491 RED_BLACK_TREE_NODE *Parent;492 RED_BLACK_TREE_NODE *RightChild;493 RED_BLACK_TREE_NODE *RightLeftChild;489 IN OUT RED_BLACK_TREE_NODE *Pivot, 490 OUT RED_BLACK_TREE_NODE **NewRoot 491 ) 492 { 493 RED_BLACK_TREE_NODE *Parent; 494 RED_BLACK_TREE_NODE *RightChild; 495 RED_BLACK_TREE_NODE *RightLeftChild; 494 496 495 497 Parent = Pivot->Parent; … … 501 503 RightLeftChild->Parent = Pivot; 502 504 } 505 503 506 RightChild->Parent = Parent; 504 507 if (Parent == NULL) { … … 511 514 } 512 515 } 516 513 517 RightChild->Left = Pivot; 514 Pivot->Parent = RightChild; 515 } 516 518 Pivot->Parent = RightChild; 519 } 517 520 518 521 /** … … 580 583 EFIAPI 581 584 OrderedCollectionInsert ( 582 IN OUT RED_BLACK_TREE *Tree,583 OUT RED_BLACK_TREE_NODE **Node OPTIONAL,584 IN VOID *UserStruct585 ) 586 { 587 RED_BLACK_TREE_NODE *Tmp;588 RED_BLACK_TREE_NODE *Parent;589 INTN Result;590 RETURN_STATUS Status;591 RED_BLACK_TREE_NODE *NewRoot;592 593 Tmp = Tree->Root;585 IN OUT RED_BLACK_TREE *Tree, 586 OUT RED_BLACK_TREE_NODE **Node OPTIONAL, 587 IN VOID *UserStruct 588 ) 589 { 590 RED_BLACK_TREE_NODE *Tmp; 591 RED_BLACK_TREE_NODE *Parent; 592 INTN Result; 593 RETURN_STATUS Status; 594 RED_BLACK_TREE_NODE *NewRoot; 595 596 Tmp = Tree->Root; 594 597 Parent = NULL; 595 598 Result = 0; … … 604 607 break; 605 608 } 609 606 610 Parent = Tmp; 607 Tmp = (Result < 0) ? Tmp->Left : Tmp->Right;611 Tmp = (Result < 0) ? Tmp->Left : Tmp->Right; 608 612 } 609 613 … … 612 616 *Node = Tmp; 613 617 } 618 614 619 Status = RETURN_ALREADY_STARTED; 615 620 goto Done; … … 624 629 goto Done; 625 630 } 631 626 632 if (Node != NULL) { 627 633 *Node = Tmp; … … 638 644 // 639 645 Tmp->Parent = Parent; 640 Tmp->Left = NULL;641 Tmp->Right = NULL;646 Tmp->Left = NULL; 647 Tmp->Right = NULL; 642 648 if (Parent == NULL) { 643 649 Tree->Root = Tmp; 644 650 Tmp->Color = RedBlackTreeBlack; 645 Status = RETURN_SUCCESS;651 Status = RETURN_SUCCESS; 646 652 goto Done; 647 653 } 654 648 655 if (Result < 0) { 649 656 Parent->Left = Tmp; … … 651 658 Parent->Right = Tmp; 652 659 } 660 653 661 Tmp->Color = RedBlackTreeRed; 654 662 … … 675 683 NewRoot = Tree->Root; 676 684 while (Tmp != NewRoot && Parent->Color == RedBlackTreeRed) { 677 RED_BLACK_TREE_NODE *GrandParent;678 RED_BLACK_TREE_NODE *Uncle;685 RED_BLACK_TREE_NODE *GrandParent; 686 RED_BLACK_TREE_NODE *Uncle; 679 687 680 688 // … … 692 700 if (Parent == GrandParent->Left) { 693 701 Uncle = GrandParent->Right; 694 if ( Uncle != NULL && Uncle->Color == RedBlackTreeRed) {702 if ((Uncle != NULL) && (Uncle->Color == RedBlackTreeRed)) { 695 703 // 696 704 // GrandParent (black) … … 701 709 // 702 710 703 Parent->Color = RedBlackTreeBlack;704 Uncle->Color = RedBlackTreeBlack;711 Parent->Color = RedBlackTreeBlack; 712 Uncle->Color = RedBlackTreeBlack; 705 713 GrandParent->Color = RedBlackTreeRed; 706 714 … … 721 729 // restore property #5 after the loop, without breaking any others. 722 730 // 723 Tmp = GrandParent;731 Tmp = GrandParent; 724 732 Parent = Tmp->Parent; 725 733 } else { … … 760 768 } 761 769 762 Parent->Color = RedBlackTreeBlack;770 Parent->Color = RedBlackTreeBlack; 763 771 GrandParent->Color = RedBlackTreeRed; 764 772 … … 795 803 // 796 804 Uncle = GrandParent->Left; 797 if ( Uncle != NULL && Uncle->Color == RedBlackTreeRed) {798 Parent->Color = RedBlackTreeBlack;799 Uncle->Color = RedBlackTreeBlack;805 if ((Uncle != NULL) && (Uncle->Color == RedBlackTreeRed)) { 806 Parent->Color = RedBlackTreeBlack; 807 Uncle->Color = RedBlackTreeBlack; 800 808 GrandParent->Color = RedBlackTreeRed; 801 Tmp = GrandParent;802 Parent = Tmp->Parent;809 Tmp = GrandParent; 810 Parent = Tmp->Parent; 803 811 } else { 804 812 if (Tmp == Parent->Left) { … … 808 816 ASSERT (GrandParent == Parent->Parent); 809 817 } 810 Parent->Color = RedBlackTreeBlack; 818 819 Parent->Color = RedBlackTreeBlack; 811 820 GrandParent->Color = RedBlackTreeRed; 812 821 RedBlackTreeRotateLeft (GrandParent, &NewRoot); … … 816 825 817 826 NewRoot->Color = RedBlackTreeBlack; 818 Tree->Root = NewRoot;819 Status = RETURN_SUCCESS;827 Tree->Root = NewRoot; 828 Status = RETURN_SUCCESS; 820 829 821 830 Done: … … 823 832 RedBlackTreeValidate (Tree); 824 833 } 834 825 835 return Status; 826 836 } 827 828 837 829 838 /** … … 838 847 BOOLEAN 839 848 NodeIsNullOrBlack ( 840 IN CONST RED_BLACK_TREE_NODE *Node849 IN CONST RED_BLACK_TREE_NODE *Node 841 850 ) 842 851 { 843 852 return (BOOLEAN)(Node == NULL || Node->Color == RedBlackTreeBlack); 844 853 } 845 846 854 847 855 /** … … 913 921 EFIAPI 914 922 OrderedCollectionDelete ( 915 IN OUT RED_BLACK_TREE *Tree,916 IN RED_BLACK_TREE_NODE *Node,917 OUT VOID **UserStruct OPTIONAL918 ) 919 { 920 RED_BLACK_TREE_NODE *NewRoot;921 RED_BLACK_TREE_NODE *OrigLeftChild;922 RED_BLACK_TREE_NODE *OrigRightChild;923 RED_BLACK_TREE_NODE *OrigParent;924 RED_BLACK_TREE_NODE *Child;925 RED_BLACK_TREE_NODE *Parent;926 RED_BLACK_TREE_COLOR ColorOfUnlinked;923 IN OUT RED_BLACK_TREE *Tree, 924 IN RED_BLACK_TREE_NODE *Node, 925 OUT VOID **UserStruct OPTIONAL 926 ) 927 { 928 RED_BLACK_TREE_NODE *NewRoot; 929 RED_BLACK_TREE_NODE *OrigLeftChild; 930 RED_BLACK_TREE_NODE *OrigRightChild; 931 RED_BLACK_TREE_NODE *OrigParent; 932 RED_BLACK_TREE_NODE *Child; 933 RED_BLACK_TREE_NODE *Parent; 934 RED_BLACK_TREE_COLOR ColorOfUnlinked; 927 935 928 936 NewRoot = Tree->Root; … … 942 950 // that we will have unlinked. 943 951 // 944 if ( OrigLeftChild == NULL || OrigRightChild == NULL) {952 if ((OrigLeftChild == NULL) || (OrigRightChild == NULL)) { 945 953 // 946 954 // Node has at most one child. We can connect that child (if any) with … … 949 957 // side of Node's parent (if any) that Node was before. 950 958 // 951 Parent = OrigParent;952 Child = (OrigLeftChild != NULL) ? OrigLeftChild : OrigRightChild;959 Parent = OrigParent; 960 Child = (OrigLeftChild != NULL) ? OrigLeftChild : OrigRightChild; 953 961 ColorOfUnlinked = Node->Color; 954 962 … … 956 964 Child->Parent = Parent; 957 965 } 966 958 967 if (OrigParent == NULL) { 959 968 NewRoot = Child; … … 979 988 // relation. 980 989 // 981 RED_BLACK_TREE_NODE *ToRelink;990 RED_BLACK_TREE_NODE *ToRelink; 982 991 983 992 ToRelink = OrigRightChild; … … 995 1004 // 996 1005 Parent = OrigRightChild; 997 Child = OrigRightChild->Right;1006 Child = OrigRightChild->Right; 998 1007 } else { 999 1008 do { … … 1014 1023 // D <--- Child 1015 1024 Parent = ToRelink->Parent; 1016 Child = ToRelink->Right;1025 Child = ToRelink->Right; 1017 1026 1018 1027 // … … 1047 1056 // 1048 1057 // 1049 ToRelink->Right = OrigRightChild;1058 ToRelink->Right = OrigRightChild; 1050 1059 OrigRightChild->Parent = ToRelink; 1051 1060 } … … 1067 1076 // Child 1068 1077 // 1069 ToRelink->Left = OrigLeftChild;1078 ToRelink->Left = OrigLeftChild; 1070 1079 OrigLeftChild->Parent = ToRelink; 1071 1080 … … 1130 1139 // 1131 1140 while (Child != NewRoot && NodeIsNullOrBlack (Child)) { 1132 RED_BLACK_TREE_NODE *Sibling;1133 RED_BLACK_TREE_NODE *LeftNephew;1134 RED_BLACK_TREE_NODE *RightNephew;1141 RED_BLACK_TREE_NODE *Sibling; 1142 RED_BLACK_TREE_NODE *LeftNephew; 1143 RED_BLACK_TREE_NODE *RightNephew; 1135 1144 1136 1145 if (Child == Parent->Left) { … … 1164 1173 // 1165 1174 Sibling->Color = RedBlackTreeBlack; 1166 Parent->Color = RedBlackTreeRed;1175 Parent->Color = RedBlackTreeRed; 1167 1176 RedBlackTreeRotateLeft (Parent, &NewRoot); 1168 1177 Sibling = Parent->Right; … … 1178 1187 // 1179 1188 ASSERT (Sibling->Color == RedBlackTreeBlack); 1180 LeftNephew = Sibling->Left;1189 LeftNephew = Sibling->Left; 1181 1190 RightNephew = Sibling->Right; 1182 1191 if (NodeIsNullOrBlack (LeftNephew) && 1183 NodeIsNullOrBlack (RightNephew)) { 1192 NodeIsNullOrBlack (RightNephew)) 1193 { 1184 1194 // 1185 1195 // In this case we can "steal" one black value from Child and Sibling … … 1201 1211 // 1202 1212 Sibling->Color = RedBlackTreeRed; 1203 Child = Parent;1204 Parent = Parent->Parent;1213 Child = Parent; 1214 Parent = Parent->Parent; 1205 1215 // 1206 1216 // Continue ascending. … … 1231 1241 // 1232 1242 LeftNephew->Color = RedBlackTreeBlack; 1233 Sibling->Color = RedBlackTreeRed;1243 Sibling->Color = RedBlackTreeRed; 1234 1244 RedBlackTreeRotateRight (Sibling, &NewRoot); 1235 Sibling = Parent->Right;1245 Sibling = Parent->Right; 1236 1246 RightNephew = Sibling->Right; 1237 1247 // … … 1239 1249 // 1240 1250 } 1251 1241 1252 // 1242 1253 // ... RightNephew is definitely red here, plus Sibling is (still) … … 1273 1284 // 1274 1285 // 1275 Sibling->Color = Parent->Color;1276 Parent->Color = RedBlackTreeBlack;1286 Sibling->Color = Parent->Color; 1287 Parent->Color = RedBlackTreeBlack; 1277 1288 RightNephew->Color = RedBlackTreeBlack; 1278 1289 RedBlackTreeRotateLeft (Parent, &NewRoot); … … 1290 1301 if (Sibling->Color == RedBlackTreeRed) { 1291 1302 Sibling->Color = RedBlackTreeBlack; 1292 Parent->Color = RedBlackTreeRed;1303 Parent->Color = RedBlackTreeRed; 1293 1304 RedBlackTreeRotateRight (Parent, &NewRoot); 1294 1305 Sibling = Parent->Left; … … 1298 1309 ASSERT (Sibling->Color == RedBlackTreeBlack); 1299 1310 RightNephew = Sibling->Right; 1300 LeftNephew = Sibling->Left;1311 LeftNephew = Sibling->Left; 1301 1312 if (NodeIsNullOrBlack (RightNephew) && 1302 NodeIsNullOrBlack (LeftNephew)) { 1313 NodeIsNullOrBlack (LeftNephew)) 1314 { 1303 1315 Sibling->Color = RedBlackTreeRed; 1304 Child = Parent;1305 Parent = Parent->Parent;1316 Child = Parent; 1317 Parent = Parent->Parent; 1306 1318 } else { 1307 1319 if (NodeIsNullOrBlack (LeftNephew)) { 1308 1320 RightNephew->Color = RedBlackTreeBlack; 1309 Sibling->Color = RedBlackTreeRed;1321 Sibling->Color = RedBlackTreeRed; 1310 1322 RedBlackTreeRotateLeft (Sibling, &NewRoot); 1311 Sibling = Parent->Left;1323 Sibling = Parent->Left; 1312 1324 LeftNephew = Sibling->Left; 1313 1325 } 1326 1314 1327 ASSERT (LeftNephew != NULL); 1315 1328 ASSERT (LeftNephew->Color == RedBlackTreeRed); 1316 1329 ASSERT (Sibling != NULL); 1317 1330 ASSERT (Sibling->Color == RedBlackTreeBlack); 1318 Sibling->Color = Parent->Color;1319 Parent->Color = RedBlackTreeBlack;1331 Sibling->Color = Parent->Color; 1332 Parent->Color = RedBlackTreeBlack; 1320 1333 LeftNephew->Color = RedBlackTreeBlack; 1321 1334 RedBlackTreeRotateRight (Parent, &NewRoot); … … 1337 1350 } 1338 1351 1339 1340 1352 /** 1341 1353 Recursively check the red-black tree properties #1 to #4 on a node. … … 1347 1359 UINT32 1348 1360 RedBlackTreeRecursiveCheck ( 1349 IN CONST RED_BLACK_TREE_NODE *Node1350 ) 1351 { 1352 UINT32 LeftHeight;1353 UINT32 RightHeight;1361 IN CONST RED_BLACK_TREE_NODE *Node 1362 ) 1363 { 1364 UINT32 LeftHeight; 1365 UINT32 RightHeight; 1354 1366 1355 1367 // … … 1376 1388 // property #4 1377 1389 // 1378 LeftHeight = RedBlackTreeRecursiveCheck (Node->Left);1390 LeftHeight = RedBlackTreeRecursiveCheck (Node->Left); 1379 1391 RightHeight = RedBlackTreeRecursiveCheck (Node->Right); 1380 1392 ASSERT (LeftHeight == RightHeight); … … 1383 1395 } 1384 1396 1385 1386 1397 /** 1387 1398 A slow function that asserts that the tree is a valid red-black tree, and … … 1397 1408 VOID 1398 1409 RedBlackTreeValidate ( 1399 IN CONST RED_BLACK_TREE *Tree1400 ) 1401 { 1402 UINT32 BlackHeight;1403 UINT32 ForwardCount;1404 UINT32 BackwardCount;1405 CONST RED_BLACK_TREE_NODE *Last;1406 CONST RED_BLACK_TREE_NODE *Node;1410 IN CONST RED_BLACK_TREE *Tree 1411 ) 1412 { 1413 UINT32 BlackHeight; 1414 UINT32 ForwardCount; 1415 UINT32 BackwardCount; 1416 CONST RED_BLACK_TREE_NODE *Last; 1417 CONST RED_BLACK_TREE_NODE *Node; 1407 1418 1408 1419 DEBUG ((DEBUG_VERBOSE, "%a: Tree=%p\n", __FUNCTION__, Tree)); … … 1421 1432 // forward ordering 1422 1433 // 1423 Last = OrderedCollectionMin (Tree);1434 Last = OrderedCollectionMin (Tree); 1424 1435 ForwardCount = (Last != NULL); 1425 1436 for (Node = OrderedCollectionNext (Last); Node != NULL; 1426 Node = OrderedCollectionNext (Last)) { 1437 Node = OrderedCollectionNext (Last)) 1438 { 1427 1439 ASSERT (Tree->UserStructCompare (Last->UserStruct, Node->UserStruct) < 0); 1428 1440 Last = Node; … … 1433 1445 // backward ordering 1434 1446 // 1435 Last = OrderedCollectionMax (Tree);1447 Last = OrderedCollectionMax (Tree); 1436 1448 BackwardCount = (Last != NULL); 1437 1449 for (Node = OrderedCollectionPrev (Last); Node != NULL; 1438 Node = OrderedCollectionPrev (Last)) { 1450 Node = OrderedCollectionPrev (Last)) 1451 { 1439 1452 ASSERT (Tree->UserStructCompare (Last->UserStruct, Node->UserStruct) > 0); 1440 1453 Last = Node; … … 1444 1457 ASSERT (ForwardCount == BackwardCount); 1445 1458 1446 DEBUG ((DEBUG_VERBOSE, "%a: Tree=%p BlackHeight=%Ld Count=%Ld\n", 1447 __FUNCTION__, Tree, (INT64)BlackHeight, (INT64)ForwardCount)); 1448 } 1459 DEBUG (( 1460 DEBUG_VERBOSE, 1461 "%a: Tree=%p BlackHeight=%Ld Count=%Ld\n", 1462 __FUNCTION__, 1463 Tree, 1464 (INT64)BlackHeight, 1465 (INT64)ForwardCount 1466 )); 1467 }
Note:
See TracChangeset
for help on using the changeset viewer.