Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 internal Enumerator(RBTree <T> t, RBTreeNode <T> cur, bool forceStarted)
 {
     tree    = t;
     started = forceStarted;
     isValid = true;
     current = cur;
 }
Ejemplo n.º 3
0
 internal Enumerator(RBTree <T> t, RBTreeNode <T> cur)
 {
     tree    = t;
     started = (cur == tree.root ? false : true);
     isValid = true;
     current = cur;
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 /// <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;
         }
     }
 }
Ejemplo n.º 9
0
 public SortedSet(IComparer <T> comparer)
 {
     this.helper = NodeHelper.GetHelper(comparer);
     this.tree   = new RBTree(this.helper);
 }
Ejemplo n.º 10
0
 public void Dispose()
 {
     tree     = null;
     pennants = null;
 }
Ejemplo n.º 11
0
 internal NodeEnumerator(RBTree tree, Stack <Node> init_pennants)
     : this(tree)
 {
     this.init_pennants = init_pennants;
 }
Ejemplo n.º 12
0
 internal NodeEnumerator(RBTree tree)
     : this()
 {
     this.tree = tree;
     version   = tree.version;
 }
Ejemplo n.º 13
0
 public SortedDictionary(IComparer <TKey> comparer)
 {
     hlp  = NodeHelper.GetHelper(comparer);
     tree = new RBTree(hlp);
 }
Ejemplo n.º 14
0
 public RBTree(RBTree <T> otherTree, IComparer <T> comp)
 {
     comparer = comp;
     Initialize();
     Copy(otherTree);
 }
Ejemplo n.º 15
0
 public void Dispose()
 {
     this.tree     = null;
     this.pennants = null;
 }
Ejemplo n.º 16
0
 private void Copy(RBTree <T> otherTree)
 {
     root  = Copy(otherTree.root, root);
     count = otherTree.count;
 }
Ejemplo n.º 17
0
 public RBTree(RBTree <T> otherTree)
 {
     comparer = otherTree.comparer;
     Initialize();
     Copy(otherTree);
 }
Ejemplo n.º 18
0
 internal NodeEnumerator(RBTree tree)
 {
     this.tree = tree;
     version   = tree.version;
     pennants  = null;
 }