use super::CsrMatrix;
pub struct EntriesIterator<'a, T> {
csr_matrix: &'a CsrMatrix<T>,
row: usize,
entry: usize,
}
impl<'a, T> EntriesIterator<'a, T> {
pub fn new(csr_matrix: &'a CsrMatrix<T>) -> Self {
Self {
csr_matrix,
row: 0,
entry: 0,
}
}
}
impl<'a, T> Iterator for EntriesIterator<'a, T> {
type Item = (usize, &'a (usize, T));
fn next(&mut self) -> Option<Self::Item> {
if self.entry == self.csr_matrix.entries.len() {
return None;
}
while self.row < self.csr_matrix.m && self.csr_matrix.offsets[self.row + 1] == self.entry {
self.row += 1;
}
let result = Some((self.row, &self.csr_matrix.entries[self.entry]));
self.entry += 1;
result
}
}