extern crate rayon;
use rayon::prelude::*;
const OCTILLION: u128 = 1_000_000_000_000_000_000_000_000_000;
fn octillion() -> rayon::range::Iter<u128> {
(0..OCTILLION).into_par_iter()
}
fn octillion_flat() -> impl ParallelIterator<Item = u128> {
(0u32..1_000_000_000)
.into_par_iter()
.with_max_len(1_000)
.map(|i| i as u64 * 1_000_000_000)
.flat_map(
|i| {
(0u32..1_000_000_000)
.into_par_iter()
.with_max_len(1_000)
.map(move |j| i + j as u64)
}
)
.map(|i| i as u128 * 1_000_000_000)
.flat_map(
|i| {
(0u32..1_000_000_000)
.into_par_iter()
.with_max_len(1_000)
.map(move |j| i + j as u128)
}
)
}
#[test]
fn find_first_octillion() {
let x = octillion().find_first(|_| true);
assert_eq!(x, Some(0));
}
#[test]
fn find_first_octillion_flat() {
let x = octillion_flat().find_first(|_| true);
assert_eq!(x, Some(0));
}
#[test]
fn find_last_octillion() {
let builder = rayon::ThreadPoolBuilder::new().num_threads(2);
let pool = builder.build().unwrap();
let x = pool.install(|| octillion().find_last(|_| true));
assert_eq!(x, Some(OCTILLION - 1));
}
#[test]
fn find_last_octillion_flat() {
let builder = rayon::ThreadPoolBuilder::new().num_threads(2);
let pool = builder.build().unwrap();
let x = pool.install(|| octillion_flat().find_last(|_| true));
assert_eq!(x, Some(OCTILLION - 1));
}