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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use crate::bits::BitSetViewExt;
use crate::join::{IntoJoin, Join};
use crate::smat::{MatrixMask, RowRead, RowUpdate, RowWrite, SMatrix, Store, StoreMut};
use crate::traits::{IndexExcl, IndexLowerBound};
use std::mem;

/// Wrapper to allow immutable access to the elments of an SMatrix in row-major order. Used for join and merge oprations.
pub struct WrapRowRead<'a, M, S>
where
    M: MatrixMask,
    S: Store,
{
    pub(crate) mat: &'a SMatrix<M, S>,
}

impl<'a, M, S> IndexExcl<usize> for WrapRowRead<'a, M, S>
where
    M: MatrixMask,
    S: Store,
{
    type Item = RowRead<'a, M, S>;

    fn index(&mut self, idx: usize) -> Self::Item {
        self.mat.read_row(idx)
    }
}

impl<'a, M, S> IndexLowerBound<usize> for WrapRowRead<'a, M, S>
where
    M: MatrixMask,
    S: Store,
{
    fn lower_bound(&mut self, idx: usize) -> Option<usize> {
        self.mat.row_mask.lower_bound(idx)
    }
}

impl<'a, M, S> IntoJoin for WrapRowRead<'a, M, S>
where
    M: MatrixMask,
    S: Store,
{
    type Store = Self;

    fn into_join(self) -> Join<Self::Store> {
        Join::from_parts(0..self.mat.capacity(), self)
    }
}

/// Wrapper to allow mutable access to the elments of an SMatrix in row-major order. Used for join and merge oprations.
pub struct WrapRowUpdate<'a, M, S>
where
    M: MatrixMask,
    S: Store,
{
    pub(crate) mat: &'a mut SMatrix<M, S>,
}

impl<'a, M, S> IndexExcl<usize> for WrapRowUpdate<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    type Item = RowUpdate<'a, M, S>;

    fn index(&mut self, idx: usize) -> Self::Item {
        unsafe { mem::transmute(self.mat.update_row(idx)) } //GAT
    }
}

impl<'a, M, S> IndexLowerBound<usize> for WrapRowUpdate<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    fn lower_bound(&mut self, idx: usize) -> Option<usize> {
        self.mat.row_mask.lower_bound(idx)
    }
}

impl<'a, M, S> IntoJoin for WrapRowUpdate<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    type Store = Self;

    fn into_join(self) -> Join<Self::Store> {
        Join::from_parts(0..self.mat.capacity(), self)
    }
}

/// Wrapper to allow Entry based access to the elments of an SMatrix in row-major order. Used for join and merge oprations.
pub struct WrapRowWrite<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    pub(crate) mat: &'a mut SMatrix<M, S>,
}

impl<'a, M, S> IndexExcl<usize> for WrapRowWrite<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    type Item = RowWrite<'a, M, S>;

    fn index(&mut self, idx: usize) -> Self::Item {
        unsafe { mem::transmute(self.mat.write_row(idx)) } //GAT
    }
}

impl<'a, M, S> IndexLowerBound<usize> for WrapRowWrite<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    fn lower_bound(&mut self, idx: usize) -> Option<usize> {
        Some(idx)
    }
}

impl<'a, M, S> IntoJoin for WrapRowWrite<'a, M, S>
where
    M: MatrixMask,
    S: StoreMut,
{
    type Store = Self;

    fn into_join(self) -> Join<Self::Store> {
        Join::from_parts(0..self.mat.capacity(), self)
    }
}