public RBTree.Node Intern <T>(T key, RBTree.Node new_node) { if (this.root == null) { if (new_node == null) { new_node = ((RBTree.INodeHelper <T>) this.hlp).CreateNode(key); } this.root = new_node; this.root.IsBlack = true; this.version = this.version + 1U; return(this.root); } List <RBTree.Node> path = RBTree.alloc_path(); int key1 = this.find_key <T>(key, path); RBTree.Node node = path[path.Count - 1]; if (node == null) { if (new_node == null) { new_node = ((RBTree.INodeHelper <T>) this.hlp).CreateNode(key); } node = this.do_insert(key1, new_node, path); } RBTree.release_path(path); return(node); }
private RBTree.Node do_remove(List <RBTree.Node> path) { int index1 = path.Count - 1; RBTree.Node node = path[index1]; if (node.left != null) { RBTree.Node other = RBTree.right_most(node.left, node.right, path); node.SwapValue(other); if (other.left != null) { RBTree.Node left = other.left; path.Add((RBTree.Node)null); path.Add(left); other.SwapValue(left); } } else if (node.right != null) { RBTree.Node right = node.right; path.Add((RBTree.Node)null); path.Add(right); node.SwapValue(right); } int index2 = path.Count - 1; RBTree.Node orig = path[index2]; if ((int)orig.Size != 1) { throw new Exception("Internal Error: red-black violation somewhere"); } path[index2] = (RBTree.Node)null; this.node_reparent(index2 == 0 ? (RBTree.Node)null : path[index2 - 2], orig, 0U, (RBTree.Node)null); int index3 = 0; while (index3 < path.Count - 2) { --path[index3].Size; index3 += 2; } if (orig.IsBlack) { orig.IsBlack = false; if (index2 != 0) { this.rebalance_delete(path); } } if (this.root != null && !this.root.IsBlack) { throw new Exception("Internal Error: root is not black"); } this.version = this.version + 1U; return(orig); }
public RBTree.Node Remove <T>(T key) { if (this.root == null) { return((RBTree.Node)null); } List <RBTree.Node> path = RBTree.alloc_path(); int key1 = this.find_key <T>(key, path); RBTree.Node node = (RBTree.Node)null; if (key1 == 0) { node = this.do_remove(path); } RBTree.release_path(path); return(node); }
public SortedDictionary(IComparer <TKey> comparer) { this.hlp = SortedDictionary <TKey, TValue> .NodeHelper.GetHelper(comparer); this.tree = new RBTree((object)this.hlp); }
public void Dispose() { this.tree = (RBTree)null; this.pennants = (Stack <RBTree.Node>)null; }
internal NodeEnumerator(RBTree tree, Stack <RBTree.Node> init_pennants) { this = new RBTree.NodeEnumerator(tree); this.init_pennants = init_pennants; }
internal NodeEnumerator(RBTree tree) { this = new RBTree.NodeEnumerator(); this.tree = tree; this.version = tree.version; }