orx_v/flat_jagged/
impl_nvec.rs

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::{FlatJagged, FlatJaggedRowMut};
use crate::{CardD1, Dim, FunVec, IntoIdx, NVec, D1, D2};

// row

impl<'a, V, I, T> NVec<D1, T> for FlatJaggedRowMut<'a, V, I, T>
where
    V: NVec<D1, T>,
    I: NVec<D1, usize>,
{
    #[inline(always)]
    fn at(&self, idx: impl IntoIdx<D1>) -> T {
        let [j] = idx.into_idx();
        let idx = self.jagged.to_d1_idx([self.i, j]);
        self.jagged.flat_vec.at(idx)
    }

    fn child(&self, _: <D1 as Dim>::ChildIdx) -> impl NVec<<D1 as Dim>::PrevDim, T> {
        self
    }

    fn all(&self) -> impl Iterator<Item = T> {
        let (begin, end) = self.jagged.row_range(self.i);
        self.jagged.flat_vec.all().skip(begin).take(end - begin)
    }
}

// vec

impl<V, I, T> NVec<D2, T> for FlatJagged<V, I, T>
where
    V: NVec<D1, T>,
    I: NVec<D1, usize>,
{
    #[inline(always)]
    fn at(&self, idx: impl IntoIdx<D2>) -> T {
        let idx = self.to_d1_idx(idx.into_idx());
        self.flat_vec.at(idx)
    }

    fn child(&self, i: <D2 as Dim>::ChildIdx) -> impl NVec<<D2 as Dim>::PrevDim, T> {
        let (begin, end) = self.row_range(i);
        FunVec::new(move |[j]| self.at([i, j]), CardD1::from(end - begin))
    }

    fn all(&self) -> impl Iterator<Item = T> {
        self.flat_vec.all()
    }
}