示例#1
0
            public bool Remove(T item)
            {
                var ret = _inner.AvlRemove(item, _lineage);

                if (ret == null)
                {
                    return(false);
                }
                _inner = ret;
                return(true);
            }
示例#2
0
            public bool Remove(TKey key)
            {
                var ret = _inner.AvlRemove(key, _lineage);

                if (ret == null)
                {
                    return(false);
                }
                _inner = ret;
                return(true);
            }
示例#3
0
            public bool Add(T item)
            {
                var ret = _inner.Root_Add(item, true, _comparer, false, _lineage);

                if (ret == null)
                {
                    return(false);
                }
                _inner = ret;
                return(true);
            }
示例#4
0
            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));
                }
            }
示例#5
0
            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));
                }
            }
示例#6
0
            /// <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);
            }
示例#7
0
 internal ImmSortedMap(OrderedAvlTree <TKey, TValue> .Node root, IComparer <TKey> comparer)
 {
     Root     = root;
     Comparer = comparer;
 }
示例#8
0
 internal ImmSortedSet(OrderedAvlTree <T, bool> .Node root, IComparer <T> comparer)
 {
     Root     = root;
     Comparer = comparer;
 }
示例#9
0
 public bool Add(KeyValuePair <TKey, TValue> item)
 {
     _inner = _inner.Root_Add(item.Key, item.Value, _comparer, true, _lineage) ?? _inner;
     return(true);
 }
示例#10
0
 Builder(OrderedAvlTree <TKey, TValue> .Node inner, IComparer <TKey> comparer)
 {
     _inner    = inner;
     _comparer = comparer;
     _lineage  = Lineage.Mutable();
 }
示例#11
0
 public static ImmSortedSet <T> Wrap <T>(this OrderedAvlTree <T, bool> .Node inner, IComparer <T> eq)
 {
     return(new ImmSortedSet <T>(inner, eq));
 }
示例#12
0
 internal static ImmSortedMap <TKey, TValue> WrapMap <TKey, TValue>(this OrderedAvlTree <TKey, TValue> .Node root,
                                                                    IComparer <TKey> comparer)
 {
     return(new ImmSortedMap <TKey, TValue>(root, comparer));
 }
示例#13
0
 public Builder(IComparer <T> comparer, OrderedAvlTree <T, bool> .Node inner)
 {
     _comparer = comparer;
     _inner    = inner;
     _lineage  = Lineage.Mutable();
 }