| 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: LinkedList::Item>> = iterFold<::Iter, …, …> |
| 10 | .into_par_iter() |
| 11 | .fold(identity:Vec::new, |mut vec: Vec<::Item>, elem: ::Item| { |
| 12 | vec.push(elem); |
| 13 | vec |
| 14 | }) |
| 15 | .map(|vec| { |
| 16 | let mut list: LinkedList<{unknown}> = LinkedList::new(); |
| 17 | list.push_back(elt:vec); |
| 18 | list |
| 19 | }) |
| 20 | .reduce(LinkedList::new, |mut list1, mut list2| { |
| 21 | list1.append(&mut list2); |
| 22 | list1 |
| 23 | }); |
| 24 | |
| 25 | let len: usize = list.iter().map(Vec::len).sum(); |
| 26 | (list, len) |
| 27 | } |
| 28 | |