diff --git a/src/rhp.rs b/src/rhp.rs index 049927f..0528c2f 100644 --- a/src/rhp.rs +++ b/src/rhp.rs @@ -17,16 +17,14 @@ pub fn sector_root(sector: &[u8]) -> Hash256 { .map(|chunk| sum_leaf(¶ms, chunk)) .collect::>(); - let mut step_size = 1; - while step_size < tree_hashes.len() { + let mut chunk_size = 2; + while chunk_size <= tree_hashes.len() { tree_hashes - .par_iter_mut() - .step_by(step_size) - .chunks(2) - .for_each(|mut nodes| { - *nodes[0] = sum_node(¶ms, nodes[0], nodes[1]); + .par_chunks_exact_mut(chunk_size) + .for_each(|nodes| { + nodes[0] = sum_node(¶ms, &nodes[0], &nodes[nodes.len() / 2]); }); - step_size *= 2; + chunk_size *= 2; } Hash256::from(tree_hashes[0]) }