| 1 |
use alloc::collections::LinkedList; |
| 2 |
use alloc::vec::Vec; |
| 3 |
|
| 4 |
use rayon::iter::{IntoParallelIterator, ParallelIterator}; |
| 5 |
|
| 6 |
/// Helper for collecting parallel iterators to an intermediary |
| 7 |
#[allow(clippy::linkedlist)] // yes, we need linked list here for efficient appending! |
| 8 |
pub(super) fn collect<I: IntoParallelIterator>(iter: I) -> (LinkedList<Vec<I::Item>>, usize) { |
| 9 |
let list = iter |
| 10 |
.into_par_iter() |
| 11 |
.fold(Vec::new, |mut vec, elem| { |
| 12 |
vec.push(elem); |
| 13 |
vec |
| 14 |
}) |
| 15 |
.map(|vec| { |
| 16 |
let mut list = LinkedList::new(); |
| 17 |
list.push_back(vec); |
| 18 |
list |
| 19 |
}) |
| 20 |
.reduce(LinkedList::new, |mut list1, mut list2| { |
| 21 |
list1.append(&mut list2); |
| 22 |
list1 |
| 23 |
}); |
| 24 |
|
| 25 |
let len = list.iter().map(Vec::len).sum(); |
| 26 |
(list, len) |
| 27 |
} |