Пример #1
0
        public static T[] ToArray <T>(this IEnumerable <T> collection, EnlargingCoefficient coefficient)
        {
            var shift = coefficient switch
            {
                EnlargingCoefficient.By2 => 1,
                EnlargingCoefficient.By4 => 2,
                EnlargingCoefficient.By8 => 3,
                _ => 1
            };

            using var enumerator = collection.GetEnumerator();
            var current       = 0;
            var currentLength = 8;
            var result        = new T[8];

            while (enumerator.MoveNext())
            {
                if (current >= currentLength)
                {
                    EnlargeExtensions.LogEnlargeArray(shift, ref result, ref currentLength);
                }
                result[current] = enumerator.Current;
                current++;
            }
            return(SimpleArrayExtensions.EnsureFullArray(result, current));
        }
Пример #2
0
        public static SimpleList <T> ToSimpleList <T>(this IEnumerable <T> enumerable, EnlargingCoefficient coefficient = EnlargingCoefficient.By2)
        {
            var shift = coefficient switch
            {
                EnlargingCoefficient.By2 => 1,
                EnlargingCoefficient.By4 => 2,
                EnlargingCoefficient.By8 => 3,
                _ => 1
            };

            using var enumerator = enumerable.GetEnumerator();
            var current       = 0;
            var currentLength = 8;
            var result        = new T[8];

            while (enumerator.MoveNext())
            {
                if (current >= currentLength)
                {
                    EnlargeExtensions.LogEnlargeArray(shift, ref result, ref currentLength);
                }
                result[current] = enumerator.Current;
                current++;
            }
            var simpleList = new SimpleList <T>();

            simpleList.Items = result;
            simpleList.Count = current;
            return(simpleList);
        }