// filters in parallel, returns elements in correct order
static L parallelFilter(Iterable it, IPred f) ctex {
if (it == null) null;
new L> out;
int poolSize = coresToUse_fixed(), queueSize = 500;
if (poolSize <= 1) ret filter(it, f);
NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS);
try {
int i = 0;
for (A o : it) {
++i;
int _i = i;
e.execute(r { pcall {
if (f.get(o)) synchronized(out) {
out.add(pair(o, _i));
}
}});
}
e.shutdown();
e.awaitTermination(1, TimeUnit.DAYS);
} finally {
e.shutdown();
}
ret firstOfPairs(sortBySecondOfPairs_inPlace(out));
}