orx_split_vec/concurrent_iter/
con_iter_ref.rs

1use crate::{Fragment, ParGrowth, SplitVec};
2use orx_concurrent_iter::{
3    IntoConcurrentIter,
4    implementations::jagged_arrays::{ConIterJaggedRef, RawJaggedRef, Slices},
5};
6
7pub struct Fragments<'a, T>(&'a [Fragment<T>]);
8
9impl<T> Clone for Fragments<'_, T> {
10    fn clone(&self) -> Self {
11        Self(self.0)
12    }
13}
14
15impl<'a, T: 'a> Slices<'a, T> for Fragments<'a, T> {
16    fn empty() -> Self {
17        Fragments(Default::default())
18    }
19
20    fn num_slices(&self) -> usize {
21        self.0.len()
22    }
23
24    fn slices(&self) -> impl Iterator<Item = &'a [T]> {
25        self.0.iter().map(|x| x.as_slice())
26    }
27
28    fn lengths(&self) -> impl Iterator<Item = usize> {
29        self.0.iter().map(|x| x.len())
30    }
31
32    fn slice_at(&self, f: usize) -> Option<&'a [T]> {
33        self.0.get(f).map(|x| x.as_slice())
34    }
35
36    unsafe fn slice_at_unchecked(&self, f: usize) -> &'a [T] {
37        self.0[f].as_slice()
38    }
39}
40
41impl<'a, T, G> IntoConcurrentIter for &'a SplitVec<T, G>
42where
43    T: Sync,
44    G: ParGrowth,
45{
46    type Item = &'a T;
47
48    type IntoIter = ConIterJaggedRef<'a, T, Fragments<'a, T>, G>;
49
50    fn into_con_iter(self) -> Self::IntoIter {
51        let jagged = RawJaggedRef::new(
52            Fragments(&self.fragments),
53            self.growth.clone(),
54            Some(self.len),
55        );
56        jagged.into_con_iter()
57    }
58}