Beispiel #1
0
        /// <summary>
        ///     Adds a sequence of items to the end of the collection.
        /// </summary>
        /// <param name="items">A sequence of items to add. Faster if the sequence is an array or a known collection type.</param>
        /// <exception cref="ArgumentNullException">Thrown if the argument is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the collection exceeds its capacity.</exception>
        /// <remarks>This member performs a lot better when the specified sequence is an array.</remarks>
        public ImmVector <T> AddLastRange(IEnumerable <T> items)
        {
            items.CheckNotNull("items");
#if ASSERTS
            var expected = Length;
            var oldLast  = TryLast;
#endif
            var len = 0;
            var s   = 0;
            if (IsEmpty)
            {
                var asVector = items as ImmVector <T>;
                if (asVector != null)
                {
                    return(asVector);
                }
            }
            var arr    = items.ToArrayFast(out len);
            var oldLen = len;
            if (Root.Length + len >= MaxCapacity)
            {
                throw Errors.Capacity_exceeded();
            }
            ImmVector <T> ret = Root.AddRange(arr, Lineage.Mutable(), 6, ref s, ref len);
#if ASSERTS
            ret.Length.AssertEqual(expected + oldLen);
            if (arr.Length > 0 && oldLen > 0)
            {
                ret.Last.AssertEqual(arr[oldLen - 1]);
            }
            else if (oldLast.IsSome)
            {
                ret.Last.AssertEqual(oldLast.Value);
            }
#endif
            return(ret);
        }
Beispiel #2
0
            public void AddRange(IEnumerable <T> items)
            {
                items.CheckNotNull("items");
                if (_inner.Length == 0)
                {
                    var vector = items as ImmVector <T>;
                    if (vector != null)
                    {
                        _inner = vector;
                        return;
                    }
                }
                int len;
                var arr = items.ToArrayFast(out len);
                var s   = 0;

                _inner = _inner.AddRange(arr, _lineage, 6, ref s, ref len);
            }