add mutable triplet iter

This commit is contained in:
lukas 2022-09-30 19:49:47 -07:00
parent 202a548a37
commit b37eeee636

View File

@ -170,6 +170,16 @@ impl<T> CooMatrix<T> {
.map(|((i, j), v)| (*i, *j, v)) .map(|((i, j), v)| (*i, *j, v))
} }
/// A mutable iterator over triplets (i, j, v).
// TODO: Consider giving the iterator a concrete type instead of impl trait...?
pub fn triplet_iter_mut(&mut self) -> impl Iterator<Item = (usize, usize, &mut T)> {
self.row_indices
.iter()
.zip(&self.col_indices)
.zip(self.values.iter_mut())
.map(|((i, j), v)| (*i, *j, v))
}
/// Reserves capacity for COO matrix by at least `additional` elements. /// Reserves capacity for COO matrix by at least `additional` elements.
/// ///
/// This increase the capacities of triplet holding arrays by reserving more space to avoid /// This increase the capacities of triplet holding arrays by reserving more space to avoid