> Zip <TOutItem, TFirstItem>(
            BuiltInEnumerable <TFirstItem> first,
            ReverseRangeEnumerable second,
            Func <TFirstItem, int, TOutItem> resultSelector
            )
        {
            var firstBridged = Bridge(first, nameof(first));

            if (second.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(second));
            }
            if (resultSelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(resultSelector));
            }

            return
                (CommonImplementation.ZipImpl <
                     TOutItem,
                     TFirstItem,
                     int,
                     BuiltInEnumerable <TFirstItem>,
                     BuiltInEnumerator <TFirstItem>,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(RefLocal(firstBridged), ref second, resultSelector));
        }
Beispiel #2
0
        // ReverseRangeEnumerable

        public double Average(ReverseRangeEnumerable source)
        {
            if (source.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(source));
            }
            if (source.InnerCount == 0)
            {
                throw CommonImplementation.SequenceEmpty();
            }

            // 6 5 4
            //   ^

            // 4 3 2 1
            //    ^

            var    leftIx = source.InnerCount / 2;
            double left   = source.Start - leftIx;

            if (source.InnerCount % 2 == 0)
            {
                // even
                double right = left - 1;

                return((left + right) / 2.0);
            }
            else
            {
                // odd
                return(left);
            }
        }
        // ReverseRangeEnumerable

        public bool SequenceEqual(
            PlaceholderEnumerable <int> first,
            ReverseRangeEnumerable second
            )
        {
            return
                (CommonImplementation.SequenceEqual <
                     int,
                     PlaceholderEnumerable <int>,
                     PlaceholderEnumerator <int>,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(RefParam(first), ref second, null));
        }
 public bool SequenceEqual(
     ReverseRangeEnumerable first,
     RangeEnumerable second
     )
 {
     return
         (CommonImplementation.SequenceEqual <
              int,
              ReverseRangeEnumerable,
              ReverseRangeEnumerator,
              RangeEnumerable,
              RangeEnumerator
              >(ref first, ref second, null));
 }
 public bool SequenceEqual(
     ReverseRangeEnumerable first,
     RangeEnumerable second,
     IEqualityComparer <int> comparer
     )
 {
     return
         (CommonImplementation.SequenceEqual <
              int,
              ReverseRangeEnumerable,
              ReverseRangeEnumerator,
              RangeEnumerable,
              RangeEnumerator
              >(ref first, ref second, comparer));
 }
Beispiel #6
0
        // ReverseRangeEnumerable

        public int Sum(ReverseRangeEnumerable source)
        {
            if (source.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(source));
            }
            if (source.InnerCount == 0)
            {
                return(0);
            }

            long last   = source.Start;
            long first  = last - source.InnerCount + 1;
            var  length = source.InnerCount;

            // https://math.stackexchange.com/a/50487/111
            // sum of range [a, b] = (a + b) / 2 * ((b - a) + 1)
            // count = b - a + 1
            // 2 * sum = (a + b) * ((b - a) + 1)

            // 0 1 2 3
            //   a = 0
            //   b = 3
            //   (a + b) = 3
            //   (b - a) + 1 = 4
            //   (a + b) * ((b - a) + 1) = 12
            //   sum = 12 / 2 = 6

            // 1 2 3 4 5
            //   a = 1
            //   b = 5
            //   (a + b) = 6
            //   (b - a) + 1 = 5
            //   (a + b) * ((b - a) + 1) = 30
            //   sum = 30 / 2 = 15

            long twiceSum = (first + last);

            twiceSum *= length;
            long ret = twiceSum / 2;

            checked
            {
                return((int)ret);
            }
        }
 public ConcatEnumerable <int, ReverseRangeEnumerable, ReverseRangeEnumerator, RangeEnumerable, RangeEnumerator> Concat(
     ReverseRangeEnumerable first,
     RangeEnumerable second
     )
 {
     return
         (CommonImplementation.Concat <
              int,
              ReverseRangeEnumerable,
              ReverseRangeEnumerator,
              RangeEnumerable,
              RangeEnumerator
              >(
              ref first,
              ref second
              ));
 }
        // ReverseRangeEnumerable

        public ConcatEnumerable <int, PlaceholderEnumerable <int>, PlaceholderEnumerator <int>, ReverseRangeEnumerable, ReverseRangeEnumerator> Concat(
            PlaceholderEnumerable <int> first,
            ReverseRangeEnumerable second
            )
        {
            return
                (CommonImplementation.Concat <
                     int,
                     PlaceholderEnumerable <int>,
                     PlaceholderEnumerator <int>,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(
                     RefParam(first),
                     ref second
                     ));
        }
            > Except(
            BuiltInEnumerable <int> first,
            ReverseRangeEnumerable second
            )
        {
            var firstBridge = Bridge(first, nameof(first));

            if (second.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(second));
            }

            return(CommonImplementation.ExceptImpl <
                       int,
                       BuiltInEnumerable <int>,
                       BuiltInEnumerator <int>,
                       ReverseRangeEnumerable,
                       ReverseRangeEnumerator
                       >(RefLocal(firstBridge), ref second));
        }
