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 += 1u; return(this.root); } List <RBTree.Node> list = RBTree.alloc_path(); int in_tree_cmp = this.find_key <T>(key, list); RBTree.Node node = list[list.Count - 1]; if (node == null) { if (new_node == null) { new_node = ((RBTree.INodeHelper <T>) this.hlp).CreateNode(key); } node = this.do_insert(in_tree_cmp, new_node, list); } RBTree.release_path(list); return(node); }
internal Enumerator(RBTree <T> t, RBTreeNode <T> cur, bool forceStarted) { tree = t; started = forceStarted; isValid = true; current = cur; }
internal Enumerator(RBTree <T> t, RBTreeNode <T> cur) { tree = t; started = (cur == tree.root ? false : true); isValid = true; current = cur; }
protected SortedDictionary(SerializationInfo info, StreamingContext context) { hlp = (NodeHelper)info.GetValue("Helper", typeof(NodeHelper)); tree = new RBTree(hlp); KeyValuePair <TKey, TValue> [] data = (KeyValuePair <TKey, TValue>[])info.GetValue("KeyValuePairs", typeof(KeyValuePair <TKey, TValue>[])); foreach (KeyValuePair <TKey, TValue> entry in data) { Add(entry.Key, entry.Value); } }
public virtual void IntersectWith(IEnumerable <T> other) { CheckArgumentNotNull(other, "other"); RBTree newtree = new RBTree(helper); foreach (T item in other) { var node = tree.Remove(item); if (node != null) { newtree.Intern(item, node); } } tree = newtree; }
private RBTree.Node do_remove(List <RBTree.Node> path) { int num = path.Count - 1; RBTree.Node node = path[num]; if (node.left != null) { RBTree.Node node2 = RBTree.right_most(node.left, node.right, path); node.SwapValue(node2); if (node2.left != null) { RBTree.Node left = node2.left; path.Add(null); path.Add(left); node2.SwapValue(left); } } else if (node.right != null) { RBTree.Node right = node.right; path.Add(null); path.Add(right); node.SwapValue(right); } num = path.Count - 1; node = path[num]; if (node.Size != 1u) { throw new SystemException("Internal Error: red-black violation somewhere"); } path[num] = null; this.node_reparent((num != 0) ? path[num - 2] : null, node, 0u, null); for (int i = 0; i < path.Count - 2; i += 2) { path[i].Size -= 1u; } if (num != 0 && node.IsBlack) { this.rebalance_delete(path); } if (this.root != null && !this.root.IsBlack) { throw new SystemException("Internal Error: root is not black"); } this.version += 1u; return(node); }
public RBTree.Node Remove <T>(T key) { if (this.root == null) { return(null); } List <RBTree.Node> path = RBTree.alloc_path(); int num = this.find_key <T>(key, path); RBTree.Node result = null; if (num == 0) { result = this.do_remove(path); } RBTree.release_path(path); return(result); }
/// <summary> /// Initializes an new instance of Collections.System.RBTreeEnumerator /// class. The current position is before the first element. /// </summary> /// <param name="t">The RBTree which will be enumerate.</param> internal Enumerator(RBTree <T> t) { tree = t; if (t.root == null && t.Count > 0) { throw new InvalidOperationException("The RBTree has null root but non-zero size"); } started = false; isValid = true; current = tree.root; if (current != null) { while (current.Left != null) { current = current.Left; } } }
public SortedSet(IComparer <T> comparer) { this.helper = NodeHelper.GetHelper(comparer); this.tree = new RBTree(this.helper); }
public void Dispose() { tree = null; pennants = null; }
internal NodeEnumerator(RBTree tree, Stack <Node> init_pennants) : this(tree) { this.init_pennants = init_pennants; }
internal NodeEnumerator(RBTree tree) : this() { this.tree = tree; version = tree.version; }
public SortedDictionary(IComparer <TKey> comparer) { hlp = NodeHelper.GetHelper(comparer); tree = new RBTree(hlp); }
public RBTree(RBTree <T> otherTree, IComparer <T> comp) { comparer = comp; Initialize(); Copy(otherTree); }
public void Dispose() { this.tree = null; this.pennants = null; }
private void Copy(RBTree <T> otherTree) { root = Copy(otherTree.root, root); count = otherTree.count; }
public RBTree(RBTree <T> otherTree) { comparer = otherTree.comparer; Initialize(); Copy(otherTree); }
internal NodeEnumerator(RBTree tree) { this.tree = tree; version = tree.version; pennants = null; }