Class TransformSemiRing
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Semiring<T>>
T[]Applies a specified function to each element of the given array and returns a new array containing the results of the mapping operation.mapReduce(T[] values, Function<T, T> mapper, BinaryOperator<T> accumulator) Applies a map-reduce procedure to an array ofSemiringvalues.reduce(T[] values, BinaryOperator<T> accumulator) Reduces the given array of field elements to a single element by repeatedly applying a binary operator to combine elements.
-
Method Details
-
mapReduce
public static <T extends Semiring<T>> Semiring mapReduce(T[] values, Function<T, T> mapper, BinaryOperator<T> accumulator) Applies a map-reduce procedure to an array ofSemiringvalues. This is equivalent toreduce(map(values, mapper), accumulator).- Parameters:
values- Values to apply map-reduce to; must not be null.mapper- Mapper to apply during themappingstep; must not be null.accumulator- Accumulator to use during thereductionstep.- Returns:
- The result of applying the map-reduce procedure using the specified
mapperandaccumulatorto thevaluesarray.
-
map
Applies a specified function to each element of the given array and returns a new array containing the results of the mapping operation. This produces a new array where each element is the result of applying the provided
mapperfunction to the corresponding element in the input array.For example, if the array contains elements [a, b, c] and the
mapperfunction multiplies each element by 2, the returned array will contain [2a, 2b, 2c].- Parameters:
values- the array of field elements to map; must not be nullmapper- the mapping function to apply to each element; must not be null- Returns:
- a new array containing the results of applying the
mapperfunction to each element in thevaluesarray - Throws:
NullPointerException- ifvaluesormapperis nullIllegalArgumentException- ifvaluesis empty
-
reduce
Reduces the given array of field elements to a single element by repeatedly applying a binary operator to combine elements. The reduction is performed from left to right, starting with the first element in the array and hence is a "left-reduce" or "left fold".
The
reduceoperation applies the specifiedaccumulatorfunction to the first element and the second element, then applies it to the result and the third element, and so on until all elements have been combined into a single result. The operation assumes that the array contains at least one element.For example, if the array contains elements [a, b, c, d] and the accumulator is a function which adds elements, the method would compute (((a + b) + c) + d).
- Parameters:
values- The array of field elements to reduce. Cannot be empty or null.accumulator- The binary operator to combine elements.- Returns:
- the result of lef-reducing all elements
valuesusing the specifiedaccumulator. - Throws:
IllegalArgumentException- ifvaluesis emptyNullPointerException- ifvaluesoraccumulatoris null
-