1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::{ConcurrentSplitVec, GrowthWithConstantTimeAccess, SplitVec};
use orx_pinned_vec::IntoConcurrentPinnedVec;

impl<T, G: GrowthWithConstantTimeAccess> IntoConcurrentPinnedVec<T> for SplitVec<T, G> {
    type ConPinnedVec = ConcurrentSplitVec<T, G>;

    fn into_concurrent(self) -> Self::ConPinnedVec {
        self.into()
    }

    fn into_concurrent_filled_with<F>(mut self, fill_with: F) -> Self::ConPinnedVec
    where
        F: Fn() -> T,
    {
        if let Some(fragment) = self.fragments.last_mut() {
            let (len, capacity) = (fragment.len(), fragment.capacity());
            let num_additional = capacity - len;
            for _ in 0..num_additional {
                fragment.push(fill_with());
            }

            self.len += num_additional;

            debug_assert_eq!(
                self.len,
                self.fragments.iter().map(|x| x.len()).sum::<usize>()
            );
        }

        self.into()
    }
}