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

◆ RBDeleteX()

int System.Data.RBTree< K >.RBDeleteX ( int root_id,
int z_id,
int mainTreeNodeID )
inlineprivate

Definition at line 759 of file RBTree.cs.

760 {
761 int num = 0;
762 if (Next(z_id) != 0)
763 {
764 return RBDeleteX(Next(z_id), Next(z_id), z_id);
765 }
766 bool flag = false;
767 int num2 = ((_accessMethod == TreeAccessMethod.KEY_SEARCH_AND_INDEX) ? mainTreeNodeID : z_id);
768 if (Next(num2) != 0)
769 {
770 root_id = Next(num2);
771 }
772 if (SubTreeSize(Next(num2)) == 2)
773 {
774 flag = true;
775 }
776 else if (SubTreeSize(Next(num2)) == 1)
777 {
778 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.InvalidNextSizeInDelete);
779 }
780 int num3 = ((Left(z_id) != 0 && Right(z_id) != 0) ? Successor(z_id) : z_id);
781 num = ((Left(num3) == 0) ? Right(num3) : Left(num3));
782 int num4 = Parent(num3);
783 if (num != 0)
784 {
785 SetParent(num, num4);
786 }
787 if (num4 == 0)
788 {
789 if (root_id == 0)
790 {
791 root = num;
792 }
793 else
794 {
795 root_id = num;
796 }
797 }
798 else if (num3 == Left(num4))
799 {
800 SetLeft(num4, num);
801 }
802 else
803 {
804 SetRight(num4, num);
805 }
806 if (num3 != z_id)
807 {
808 SetKey(z_id, Key(num3));
810 }
811 if (Next(num2) != 0)
812 {
813 if (root_id == 0 && z_id != num2)
814 {
815 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.InvalidStateinDelete);
816 }
817 if (root_id != 0)
818 {
821 }
822 }
823 for (int num5 = num4; num5 != 0; num5 = Parent(num5))
824 {
826 }
827 if (root_id != 0)
828 {
829 for (int num6 = num2; num6 != 0; num6 = Parent(num6))
830 {
832 }
833 }
834 if (color(num3) == NodeColor.black)
835 {
837 }
838 if (flag)
839 {
840 if (num2 == 0 || SubTreeSize(Next(num2)) != 1)
841 {
842 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.InvalidNodeSizeinDelete);
843 }
845 int num7 = Next(num2);
850 if (Parent(num2) != 0)
851 {
853 if (Left(Parent(num2)) == num2)
854 {
856 }
857 else
858 {
860 }
861 }
862 if (Left(num2) != 0)
863 {
865 }
866 if (Right(num2) != 0)
867 {
869 }
870 if (root == num2)
871 {
872 root = num7;
873 }
874 FreeNode(num2);
875 num2 = 0;
876 }
877 else if (Next(num2) != 0)
878 {
879 if (root_id == 0 && z_id != num2)
880 {
881 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.InvalidStateinEndDelete);
882 }
883 if (root_id != 0)
884 {
887 }
888 }
889 if (num3 != z_id)
890 {
895 if (Parent(z_id) != 0)
896 {
898 if (Left(Parent(z_id)) == z_id)
899 {
901 }
902 else
903 {
905 }
906 }
907 else
908 {
909 SetParent(num3, 0);
910 }
911 if (Left(z_id) != 0)
912 {
914 }
915 if (Right(z_id) != 0)
916 {
918 }
919 if (root == z_id)
920 {
921 root = num3;
922 }
923 else if (root_id == z_id)
924 {
925 root_id = num3;
926 }
927 if (num2 != 0 && Next(num2) == z_id)
928 {
929 SetNext(num2, num3);
930 }
931 }
932 FreeNode(z_id);
933 _version++;
934 return z_id;
935 }
K Key(int nodeId)
Definition RBTree.cs:1407
NodeColor color(int nodeId)
Definition RBTree.cs:1392
void SetNext(int nodeId, int nextNodeId)
Definition RBTree.cs:1351
void SetRight(int nodeId, int rightNodeId)
Definition RBTree.cs:1326
int Successor(int x_id)
Definition RBTree.cs:400
void SetColor(int nodeId, NodeColor color)
Definition RBTree.cs:1341
int SubTreeSize(int nodeId)
Definition RBTree.cs:1402
readonly TreeAccessMethod _accessMethod
Definition RBTree.cs:217
void SetLeft(int nodeId, int leftNodeId)
Definition RBTree.cs:1331
int _inUseSatelliteTreeCount
Definition RBTree.cs:215
int Next(int nodeId)
Definition RBTree.cs:1397
void DecreaseSize(int nodeId)
Definition RBTree.cs:1372
void SetParent(int nodeId, int parentNodeId)
Definition RBTree.cs:1336
int RBDeleteX(int root_id, int z_id, int mainTreeNodeID)
Definition RBTree.cs:759
void SetSubTreeSize(int nodeId, int size)
Definition RBTree.cs:1356
void SetKey(int nodeId, K key)
Definition RBTree.cs:1346
void FreeNode(int nodeId)
Definition RBTree.cs:324
void RecomputeSize(int nodeId)
Definition RBTree.cs:1366

References System.Data.RBTree< K >._accessMethod, System.Data.RBTree< K >._inUseSatelliteTreeCount, System.Data.RBTree< K >._version, System.Data.RBTree< K >.color(), System.Data.RBTree< K >.DecreaseSize(), System.Data.RBTree< K >.FreeNode(), System.Data.ExceptionBuilder.InternalRBTreeError(), System.Data.RBTree< K >.Key(), System.Collections.Generic.Left, System.Data.RBTree< K >.Next(), System.Data.Parent, System.Data.RBDeleteFixup, System.Data.RBTree< K >.RBDeleteX(), System.Data.RBTree< K >.RecomputeSize(), System.Data.Right, System.Data.RBTree< K >.root, System.Data.RBTree< K >.SetColor(), System.Data.RBTree< K >.SetKey(), System.Data.RBTree< K >.SetLeft(), System.Data.RBTree< K >.SetNext(), System.Data.RBTree< K >.SetParent(), System.Data.RBTree< K >.SetRight(), System.Data.RBTree< K >.SetSubTreeSize(), System.Data.RBTree< K >.SubTreeSize(), and System.Data.RBTree< K >.Successor().

Referenced by System.Data.RBTree< K >.DeleteByIndex(), System.Data.RBTree< K >.RBDelete(), and System.Data.RBTree< K >.RBDeleteX().