Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ RBDeleteFixup()

int System.Data.RBTree< K >.RBDeleteFixup ( int root_id,
int x_id,
int px_id,
int mainTreeNodeID )
inlineprivate

Definition at line 937 of file RBTree.cs.

938 {
939 if (x_id == 0 && px_id == 0)
940 {
941 return 0;
942 }
943 while (((root_id == 0) ? root : root_id) != x_id && color(x_id) == NodeColor.black)
944 {
945 int num;
946 if ((x_id != 0 && x_id == Left(Parent(x_id))) || (x_id == 0 && Left(px_id) == 0))
947 {
948 num = ((x_id == 0) ? Right(px_id) : Right(Parent(x_id)));
949 if (num == 0)
950 {
951 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.RBDeleteFixup);
952 }
953 if (color(num) == NodeColor.red)
954 {
955 SetColor(num, NodeColor.black);
958 num = ((x_id == 0) ? Right(px_id) : Right(Parent(x_id)));
959 }
960 if (color(Left(num)) == NodeColor.black && color(Right(num)) == NodeColor.black)
961 {
962 SetColor(num, NodeColor.red);
963 x_id = px_id;
964 px_id = Parent(px_id);
965 continue;
966 }
967 if (color(Right(num)) == NodeColor.black)
968 {
969 SetColor(Left(num), NodeColor.black);
970 SetColor(num, NodeColor.red);
972 num = ((x_id == 0) ? Right(px_id) : Right(Parent(x_id)));
973 }
974 SetColor(num, color(px_id));
975 SetColor(px_id, NodeColor.black);
976 SetColor(Right(num), NodeColor.black);
978 x_id = ((root_id == 0) ? root : root_id);
979 px_id = Parent(x_id);
980 continue;
981 }
982 num = Left(px_id);
983 if (color(num) == NodeColor.red)
984 {
985 SetColor(num, NodeColor.black);
986 if (x_id != 0)
987 {
990 num = ((x_id == 0) ? Left(px_id) : Left(Parent(x_id)));
991 }
992 else
993 {
996 num = ((x_id == 0) ? Left(px_id) : Left(Parent(x_id)));
997 if (num == 0)
998 {
999 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CannotRotateInvalidsuccessorNodeinDelete);
1000 }
1001 }
1002 }
1003 if (color(Right(num)) == NodeColor.black && color(Left(num)) == NodeColor.black)
1004 {
1005 SetColor(num, NodeColor.red);
1006 x_id = px_id;
1007 px_id = Parent(px_id);
1008 continue;
1009 }
1010 if (color(Left(num)) == NodeColor.black)
1011 {
1012 SetColor(Right(num), NodeColor.black);
1013 SetColor(num, NodeColor.red);
1015 num = ((x_id == 0) ? Left(px_id) : Left(Parent(x_id)));
1016 }
1017 SetColor(num, color(px_id));
1018 SetColor(px_id, NodeColor.black);
1019 SetColor(Left(num), NodeColor.black);
1021 x_id = ((root_id == 0) ? root : root_id);
1022 px_id = Parent(x_id);
1023 }
1024 SetColor(x_id, NodeColor.black);
1025 return root_id;
1026 }
NodeColor color(int nodeId)
Definition RBTree.cs:1392
void SetColor(int nodeId, NodeColor color)
Definition RBTree.cs:1341
int LeftRotate(int root_id, int x_id, int mainTreeNode)
Definition RBTree.cs:456
int RightRotate(int root_id, int x_id, int mainTreeNode)
Definition RBTree.cs:499

References System.Data.RBTree< K >.color(), System.Data.ExceptionBuilder.InternalRBTreeError(), System.Collections.Generic.Left, System.Data.RBTree< K >.LeftRotate(), System.Data.Parent, System.Data.Right, System.Data.RBTree< K >.RightRotate(), System.Data.RBTree< K >.root, and System.Data.RBTree< K >.SetColor().