internal void method_1() { if (this.method_3(this.node_0, true, 0) == 0) { throw new Exception("Invalid tree."); } if (this.node_0 == null) { return; } if (this.node_0.Parent != null) { throw new Exception("root.Parent should be null."); } RedBlackTree <T> .ForwardEnumerator forwardEnumerator = new RedBlackTree <T> .ForwardEnumerator(this); while (forwardEnumerator.MoveNext()) { forwardEnumerator.CurrentNode.method_3(); } }
public bool Search(Func <T, int> compare) { this.Reset(); RedBlackTree <T> .Node node1 = this.tree.node_0; bool flag = false; RedBlackTree <T> .Node node2 = node1; while (node1 != null) { node2 = node1; int num = compare(node1.Value); if (num < 0) { node1 = node1.Left; } else if (num > 0) { node1 = node1.Right; flag = true; } else if (num == 0) { flag = true; break; } } if (flag) { this.current = node2.Value; this.currentNode = node2; } else { this.currentNode = (RedBlackTree <T> .Node)null; this.current = default(T); } return(flag); }
private static void smethod_8( ref RedBlackTree <T> .Node root, RedBlackTree <T> .Node node, RedBlackTree <T> .Node replacement) { if (node.node_0 == null) { root = replacement; if (root == null) { return; } root.node_0 = (RedBlackTree <T> .Node)null; } else if (node.node_0.node_1 == node) { node.node_0.Left = replacement; } else { node.node_0.Right = replacement; } }
internal void method_2(out bool isInvalidTree, out bool rootParentNotNull) { isInvalidTree = false; rootParentNotNull = false; if (this.method_3(this.node_0, true, 0) == 0) { isInvalidTree = true; } if (this.node_0 == null) { return; } if (this.node_0.Parent != null) { rootParentNotNull = true; } RedBlackTree <T> .ForwardEnumerator forwardEnumerator = new RedBlackTree <T> .ForwardEnumerator(this); while (forwardEnumerator.MoveNext()) { forwardEnumerator.CurrentNode.method_3(); } }
private bool method_0(T target) { RedBlackTree <T> .Node node = this.tree.node_0; bool flag = false; int num; for (; node != null; node = num < 0 ? node.Left : node.Right) { num = this.tree.icomparer_0.Compare(target, node.Value); if (num == 0) { flag = true; this.currentNode = node; this.current = node.Value; break; } } if (!flag) { this.currentNode = (RedBlackTree <T> .Node)null; this.current = default(T); } return(flag); }
public void Reset() { this.currentNode = (RedBlackTree <T> .Node)null; }
public void Clear() { this.node_0 = (RedBlackTree <T> .Node)null; this.int_0 = 0; }
public ReverseEnumerator(RedBlackTree <T> .EnumeratorBase from) : base(from) { }
public ReverseEnumerator(RedBlackTree <T> tree, T target) : base(tree, target) { }
public ReverseEnumerator(RedBlackTree <T> tree) : base(tree) { }
public EnumeratorBase(RedBlackTree <T> tree) { this.tree = tree; this.Reset(); }
internal int method_5(T value, IComparer <T> comparer) { int num1 = 0; RedBlackTree <T> .Node node1 = (RedBlackTree <T> .Node)null; RedBlackTree <T> .Node root1 = (RedBlackTree <T> .Node)null; RedBlackTree <T> .Node root2 = this; bool isLeft1 = false; RedBlackTree <T> .Node node2 = root2.method_2(false); while (node2 != null) { bool isLeft2 = isLeft1; RedBlackTree <T> .Node node3 = root1; root1 = root2; root2 = node2; int num2 = comparer.Compare(value, root2.gparam_0); isLeft1 = num2 < 0; if (num2 == 0) { node1 = root2; } node2 = root2.method_2(isLeft1); if (!root2.IsRed && !RedBlackTree <T> .Node.smethod_0(node2)) { if (RedBlackTree <T> .Node.smethod_0(root2.method_2(!isLeft1))) { RedBlackTree <T> .Node child = isLeft1 ? RedBlackTree <T> .Node.smethod_3(root2) : RedBlackTree <T> .Node.smethod_1(root2); root1.method_1(isLeft2, child); root1 = child; } else { RedBlackTree <T> .Node node4 = root1.method_2(!isLeft2); if (node4 != null) { if (!RedBlackTree <T> .Node.smethod_0(node4.node_1) && !RedBlackTree <T> .Node.smethod_0(node4.node_2)) { root1.bool_0 = false; node4.bool_0 = true; root2.bool_0 = true; } else { bool isLeft3 = root1 != node3.node_2; RedBlackTree <T> .Node child; if (RedBlackTree <T> .Node.smethod_0(node4.method_2(isLeft2))) { child = isLeft2 ? RedBlackTree <T> .Node.smethod_4(root1) : RedBlackTree <T> .Node.smethod_2(root1); node3.method_1(isLeft3, child); } else if (RedBlackTree <T> .Node.smethod_0(node4.method_2(!isLeft2))) { child = isLeft2 ? RedBlackTree <T> .Node.smethod_3(root1) : RedBlackTree <T> .Node.smethod_1(root1); node3.method_1(isLeft3, child); } else { child = node3.method_2(isLeft3); } RedBlackTree <T> .Node node5 = root2; child.bool_0 = true; node5.bool_0 = true; child.node_1.bool_0 = false; child.node_2.bool_0 = false; } } } } } if (node1 != null) { node1.gparam_0 = root2.gparam_0; root1.method_1(root1.Right != root2, root2.method_2(root2.Left == null)); num1 = 1; } return(num1); }
private static RedBlackTree <T> .Node smethod_2(RedBlackTree <T> .Node root) { root.Left = RedBlackTree <T> .Node.smethod_3(root.node_1); return(RedBlackTree <T> .Node.smethod_1(root)); }
public void Dispose() { this.tree = (RedBlackTree <T>)null; this.currentNode = (RedBlackTree <T> .Node)null; }
public void ReverseNodes(RedBlackTree <T> .Node first, RedBlackTree <T> .Node last) { if (first == last) { return; } RedBlackTree <T> .Node child1 = first; RedBlackTree <T> .Node child2 = last; while (true) { RedBlackTree <T> .Node next = child1.GetNext(); RedBlackTree <T> .Node previous = child2.GetPrevious(); bool flag = next == previous || next == child2; if (child1.Parent == child2) { RedBlackTree <T> .Node node = child1; child1 = child2; child2 = node; } RedBlackTree <T> .Node left1 = child1.Left; RedBlackTree <T> .Node right1 = child1.Right; RedBlackTree <T> .Node parent1 = child1.Parent; bool isRed1 = child1.IsRed; RedBlackTree <T> .Node left2 = child2.Left; RedBlackTree <T> .Node right2 = child2.Right; RedBlackTree <T> .Node parent2 = child2.Parent; bool isRed2 = child2.IsRed; if (child1.Right == child2) { child1.Left = left2; child1.Right = right2; child2.Left = left1; child2.Right = child1; if (parent1 == null) { this.node_0 = child2; child2.Parent = (RedBlackTree <T> .Node)null; } else { parent1.method_1(parent1.Left == child1, child2); } } else if (child1.Left == child2) { child1.Left = left2; child1.Right = right2; child2.Left = child1; child2.Right = right1; if (parent1 == null) { this.node_0 = child2; child2.Parent = (RedBlackTree <T> .Node)null; } else { parent1.method_1(parent1.Left == child1, child2); } } else { child1.Left = left2; child1.Right = right2; if (parent2 == null) { this.node_0 = child1; child1.Parent = (RedBlackTree <T> .Node)null; } else { parent2.method_1(parent2.Left == child2, child1); } child2.Left = left1; child2.Right = right1; if (parent1 == null) { this.node_0 = child2; child2.Parent = (RedBlackTree <T> .Node)null; } else { parent1.method_1(parent1.Left == child1, child2); } } child1.IsRed = isRed2; child2.IsRed = isRed1; if (!flag) { child1 = next; child2 = previous; } else { break; } } }
public EnumeratorBase(RedBlackTree <T> tree, T target) { this.tree = tree; this.Reset(); this.method_0(target); }
public EnumeratorBase(RedBlackTree <T> .EnumeratorBase from) { this.current = from.current; this.tree = from.tree; this.currentNode = from.currentNode; }
internal RedBlackTree <T> .Node method_4(T value, IComparer <T> comparer) { bool isLeft1 = false; bool flag = false; RedBlackTree <T> .Node node1 = this; RedBlackTree <T> .Node root = (RedBlackTree <T> .Node)null; RedBlackTree <T> .Node node2 = (RedBlackTree <T> .Node)null; RedBlackTree <T> .Node node3; for (RedBlackTree <T> .Node node4 = this.node_2; node4 != null; node4 = isLeft1 ? node4.node_1 : node4.node_2) { if (node4.node_1 != null && node4.node_1.bool_0 && (node4.node_2 != null && node4.node_2.bool_0)) { node4.bool_0 = true; node4.node_1.bool_0 = false; node4.node_2.bool_0 = false; if (RedBlackTree <T> .Node.smethod_0(node2)) { bool isLeft2 = node1.node_1 == root; if (isLeft1 == flag) { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root)); } else { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root)); } } } else if (node4.bool_0 && RedBlackTree <T> .Node.smethod_0(node2)) { bool isLeft2 = node1.node_1 == root; if (isLeft1 == flag) { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root)); } else { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root)); } } int num = comparer.Compare(value, node4.gparam_0); if (num != 0) { flag = isLeft1; isLeft1 = num < 0; if (root != null) { node1 = root; } root = node2; node2 = node4; } else { node3 = (RedBlackTree <T> .Node)null; goto label_20; } } RedBlackTree <T> .Node child; node3 = child = new RedBlackTree <T> .Node(value); node2.method_1(isLeft1, child); if (node2.bool_0) { bool isLeft2 = node1.node_1 == root; if (isLeft1 == flag) { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root)); } else { node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root)); } } label_20: return(node3); }
public ForwardEnumerator(RedBlackTree <T> tree) : base(tree) { }
private static RedBlackTree <T> .Node smethod_4(RedBlackTree <T> .Node root) { root.Right = RedBlackTree <T> .Node.smethod_1(root.node_2); return(RedBlackTree <T> .Node.smethod_3(root)); }
public ForwardEnumerator(RedBlackTree <T> tree, T target) : base(tree, target) { }
internal void method_6(ref RedBlackTree <T> .Node root) { if (this.node_1 != null && this.node_2 != null) { RedBlackTree <T> .Node rightMost = this.node_1.GetRightMost(); RedBlackTree <T> .Node.smethod_7(ref root, this, rightMost); } if (this.node_1 == null && this.node_2 == null) { RedBlackTree <T> .Node sibling = this.Sibling; RedBlackTree <T> .Node.smethod_8(ref root, this, (RedBlackTree <T> .Node) null); if (!this.bool_0) { bool parentsNeedRebalancing = true; RedBlackTree <T> .Node root1 = this.node_0; if (root1 != null) { while (parentsNeedRebalancing) { bool flag = root == root1; RedBlackTree <T> .Node parent = root1.Parent; bool isLeft = parent != null && parent.Left == root1; RedBlackTree <T> .Node child = sibling != sibling.Parent.Left ? RedBlackTree <T> .Node.smethod_6(root1, sibling, out parentsNeedRebalancing) : RedBlackTree <T> .Node.smethod_5(root1, sibling, out parentsNeedRebalancing); if (flag) { root = child; root.Parent = (RedBlackTree <T> .Node)null; } else { parent.method_1(isLeft, child); } sibling = child.Sibling; root1 = child.Parent; if (root1 == null || sibling == null) { break; } } } } } else { RedBlackTree <T> .Node replacement = this.node_1 != null ? this.node_1 : this.node_2; RedBlackTree <T> .Node.smethod_8(ref root, this, replacement); if (!this.bool_0) { if (!replacement.bool_0) { throw new Exception(); } replacement.bool_0 = false; } } if (root == null) { return; } root.bool_0 = false; }
public ForwardEnumerator(RedBlackTree <T> .EnumeratorBase from) : base(from) { }