use crate::block::xor_blocks;
use std::thread::spawn;
use super::serial_digest::serial_arb_digest;
#[inline(always)]
pub fn parallel_arb_digest<const RND: u64, const LEN: usize>(
input: &[[u8; LEN]],
threads: usize,
) -> [u8; LEN] {
let mut output = [0u8; LEN];
let workload_len = input.len() / threads;
let mut thread_handles: Vec<_> = input
.chunks(workload_len)
.enumerate()
.map(|(i, chunk)| {
let section_blocks = chunk.to_owned();
let offset = workload_len * i;
spawn(move || serial_arb_digest::<RND, LEN>(§ion_blocks, offset))
})
.collect();
while let Some(worker) = thread_handles.pop() {
output = xor_blocks(&output, &worker.join().unwrap());
}
output
}