/// <summary> /// Constructs a {@code TerminalOp} that implements a functional reduce on /// {@code int} values. /// </summary> /// <param name="identity"> the identity for the combining function </param> /// <param name="operator"> the combining function </param> /// <returns> a {@code TerminalOp} implementing the reduction </returns> public static TerminalOp <Integer, Integer> MakeInt(int identity, IntBinaryOperator @operator) { Objects.RequireNonNull(@operator); //JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter: // class ReducingSink implements AccumulatingSink<Integer, Integer, ReducingSink>, Sink_OfInt // { // private int state; // // @@Override public void begin(long size) // { // state = identity; // } // // @@Override public void accept(int t) // { // state = @operator.applyAsInt(state, t); // } // // @@Override public Integer get() // { // return state; // } // // @@Override public void combine(ReducingSink other) // { // accept(other.state); // } // } return(new ReduceOpAnonymousInnerClassHelper5()); }
/// <summary> /// Subtask constructor </summary> internal IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function, int[] array, int origin, int fence, int threshold, int lo, int hi) : base(parent) { this.Function = function; this.Array = array; this.Origin = origin; this.Fence = fence; this.Threshold = threshold; this.Lo = lo; this.Hi = hi; }
/// <summary> /// Root task constructor </summary> public IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function, int[] array, int lo, int hi) : base(parent) { this.Function = function; this.Array = array; this.Lo = this.Origin = lo; this.Hi = this.Fence = hi; int p; this.Threshold = (p = (hi - lo) / (ForkJoinPool.CommonPoolParallelism << 3)) <= MIN_PARTITION ? MIN_PARTITION : p; }
/// <summary> /// Atomically updates the current value with the results of /// applying the given function to the current and given values, /// returning the updated value. The function should be /// side-effect-free, since it may be re-applied when attempted /// updates fail due to contention among threads. The function /// is applied with the current value as its first argument, /// and the given update as the second argument. /// </summary> /// <param name="x"> the update value </param> /// <param name="accumulatorFunction"> a side-effect-free function of two arguments </param> /// <returns> the updated value /// @since 1.8 </returns> public int AccumulateAndGet(int x, IntBinaryOperator accumulatorFunction) { int prev, next; do { prev = Get(); next = accumulatorFunction.ApplyAsInt(prev, x); } while (!CompareAndSet(prev, next)); return(next); }
/// <summary> /// Atomically updates the field of the given object managed by this /// updater with the results of applying the given function to the /// current and given values, returning the previous value. The /// function should be side-effect-free, since it may be re-applied /// when attempted updates fail due to contention among threads. The /// function is applied with the current value as its first argument, /// and the given update as the second argument. /// </summary> /// <param name="obj"> An object whose field to get and set </param> /// <param name="x"> the update value </param> /// <param name="accumulatorFunction"> a side-effect-free function of two arguments </param> /// <returns> the previous value /// @since 1.8 </returns> public int GetAndAccumulate(T obj, int x, IntBinaryOperator accumulatorFunction) { int prev, next; do { prev = Get(obj); next = accumulatorFunction.ApplyAsInt(prev, x); } while (!CompareAndSet(obj, prev, next)); return(prev); }
/// <summary> /// Atomically updates the element at index {@code i} with the /// results of applying the given function to the current and /// given values, returning the updated value. The function should /// be side-effect-free, since it may be re-applied when attempted /// updates fail due to contention among threads. The function is /// applied with the current value at index {@code i} as its first /// argument, and the given update as the second argument. /// </summary> /// <param name="i"> the index </param> /// <param name="x"> the update value </param> /// <param name="accumulatorFunction"> a side-effect-free function of two arguments </param> /// <returns> the updated value /// @since 1.8 </returns> public int AccumulateAndGet(int i, int x, IntBinaryOperator accumulatorFunction) { long offset = CheckedByteOffset(i); int prev, next; do { prev = GetRaw(offset); next = accumulatorFunction.ApplyAsInt(prev, x); } while (!CompareAndSetRaw(offset, prev, next)); return(next); }
/// <summary> /// Constructs a {@code TerminalOp} that implements a functional reduce on /// {@code int} values, producing an optional integer result. /// </summary> /// <param name="operator"> the combining function </param> /// <returns> a {@code TerminalOp} implementing the reduction </returns> public static TerminalOp <Integer, OptionalInt> MakeInt(IntBinaryOperator @operator) { Objects.RequireNonNull(@operator); //JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter: // class ReducingSink implements AccumulatingSink<Integer, java.util.OptionalInt, ReducingSink>, Sink_OfInt // { // private boolean empty; // private int state; // // public void begin(long size) // { // empty = true; // state = 0; // } // // @@Override public void accept(int t) // { // if (empty) // { // empty = false; // state = t; // } // else // { // state = @operator.applyAsInt(state, t); // } // } // // @@Override public OptionalInt get() // { // return empty ? OptionalInt.empty() : OptionalInt.of(state); // } // // @@Override public void combine(ReducingSink other) // { // if (!other.empty) // accept(other.state); // } // } return(new ReduceOpAnonymousInnerClassHelper6()); }
public int getAndAccumulate(int arg0, int arg1, IntBinaryOperator arg2) { return Instance.CallMethod<int>("getAndAccumulate", "(IILjava/util/function/IntBinaryOperator;)I", arg0, arg1, arg2); }