parallel_chunks

Function parallel_chunks 

Source
pub fn parallel_chunks<T>(data: Vec<T>, chunk_size: usize) -> Vec<Vec<T>>
where T: Send + Sync,
Expand description

Split a vector into chunks of specified size in parallel.

This function divides a vector into chunks of equal size (except possibly the last chunk), similar to itertools::chunks but with parallel processing.

§Type Parameters

  • T: The element type, must be Send + Sync.

§Parameters

  • data: The input vector to chunk.
  • chunk_size: The size of each chunk.

§Returns

A vector of vectors, where each inner vector is a chunk.

§Examples

use trash_analyzer::parallel::parallel_chunks;

let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let chunks = parallel_chunks(data, 3);
assert_eq!(chunks, vec![
    vec![1, 2, 3],
    vec![4, 5, 6],
    vec![7, 8, 9],
    vec![10]
]);