public bool Remove(T item) { var ret = _inner.AvlRemove(item, _lineage); if (ret == null) { return(false); } _inner = ret; return(true); }
public bool Remove(TKey key) { var ret = _inner.AvlRemove(key, _lineage); if (ret == null) { return(false); } _inner = ret; return(true); }
public bool Add(T item) { var ret = _inner.Root_Add(item, true, _comparer, false, _lineage); if (ret == null) { return(false); } _inner = ret; return(true); }
public void AddRange(IEnumerable <KeyValuePair <TKey, TValue> > items) { items.CheckNotNull("items"); var map = items as ImmSortedMap <TKey, TValue>; if (map != null && _comparer.Equals(map.Comparer)) { _inner = _inner.Union(map.Root, null, _lineage); } else { items.ForEach(x => Add(x)); } }
public void AddRange(IEnumerable <T> items) { items.CheckNotNull("items"); var set = items as ImmSortedSet <T>; if (set != null && _comparer.Equals(set.Comparer)) { _inner = _inner.Union(set.Root, null, _lineage); } else { items.ForEach(x => Add(x)); } }
/// <summary> /// Removes the keys of the other tree from this tree. Keys are ignored. <br /> /// Corresponds to a set theoretic relative complement: this ∖ other. /// </summary> /// <param name="other"></param> /// <param name="lin"></param> /// <param name="subtraction"></param> /// <returns></returns> public Node Except <TValue2>(OrderedAvlTree <TKey, TValue2> .Node other, Lineage lin, ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null) { if (IsEmpty || other.IsEmpty) { return(this); } Node thisLesser, thisGreater; Node centralNode; Split(other.Key, out thisLesser, out centralNode, out thisGreater, lin); var thisLesserCount = thisLesser.Count; var thisGreaterCount = thisGreater.Count; var exceptLesser = thisLesser.Except(other.Left, lin, subtraction); var subtracted = centralNode != null && subtraction != null ? subtraction(other.Key, centralNode.Value, other.Value) : Optional.None; var exceptGreater = thisGreater.Except(other.Right, lin, subtraction); var exceptLesserCount = exceptLesser.Count; var exceptGreaterCount = exceptGreater.Count; Node ret; if (subtracted.IsNone) { ret = Concat(exceptLesser, exceptGreater, lin); } else { centralNode = centralNode.WithValue(subtracted.Value, lin); ret = Concat(exceptLesser, centralNode, exceptGreater, lin); } #if ASSERTS AssertEx.AssertTrue(exceptLesserCount <= thisLesserCount); AssertEx.AssertTrue(exceptGreaterCount <= thisGreaterCount); AssertEx.AssertTrue(exceptGreaterCount + exceptLesserCount <= thisLesserCount + thisGreaterCount); AssertEx.AssertTrue(exceptGreater.IsBalanced); #endif return(ret); }
internal ImmSortedMap(OrderedAvlTree <TKey, TValue> .Node root, IComparer <TKey> comparer) { Root = root; Comparer = comparer; }
internal ImmSortedSet(OrderedAvlTree <T, bool> .Node root, IComparer <T> comparer) { Root = root; Comparer = comparer; }
public bool Add(KeyValuePair <TKey, TValue> item) { _inner = _inner.Root_Add(item.Key, item.Value, _comparer, true, _lineage) ?? _inner; return(true); }
Builder(OrderedAvlTree <TKey, TValue> .Node inner, IComparer <TKey> comparer) { _inner = inner; _comparer = comparer; _lineage = Lineage.Mutable(); }
public static ImmSortedSet <T> Wrap <T>(this OrderedAvlTree <T, bool> .Node inner, IComparer <T> eq) { return(new ImmSortedSet <T>(inner, eq)); }
internal static ImmSortedMap <TKey, TValue> WrapMap <TKey, TValue>(this OrderedAvlTree <TKey, TValue> .Node root, IComparer <TKey> comparer) { return(new ImmSortedMap <TKey, TValue>(root, comparer)); }
public Builder(IComparer <T> comparer, OrderedAvlTree <T, bool> .Node inner) { _comparer = comparer; _inner = inner; _lineage = Lineage.Mutable(); }