public ImmutableList <T> Insert(int index, T element) { if (index > Count) { throw new ArgumentOutOfRangeException("index"); } return(new ImmutableList <T> (root.InsertIntoNew(index, element), valueComparer)); }
public void Insert(int index, T element) { if (index > Count) { throw new ArgumentOutOfRangeException("index"); } root = root.InsertIntoNew(index, element); Debug.Assert(root.IsMutable); }
/// <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()); }
public IImmutableList <T> Cons(T item) { return(new ImmutableList <T>(root.InsertIntoNew(0, item), valueComparer)); }
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)); }
public void Add(KeyValuePair <TKey, TValue> item) { root = root.InsertIntoNew(item, CompareKV); }