6 internal static class AggregationMinMaxHelpers<
T>
10 Func<Pair<bool, T>,
T, Pair<bool, T>> intermediateReduce = MakeIntermediateReduceFunction(sign);
11 Func<Pair<bool, T>, Pair<bool, T>, Pair<bool, T>> finalReduce = MakeFinalReduceFunction(sign);
12 Func<Pair<bool, T>,
T> resultSelector = MakeResultSelectorFunction();
13 AssociativeAggregationOperator<T, Pair<bool, T>,
T> associativeAggregationOperator =
new AssociativeAggregationOperator<T, Pair<bool, T>,
T>(source,
new Pair<bool, T>(first:
false,
default(
T)),
null, seedIsSpecified:
true, intermediateReduce, finalReduce, resultSelector,
default(
T) !=
null, QueryAggregationOptions.AssociativeCommutative);
14 return associativeAggregationOperator.Aggregate();
19 return Reduce(source, -1);
24 return Reduce(source, 1);
27 private static Func<Pair<bool, T>,
T, Pair<bool, T>> MakeIntermediateReduceFunction(
int sign)
30 return delegate(Pair<bool, T> accumulator,
T element)
32 if ((
default(
T) !=
null || element !=
null) && (!accumulator.First || Util.Sign(comparer.
Compare(element, accumulator.Second)) == sign))
34 return new Pair<bool, T>(first:
true, element);
40 private static Func<Pair<bool, T>, Pair<bool, T>, Pair<bool, T>> MakeFinalReduceFunction(
int sign)
43 return delegate(Pair<bool, T> accumulator, Pair<bool, T> element)
45 if (element.First && (!accumulator.First || Util.Sign(comparer.
Compare(element.Second, accumulator.Second)) == sign))
47 return new Pair<bool, T>(first:
true, element.Second);
53 private static Func<Pair<bool, T>,
T> MakeResultSelectorFunction()
55 return (Pair<bool, T> accumulator) => accumulator.Second;
Provides a base class for implementations of the T:System.Collections.Generic.IComparer`1 generic int...
abstract int Compare(T x, T y)
When overridden in a derived class, performs a comparison of two objects of the same type and returns...