Java 类java.util.function.IntBinaryOperator 实例源码
项目:jdk8u-jdk
文件:PrimitiveSumMinMaxTest.java
public void testIntMethods() {
BinaryOperator<Integer> sum1 = Integer::sum;
IntBinaryOperator sum2 = Integer::sum;
BinaryOperator<Integer> max1 = Integer::max;
IntBinaryOperator max2 = Integer::max;
BinaryOperator<Integer> min1 = Integer::min;
IntBinaryOperator min2 = Integer::min;
Comparator<Integer> cmp = Integer::compare;
int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
for (int i : numbers) {
for (int j : numbers) {
assertEquals(i+j, (int) sum1.apply(i, j));
assertEquals(i+j, sum2.applyAsInt(i, j));
assertEquals(Math.max(i,j), (int) max1.apply(i, j));
assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
assertEquals(Math.min(i,j), (int) min1.apply(i, j));
assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
}
}
}
项目:openjdk-jdk10
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntBiFunction<? super K, ? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceMappingsToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceMappingsToIntTask<K,V>
t = (MapReduceMappingsToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:math
文件:MuVector4i.java
@NonNull
@Override
public MuVector4i map(@NonNull final Vector4i that, @NonNull final IntBinaryOperator operator) {
this.x = operator.applyAsInt(this.x, that.x());
this.y = operator.applyAsInt(this.y, that.y());
this.z = operator.applyAsInt(this.z, that.z());
this.w = operator.applyAsInt(this.w, that.w());
return this;
}
项目:math
文件:MuVector3i.java
@NonNull
@Override
public MuVector3i map(@NonNull final Vector3i that, @NonNull final IntBinaryOperator operator) {
this.x = operator.applyAsInt(this.x, that.x());
this.y = operator.applyAsInt(this.y, that.y());
this.z = operator.applyAsInt(this.z, that.z());
return this;
}
项目:math
文件:MuVector2i.java
@NonNull
@Override
public MuVector2i map(@NonNull final Vector2i that, @NonNull final IntBinaryOperator operator) {
this.x = operator.applyAsInt(this.x, that.x());
this.y = operator.applyAsInt(this.y, that.y());
return this;
}
项目:util4j
文件:GridOperator.java
public int traverseGrid(IntBinaryOperator func) {
AtomicInteger at = new AtomicInteger();
traversalX.forEach(t_x -> {
traversalY.forEach(t_y -> {
at.addAndGet(func.applyAsInt(t_x, t_y));
});
});
return at.get();
}
项目:PurificatiMagicae
文件:EquationOperations.java
private static BiFunction<Integer, Integer, Pair<Integer, Integer[]>> createEqOp(IntBinaryOperator simpleOp)
{
return (x, y) ->
{
int res = simpleOp.applyAsInt(x, y);
return Pair.of(x, new Integer[]{y, res});
};
}
项目:atomic
文件:AtomicIntegerArray.java
public final int getAndAccumulate(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 prev;
}
项目:atomic
文件:AtomicIntegerArray.java
public final 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;
}
项目:atomic
文件:AtomicInteger.java
public final int getAndAccumulate(int x, IntBinaryOperator accumulatorFunction) {
int prev, next;
do {
prev = value;
next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return prev;
}
项目:atomic
文件:AtomicInteger.java
public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) {
int prev, next;
do {
prev = value;
next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return next;
}
项目:jvb
文件:CPU.java
private void bitStringArithmeticAlignedWords(IntBinaryOperator op, int sourceAddr, int destinationAddr, int length) {
for (int i = 0; i < length; i++) {
int src = bus.getWord(sourceAddr + i * Integer.BYTES);
int dst = bus.getWord(destinationAddr + i * Integer.BYTES);
bus.setWord(destinationAddr + i * Integer.BYTES, op.applyAsInt(src, dst));
}
}
项目:OpenJSharp
文件:ReduceOps.java
/**
* Constructs a {@code TerminalOp} that implements a functional reduce on
* {@code int} values.
*
* @param identity the identity for the combining function
* @param operator the combining function
* @return a {@code TerminalOp} implementing the reduction
*/
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
Objects.requireNonNull(operator);
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 ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
项目:OpenJSharp
文件:ArrayPrefixHelpers.java
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
IntBinaryOperator function,
int[] array, int lo, int hi) {
super(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.getCommonPoolParallelism() << 3))
<= MIN_PARTITION ? MIN_PARTITION : p;
}
项目:Vanilla-Injection
文件:Vec3I.java
private static BinaryOperator<Vec3I> getBinaryOperator(IntBinaryOperator op) {
return (a, b) -> {
int x = op.applyAsInt(a.x, b.x);
int y = op.applyAsInt(a.y, b.y);
int z = op.applyAsInt(a.z, b.z);
return new Vec3I(x, y, z);
};
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
MapReduceKeysToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceKeysToIntTask<K,V> nextRight,
ToIntFunction<? super K> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<? super K> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceKeysToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.key));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceKeysToIntTask<K,V>
t = (MapReduceKeysToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
MapReduceValuesToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceValuesToIntTask<K,V> nextRight,
ToIntFunction<? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceValuesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceValuesToIntTask<K,V>
t = (MapReduceValuesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
MapReduceEntriesToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceEntriesToIntTask<K,V> nextRight,
ToIntFunction<Map.Entry<K,V>> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<Map.Entry<K,V>> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceEntriesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceEntriesToIntTask<K,V>
t = (MapReduceEntriesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
MapReduceMappingsToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceMappingsToIntTask<K,V> nextRight,
ToIntBiFunction<? super K, ? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:OpenJSharp
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntBiFunction<? super K, ? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceMappingsToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceMappingsToIntTask<K,V>
t = (MapReduceMappingsToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:jdk8u-jdk
文件:ReduceOps.java
/**
* Constructs a {@code TerminalOp} that implements a functional reduce on
* {@code int} values.
*
* @param identity the identity for the combining function
* @param operator the combining function
* @return a {@code TerminalOp} implementing the reduction
*/
public static TerminalOp<Integer, Integer>
makeInt(int identity, IntBinaryOperator operator) {
Objects.requireNonNull(operator);
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 ReduceOp<Integer, Integer, ReducingSink>(StreamShape.INT_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
项目:openjdk-jdk10
文件:ConcurrentHashMap.java
MapReduceValuesToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceValuesToIntTask<K,V> nextRight,
ToIntFunction<? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:openjdk-jdk10
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceValuesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceValuesToIntTask<K,V>
t = (MapReduceValuesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:openjdk-jdk10
文件:ParallelPrefix.java
@DataProvider(name = "intSet")
public static Object[][] intSet(){
return genericData(size -> IntStream.range(0, size).toArray(),
new IntBinaryOperator[]{
Integer::sum,
Integer::min});
}
项目:jdk8u-jdk
文件:ArrayPrefixHelpers.java
/** Root task constructor */
public IntCumulateTask(IntCumulateTask parent,
IntBinaryOperator function,
int[] array, int lo, int hi) {
super(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.getCommonPoolParallelism() << 3))
<= MIN_PARTITION ? MIN_PARTITION : p;
}
项目:jdk8u-jdk
文件:ArrayPrefixHelpers.java
/** Subtask constructor */
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
int[] array, int origin, int fence, int threshold,
int lo, int hi) {
super(parent);
this.function = function; this.array = array;
this.origin = origin; this.fence = fence;
this.threshold = threshold;
this.lo = lo; this.hi = hi;
}
项目:openjdk-jdk10
文件:ConcurrentHashMap.java
MapReduceMappingsToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceMappingsToIntTask<K,V> nextRight,
ToIntBiFunction<? super K, ? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:openjdk-jdk10
文件:ParallelPrefix.java
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
int[] sequentialResult = data.clone();
for (int index = fromIndex + 1; index < toIndex; index++) {
sequentialResult[index ] = op.applyAsInt(sequentialResult[index - 1], sequentialResult[index]);
}
int[] parallelResult = data.clone();
Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
assertArraysEqual(parallelResult, sequentialResult);
int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
Arrays.parallelPrefix(parallelRangeResult, op);
assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
MapReduceKeysToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceKeysToIntTask<K,V> nextRight,
ToIntFunction<? super K> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<? super K> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceKeysToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.key));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceKeysToIntTask<K,V>
t = (MapReduceKeysToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
MapReduceValuesToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceValuesToIntTask<K,V> nextRight,
ToIntFunction<? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceValuesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceValuesToIntTask<K,V>
t = (MapReduceValuesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:openjdk-jdk10
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<Map.Entry<K,V>> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceEntriesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceEntriesToIntTask<K,V>
t = (MapReduceEntriesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntFunction<Map.Entry<K,V>> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceEntriesToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceEntriesToIntTask<K,V>
t = (MapReduceEntriesToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
MapReduceMappingsToIntTask
(BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
MapReduceMappingsToIntTask<K,V> nextRight,
ToIntBiFunction<? super K, ? super V> transformer,
int basis,
IntBinaryOperator reducer) {
super(p, b, i, f, t); this.nextRight = nextRight;
this.transformer = transformer;
this.basis = basis; this.reducer = reducer;
}
项目:jdk8u-jdk
文件:ConcurrentHashMap.java
public final void compute() {
final ToIntBiFunction<? super K, ? super V> transformer;
final IntBinaryOperator reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
int r = this.basis;
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceMappingsToIntTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, r, reducer)).fork();
}
for (Node<K,V> p; (p = advance()) != null; )
r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceMappingsToIntTask<K,V>
t = (MapReduceMappingsToIntTask<K,V>)c,
s = t.rights;
while (s != null) {
t.result = reducer.applyAsInt(t.result, s.result);
s = t.rights = s.nextRight;
}
}
}
}
项目:jdk8u-jdk
文件:ParallelPrefix.java
@DataProvider
public static Object[][] intSet(){
return genericData(size -> IntStream.range(0, size).toArray(),
new IntBinaryOperator[]{
Integer::sum,
Integer::min});
}