Exemplo n.º 1
0
            public bool Remove(TKey key)
            {
                bool found;

                root = root.RemoveFromNew(new KeyValuePair <TKey, TValue>(key, default(TValue)), CompareKV, out found);
                return(found);
            }
Exemplo n.º 2
0
        public ImmutableDictionary <TKey, TValue> Remove(TKey key)
        {
            var old  = root;
            var pair = new KeyValuePair <TKey, TValue> (key, default(TValue));

            return(new ImmutableDictionary <TKey, TValue> (root.RemoveFromNew(pair, CompareKV, out old), keyComparer, valueComparer));
        }
Exemplo n.º 3
0
        public IImmutableList <T> Drop(int count)
        {
            var result = this;

            while (count-- > 0)
            {
                bool found;
                result = new ImmutableList <T>(root.RemoveFromNew(0, out found), valueComparer);
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to remove the key, and return the resulting Dict
        /// if the key is not found, old_node is Empty, else old_node is the Dict
        /// with matching Key
        /// </summary>
        public AvlNode <T> RemoveFromNew(int index, out AvlNode <T> old_node)
        {
            if (IsEmpty)
            {
                old_node = Empty;
                return(Empty);
            }

            if (index < left._count)
            {
                var newlt = left.RemoveFromNew(index, out old_node);
                if (old_node.IsEmpty)
                {
                    //Not found, so nothing changed
                    return(this);
                }
                var newroot = new AvlNode <T> (Value, newlt, right);
                return(newroot.FixRootBalance());
            }

            if (index > left._count)
            {
                var newgt = right.RemoveFromNew(index - left._count - 1, out old_node);
                if (old_node.IsEmpty)
                {
                    //Not found, so nothing changed
                    return(this);
                }
                var newroot = new AvlNode <T> (Value, left, newgt);
                return(newroot.FixRootBalance());
            }

            //found it
            old_node = this;
            return(RemoveRoot());
        }
        public ImmutableList <T> RemoveAt(int index)
        {
            var old = root;

            return(new ImmutableList <T> (root.RemoveFromNew(index, out old), valueComparer));
        }