I wish to read/write an array (and update another one) with a parallelStream
, without an index.
AtomicInteger
doesn't allow bitwise operations, and using j.get() * 2
is slow:
final int[] j = {0};
ps.parallelStream().forEach(p -> {
long k = next[j[0] << 1];
for(; k < finalK; k += p)
seg[(int) (k >>> S)] |= (1L << (k & BMASK));
next[j[0] << 1] = (k - finalK);
k = next[j[0] << 1 | 1];
for(; k < finalK; k+= p)
seg[(int) (k >>> S)] |= (1L << (k & BMASK));
next[j[0] << 1 | 1] = (k - finalK);
j[0]++;
});
This is working in a sequential stream, not in parallel.
Sorry, if the seg[(int) (k >>> S)] |= (1L << (k & BMASK));
seems unreadable, it's just the same as setting the bit k of a BitSet(seg is a long[]), wich is too much slow for my purpose.