Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the BigList with elements from the specified collection.
        /// </summary>
        /// <param name="collection">The collection whose elements are copied to the new BigList.</param>
        public BigList(IEnumerable <T> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            var collectionObj = collection as ICollection <T>;

            if (collectionObj != null)
            {
                var count = collectionObj.Count;
                _items = new BigArray <T>(count);
                var index = 0;
                foreach (var item in collectionObj)
                {
                    _items[index++] = item;
                }
                _size = count;
            }
            else
            {
                _size  = 0;
                _items = new BigArray <T>(DefaultCapacity);
                using (var enumerator = collection.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        Add(enumerator.Current);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void ResizeGrow()
        {
            var array = new BigArray <long>(34);

            array.Resize(1002563);

            Assert.Equal(1002563, array.Length);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the BigList with specified capacity.
        /// </summary>
        /// <param name="capacity">Initial capacity.</param>
        public BigList(long capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity");
            }

            _items = new BigArray <T>(capacity);
        }
Ejemplo n.º 4
0
        public static void CopyToBigArray()
        {
            var array = new BigArray <long>(32);

            array[0] = 33;
            array[2] = 918;

            var dest = new BigArray <long>(34);

            array.CopyTo(2, dest, 0, 30);
            Assert.Equal(34, dest.Length);
            Assert.Equal(918, dest[0]);
        }
Ejemplo n.º 5
0
        public static void CopyToArray()
        {
            var array = new BigArray <long>(32);

            array[0] = 33;
            array[2] = 918;

            var dest = new long[5];

            array.CopyTo(0, dest, 0, 5);

            Assert.Equal(33, dest[0]);
            Assert.Equal(918, dest[2]);
        }
Ejemplo n.º 6
0
        public static void Construct2000FromBigArray()
        {
            var array = new BigArray <long>(2000);

            for (int i = 0; i < 2000; i++)
            {
                array[i] = i * 2;
            }

            var list = new BigList <long>(array);

            Assert.Equal(2000, list.Count);
            Assert.Equal(1999 * 2, list[list.Count - 1]);
        }
Ejemplo n.º 7
0
        public static void Clear()
        {
            var array = new BigArray <long>(5);

            array[0] = 22;
            array[1] = 90;
            array[2] = 19920020339484;

            BigArray <long> .Clear(array, 0, 5);

            Assert.Equal(5, array.Length);
            Assert.Equal(0, array[0]);
            Assert.Equal(0, array[1]);
            Assert.Equal(0, array[2]);
        }
Ejemplo n.º 8
0
        public static BigArray <T> ToBigArray <T>(this IEnumerable <T> source)
        {
            if (source is BigArray <T> )
            {
                return((BigArray <T>)source);
            }

            var  size  = source.LongCount();
            var  array = new BigArray <T>(size);
            long index = 0;

            foreach (var item in source)
            {
                array[index++] = item;
            }

            return(array);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Initialize a new big list with a collection and known size.
        /// </summary>
        /// <param name="collection">Items to add</param>
        /// <param name="collectionCount">Size of list</param>
        public BigList(IEnumerable <T> collection, long collectionCount)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (collectionCount < 0)
            {
                throw new ArgumentException("Cannot make new big list with < 0 items", "collectionCount");
            }
            _items = new BigArray <T>(collectionCount);
            var index = 0;

            foreach (var item in collection)
            {
                _items[index++] = item;
            }
            _size = collectionCount;
        }
Ejemplo n.º 10
0
        public static void QuickSort(BigArray <T> elements, long left, long right)
        {
            long i = left, j = right;
            var  pivot = elements[(left + right) / 2];

            while (i <= j)
            {
                while (comparer.Compare(elements[i], pivot) < 0)
                {
                    i++;
                }

                while (comparer.Compare(elements[j], pivot) > 0)
                {
                    j--;
                }

                if (i <= j)
                {
                    // Swap
                    var tmp = elements[i];
                    elements[i] = elements[j];
                    elements[j] = tmp;

                    i++;
                    j--;
                }
            }

            // Recursive calls
            if (left < j)
            {
                QuickSort(elements, left, j);
            }

            if (i < right)
            {
                QuickSort(elements, i, right);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 ///     Initializes a new instance of the BigList.
 /// </summary>
 public BigList()
 {
     _items = _emptyArray;
 }
Ejemplo n.º 12
0
 private BigArray(BigArray <T> other)
 {
     this.items = (T[][])other.items.Clone();
     BlockSize  = other.BlockSize;
     Length     = other.Length;
 }