make mut iterator pointer based
Change the ColumnIterMut back to the original impl and manually implement Send
This commit is contained in:
parent
42ab3f6903
commit
f6461d3862
|
@ -396,18 +396,19 @@ where
|
|||
/// An iterator through the mutable columns of a matrix.
|
||||
#[derive(Debug)]
|
||||
pub struct ColumnIterMut<'a, T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> {
|
||||
mat: &'a mut Matrix<T, R, C, S>,
|
||||
mat: *mut Matrix<T, R, C, S>,
|
||||
phantom: PhantomData<&'a mut Matrix<T, R, C, S>>,
|
||||
range: Range<usize>,
|
||||
}
|
||||
|
||||
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> ColumnIterMut<'a, T, R, C, S> {
|
||||
pub(crate) fn new(mat: &'a mut Matrix<T, R, C, S>) -> Self {
|
||||
let range = 0..mat.ncols();
|
||||
ColumnIterMut { mat, range }
|
||||
ColumnIterMut { mat, range, phantom: Default::default() }
|
||||
}
|
||||
|
||||
fn ncols(&self) -> usize {
|
||||
self.mat.ncols()
|
||||
unsafe { (*self.mat).ncols() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,8 +420,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Iterator
|
|||
#[inline]
|
||||
fn next(&'_ mut self) -> Option<Self::Item> {
|
||||
if self.range.start < self.ncols() {
|
||||
let pmat: *mut _ = self.mat;
|
||||
let res = unsafe { (*pmat).column_mut(self.range.start) };
|
||||
let res = unsafe { (*self.mat).column_mut(self.range.start) };
|
||||
self.range.start += 1;
|
||||
Some(res)
|
||||
} else {
|
||||
|
@ -456,10 +456,9 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> DoubleEndedI
|
|||
debug_assert!(self.range.start <= self.range.end);
|
||||
if !self.range.is_empty() {
|
||||
self.range.end -= 1;
|
||||
debug_assert!(self.range.end < self.mat.ncols());
|
||||
debug_assert!(self.range.end < self.ncols());
|
||||
debug_assert!(self.range.end >= self.range.start);
|
||||
let pmat: *mut _ = self.mat;
|
||||
Some(unsafe { (*pmat).column_mut(self.range.end) })
|
||||
Some(unsafe { (*self.mat).column_mut(self.range.end) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -482,17 +481,21 @@ where
|
|||
fn split_at(self, index: usize) -> (Self, Self) {
|
||||
// the index is relative to the size of this current iterator
|
||||
// it will always start at zero so it serves as an offset
|
||||
let pmat: *mut _ = self.mat;
|
||||
|
||||
let left = Self {
|
||||
mat: unsafe { &mut *pmat },
|
||||
mat: self.mat,
|
||||
range: self.range.start..(self.range.start + index),
|
||||
phantom: Default::default(),
|
||||
};
|
||||
|
||||
let right = Self {
|
||||
mat: self.mat,
|
||||
range: (self.range.start + index)..self.range.end,
|
||||
phantom: Default::default(),
|
||||
};
|
||||
(left, right)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Send
|
||||
for ColumnIterMut<'a, T, R, C, S> {}
|
Loading…
Reference in New Issue