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 ofSemiring
values.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 ofSemiring
values. 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 themapping
step; must not be null.accumulator
- Accumulator to use during thereduction
step.- Returns:
- The result of applying the map-reduce procedure using the specified
mapper
andaccumulator
to thevalues
array.
-
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
mapper
function to the corresponding element in the input array.For example, if the array contains elements [a, b, c] and the
mapper
function 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
mapper
function to each element in thevalues
array - Throws:
NullPointerException
- ifvalues
ormapper
is nullIllegalArgumentException
- ifvalues
is 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
reduce
operation applies the specifiedaccumulator
function 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
values
using the specifiedaccumulator
. - Throws:
IllegalArgumentException
- ifvalues
is emptyNullPointerException
- ifvalues
oraccumulator
is null
-