Beispiel #10
0
            > Join <TOutItem, TJoinKeyItem, TJoinLeftItem>(
            BuiltInEnumerable <TJoinLeftItem> outer,
            ReverseRangeEnumerable inner,
            Func <TJoinLeftItem, TJoinKeyItem> outerKeySelector,
            Func <int, TJoinKeyItem> innerKeySelector,
            Func <TJoinLeftItem, int, TOutItem> resultSelector,
            IEqualityComparer <TJoinKeyItem> comparer
            )
        {
            var outerBridge = Bridge(outer, nameof(outer));

            if (inner.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(inner));
            }

            if (outerKeySelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(outerKeySelector));
            }
            if (innerKeySelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(innerKeySelector));
            }
            if (resultSelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(resultSelector));
            }

            return
                (CommonImplementation.JoinImpl <
                     TOutItem,
                     TJoinKeyItem,
                     TJoinLeftItem,
                     BuiltInEnumerable <TJoinLeftItem>,
                     BuiltInEnumerator <TJoinLeftItem>,
                     int,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(RefLocal(outerBridge), ref inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
        }
            > GroupJoin <TResult, TGroupJoinKey, TOuter>(
            BuiltInEnumerable <TOuter> outer,
            ReverseRangeEnumerable inner,
            Func <TOuter, TGroupJoinKey> outerKeySelector,
            Func <int, TGroupJoinKey> innerKeySelector,
            Func <TOuter, GroupedEnumerable <TGroupJoinKey, int>, TResult> resultSelector
            )
        {
            var outerBridge = Bridge(outer, nameof(outer));

            if (inner.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(inner));
            }
            if (outerKeySelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(outerKeySelector));
            }
            if (innerKeySelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(innerKeySelector));
            }
            if (resultSelector == null)
            {
                throw CommonImplementation.ArgumentNull(nameof(resultSelector));
            }

            return
                (CommonImplementation.GroupJoinImpl <
                     TResult,
                     TGroupJoinKey,
                     TOuter,
                     BuiltInEnumerable <TOuter>,
                     BuiltInEnumerator <TOuter>,
                     int,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(RefLocal(outerBridge), ref inner, outerKeySelector, innerKeySelector, resultSelector));
        }
Beispiel #12
0
        public bool SequenceEqual(
            BuiltInEnumerable <int> first,
            ReverseRangeEnumerable second,
            IEqualityComparer <int> comparer
            )
        {
            var firstBridge = Bridge(first, nameof(second));

            if (second.IsDefaultValue())
            {
                throw CommonImplementation.Uninitialized(nameof(second));
            }

            return
                (CommonImplementation.SequenceEqualImpl <
                     int,
                     BuiltInEnumerable <int>,
                     BuiltInEnumerator <int>,
                     ReverseRangeEnumerable,
                     ReverseRangeEnumerator
                     >(RefLocal(firstBridge), ref second, comparer));
        }
 public static System.Collections.Generic.LinkedList <int> LinkedList(ReverseRangeEnumerable second)
 => LinkedListImpl <int, ReverseRangeEnumerable, ReverseRangeEnumerator>(ref second);
 public static System.Collections.Generic.Stack <int> Stack(ReverseRangeEnumerable second)
 => StackImpl <int, ReverseRangeEnumerable, ReverseRangeEnumerator>(ref second);
 public static System.Collections.Generic.Queue <int> Queue(ReverseRangeEnumerable second)
 => QueueImpl <int, ReverseRangeEnumerable, ReverseRangeEnumerator>(ref second);