Beispiel #1
0
        /// <summary>
        /// Returns a <see cref="IVector"/> of the items in <see cref="IVector"/> from start (inclusive)
        /// to end (exclusive). If end is not supplied, default to <see cref="Count"/> of <see cref="IVector"/>.
        /// </summary>
        /// <param name="v">An object that implements the <see cref="IVector"/> interface.</param>
        /// <param name="start">The zero-based starting index position.</param>
        /// <param name="end">The number of items.</param>
        /// <returns>
        /// Returns a <see cref="IVector"/> of the items in <see cref="IVector"/> from start (inclusive)
        /// to end (exclusive). If end is not supplied, default to <see cref="Count"/> of <see cref="IVector"/>.
        /// </returns>
        public object Invoke(object v, object start, object end)
        {
            var vec = (IVector)v;

            var s = (int)start;

            if (s < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start), $"{nameof(start)} cannot be less than zero.");
            }

            var e = (int)end;

            if (e < s)
            {
                throw new ArgumentOutOfRangeException(nameof(end), $"{nameof(end)} cannot be less than {nameof(start)}.");
            }
            if (e > vec.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(end), $"{nameof(end)} cannot be greater than the end of the vector.");
            }

            if (s == e)
            {
                return(Collections.Vector.EMPTY);
            }

            return(SubVector.Create(vec, s, e));
        }
Beispiel #2
0
 /// <summary>
 /// Initialize a subvector, with the given metadata and start/end indices.
 /// </summary>
 /// <param name="meta">The metatdata to attach.</param>
 /// <param name="v">The vector to subvector.</param>
 /// <param name="start">The start index of the subvector.</param>
 /// <param name="end">The end index of the subvector.</param>
 public SubVector(IPersistentMap meta, IPersistentVector v, int start, int end)
     : base(meta)
 {
     if (v is SubVector)
     {
         SubVector sv = (SubVector)v;
         start += sv._start;
         end   += sv._start;
         v      = sv._v;
     }
     _v     = v;
     _start = start;
     _end   = end;
 }
Beispiel #3
0
            /// <summary>
            /// Initialize a subvector, with the given metadata and start/end indices.
            /// </summary>
            /// <param name="meta">The metatdata to attach.</param>
            /// <param name="v">The vector to subvector.</param>
            /// <param name="start">The start index of the subvector.</param>
            /// <param name="end">The end index of the subvector.</param>
            public SubVector(IPersistentMap meta, IPersistentVector v, int start, int end)
            {
                _meta = meta;

                SubVector sv = v as SubVector;

                if (sv != null)
                {
                    start += sv._start;
                    end   += sv._start;
                    v      = sv._v;
                }
                _v     = v;
                _start = start;
                _end   = end;
            }