2016-08-23 09:33:05 -06:00
|
|
|
// arrays/ParallelPrefix3.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2016-01-25 18:05:55 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2017-01-14 07:41:28 -08:00
|
|
|
// {ValidateByHand} // CI Systems have trouble
|
2016-01-25 18:05:55 -08:00
|
|
|
import java.util.*;
|
|
|
|
|
2016-08-23 09:33:05 -06:00
|
|
|
public class ParallelPrefix3 {
|
2016-07-08 14:13:13 -06:00
|
|
|
static final int SIZE = 10_000_000;
|
2016-01-25 18:05:55 -08:00
|
|
|
public static void main(String[] args) {
|
|
|
|
long[] nums = new long[SIZE];
|
|
|
|
Arrays.setAll(nums, n -> n);
|
|
|
|
Arrays.parallelPrefix(nums, Long::sum);
|
|
|
|
System.out.println("First 20: " + nums[19]);
|
|
|
|
System.out.println("First 200: " + nums[199]);
|
|
|
|
System.out.println("All: " + nums[nums.length-1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
|
|
|
First 20: 190
|
|
|
|
First 200: 19900
|
2016-07-22 14:45:35 -06:00
|
|
|
All: 49999995000000
|
2016-01-25 18:05:55 -08:00
|
|
|
*/
|