use crate::traits::{SparseValuedMatrix2DRef, SparseValuedMatrixMut, ValuedMatrix};
pub trait SparseValuedMatrix2DMut: SparseValuedMatrix2DRef + SparseValuedMatrixMut {
type SparseRowValuesMut<'a>: Iterator<Item = &'a mut <Self as ValuedMatrix>::Value>
+ DoubleEndedIterator<Item = &'a mut <Self as ValuedMatrix>::Value>
where
Self: 'a,
<Self as ValuedMatrix>::Value: 'a;
fn sparse_row_values_mut(&mut self, row: Self::RowIndex) -> Self::SparseRowValuesMut<'_>;
fn sparse_value_at_mut(
&mut self,
row: Self::RowIndex,
column: Self::ColumnIndex,
) -> Option<&mut <Self as ValuedMatrix>::Value>
where
Self::ColumnIndex: PartialEq;
#[inline]
fn replace_value(
&mut self,
row: Self::RowIndex,
column: Self::ColumnIndex,
value: <Self as ValuedMatrix>::Value,
) -> Option<<Self as ValuedMatrix>::Value>
where
Self::ColumnIndex: PartialEq,
{
self.sparse_value_at_mut(row, column).map(|v| core::mem::replace(v, value))
}
#[inline]
fn update_value(
&mut self,
row: Self::RowIndex,
column: Self::ColumnIndex,
f: impl FnOnce(&mut <Self as ValuedMatrix>::Value),
) -> bool
where
Self::ColumnIndex: PartialEq,
{
if let Some(v) = self.sparse_value_at_mut(row, column) {
f(v);
true
} else {
false
}
}
fn sparse_row_entries_mut(
&mut self,
row: Self::RowIndex,
) -> impl Iterator<Item = (Self::ColumnIndex, &mut <Self as ValuedMatrix>::Value)>;
}