Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal virtual bool DoRemove(T item)
- {
- if (this.root == null)
- return false;
- this.version++;
- SortedSet<T>.Node node = this.root;
- SortedSet<T>.Node node2 = null;
- SortedSet<T>.Node node3 = null;
- SortedSet<T>.Node node4 = null;
- SortedSet<T>.Node parentOfMatch = null;
- bool flag = false;
- while (node != null)
- {
- if (SortedSet<T>.Is2Node(node))
- {
- if (node2 == null)
- {
- node.IsRed = true;
- }
- else
- {
- SortedSet<T>.Node node5 = SortedSet<T>.GetSibling(node, node2);
- if (node5.IsRed)
- {
- if (node2.Right == node5)
- SortedSet<T>.RotateLeft(node2);
- else
- SortedSet<T>.RotateRight(node2);
- node2.IsRed = true;
- node5.IsRed = false;
- this.ReplaceChildOfNodeOrRoot(node3, node2, node5);
- node3 = node5;
- if (node2 == node4)
- parentOfMatch = node5;
- node5 = ((node2.Left == node) ? node2.Right : node2.Left);
- }
- if (SortedSet<T>.Is2Node(node5))
- {
- SortedSet<T>.Merge2Nodes(node2, node, node5);
- }
- else
- {
- TreeRotation treeRotation = SortedSet<T>.RotationNeeded(node2, node, node5);
- SortedSet<T>.Node node6 = null;
- switch (treeRotation)
- {
- case TreeRotation.LeftRotation:
- node5.Right.IsRed = false;
- node6 = SortedSet<T>.RotateLeft(node2);
- break;
- case TreeRotation.RightRotation:
- node5.Left.IsRed = false;
- node6 = SortedSet<T>.RotateRight(node2);
- break;
- case TreeRotation.RightLeftRotation:
- node6 = SortedSet<T>.RotateRightLeft(node2);
- break;
- case TreeRotation.LeftRightRotation:
- node6 = SortedSet<T>.RotateLeftRight(node2);
- break;
- }
- node6.IsRed = node2.IsRed;
- node2.IsRed = false;
- node.IsRed = true;
- this.ReplaceChildOfNodeOrRoot(node3, node2, node6);
- if (node2 == node4)
- parentOfMatch = node6;
- }
- }
- }
- int num = flag ? -1 : this.comparer.Compare(item, node.Item);
- if (num == 0)
- {
- flag = true;
- node4 = node;
- parentOfMatch = node2;
- }
- node3 = node2;
- node2 = node;
- if (num < 0)
- node = node.Left;
- else
- node = node.Right;
- }
- if (node4 != null)
- {
- this.ReplaceNode(node4, parentOfMatch, node2, node3);
- this.count--;
- }
- if (this.root != null)
- this.root.IsRed = false;
- return flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement