public ImmutableList <T> Insert(int index, T element)
 {
     if (index > Count)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     return(new ImmutableList <T> (root.InsertIntoNew(index, element), valueComparer));
 }
예제 #2
0
 public void Insert(int index, T element)
 {
     if (index > Count)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     root = root.InsertIntoNew(index, element);
     Debug.Assert(root.IsMutable);
 }
예제 #3
0
        /// <summary>
        /// Return a new tree with the key-value pair inserted
        /// If the key is already present, it replaces the value
        /// This operation is O(Log N) where N is the number of keys
        /// </summary>
        public AvlNode <T> InsertIntoNew(int index, T val)
        {
            if (IsEmpty)
            {
                return(new AvlNode <T> (val));
            }

            AvlNode <T> newlt = left;
            AvlNode <T> newgt = right;

            if (index <= left._count)
            {
                newlt = left.InsertIntoNew(index, val);
            }
            else
            {
                newgt = right.InsertIntoNew(index - left._count - 1, val);
            }

            var newroot = new AvlNode <T> (Value, newlt, newgt);

            return(newroot.FixRootBalance());
        }
예제 #4
0
 public IImmutableList <T> Cons(T item)
 {
     return(new ImmutableList <T>(root.InsertIntoNew(0, item), valueComparer));
 }
예제 #5
0
        public ImmutableDictionary <TKey, TValue> Add(TKey key, TValue value)
        {
            var pair = new KeyValuePair <TKey, TValue> (key, value);

            return(new ImmutableDictionary <TKey, TValue> (root.InsertIntoNew(pair, CompareKV), keyComparer, valueComparer));
        }
예제 #6
0
 public void Add(KeyValuePair <TKey, TValue> item)
 {
     root = root.InsertIntoNew(item, CompareKV);
 }