Ejemplo n.º 1
0
        /// <summary>
        /// Creates a shallow copy of a range of elements in the source <see cref="BigArray{T}"/>.
        /// </summary>
        /// <param name="index">The zero-based <see cref="BigArray{T}"/> index at which the range starts.</param>
        /// <param name="count">The number of elements in the range.</param>
        /// <returns></returns>
        public BigArray <T> GetRange(int index, int count)
        {
            if (!this.IsValidRange(index, count))
            {
                throw new ArgumentOutOfRangeException();
            }

            var newArray = new BigArray <T>();

            if (count == 0)
            {
                return(newArray);
            }

            var enumerator = GetEnumerator();

            ((BigArrayEnumerator)enumerator).MoveToIndex(index);
            bool isContinue = true;

            while (isContinue && count != 0)
            {
                newArray.Add(enumerator.Current);

                count--;
                isContinue = enumerator.MoveNext();
            }

            return(newArray);
        }
Ejemplo n.º 2
0
            //API

            /// <summary>
            /// Supports a iteration over a <see cref="BigArray"/> collection.
            /// </summary>
            /// <param name="array"><see cref="BigArray"/> object using for enumerate it.</param>
            public BigArrayEnumerator(BigArray <T> array)
            {
                Array            = array;
                _blockCollection = Array._blockCollection;
                _blockCount      = _blockCollection.Count;

                if (Array.Count != 0)
                {
                    Reset();
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the elements in the current <see cref="BigArray{T}"/> to another type, and returns a list containing the converted elements.
        /// </summary>
        /// <typeparam name="TOutput">The type of the elements of the target array.</typeparam>
        /// <param name="converter">A Converter{TInput, TOutput} delegate that converts each element from one type to another type.</param>
        /// <returns>A <see cref="BigArray{T}"/> of the target type containing the converted elements from the current <see cref="BigArray{T}"/>.</returns>
        public BigArray <TOutput> ConvertAll <TOutput>(Converter <T, TOutput> converter)
        {
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            var result = new BigArray <TOutput>();

            //Convert all blocks
            foreach (var block in _blockCollection)
            {
                result._blockCollection.Add(block.ConvertAll(converter));
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves all the elements that match the conditions defined by the specified predicate.
        /// </summary>
        /// <param name="match">The Predicate{T} delegate that defines the conditions of the elements to search for.</param>
        /// <param name="isSaveOrder">If flag is true - return suitable elements in right order, otherwise - order doesn't matter.</param>
        /// <returns>A <see cref="BigArray{T}"/> containing all the elements that match the conditions defined by the specified predicate,
        /// if found; otherwise, an empty <see cref="BigArray{T}"/>.</returns>
        public BigArray <T> FindAll(Predicate <T> match, bool isSaveOrder = false)
        {
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }

            var resultArray = new BigArray <T>();

            if (isSaveOrder)
            {
                foreach (var block in _blockCollection)
                {
                    var findData = block.FindAll(match);

                    if (findData.Count != 0)
                    {
                        resultArray.AddRange(findData);
                    }
                }
            }
            else
            {
                object locker = new object();

                Parallel.ForEach(_blockCollection, block =>
                {
                    var findData = block.FindAll(match);

                    lock (locker)
                    {
                        if (findData.Count != 0)
                        {
                            resultArray.AddRange(findData);
                        }
                    }
                });
            }

            return(resultArray);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BigStack{T}"/> class that contains elements copied from the specified collection.
 /// </summary>
 /// <param name="collection">The collection to copy elements from.</param>
 public BigStack(ICollection <T> collection)
 {
     _array = new BigArray <T>(collection);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Crerate new instance of <see cref="BigQueue{T}"/> using specified collection.
 /// </summary>
 /// <param name="collection">Collection whitch use as base for the new <see cref="BigQueue{T}"/>.
 /// The collection it self can't be null, but it can contains elements that are null, if type T is a reference type.</param>
 public BigQueue(ICollection <T> collection)
 {
     _array = new BigArray <T>(collection);
 }