add rows helper for Sccs

This commit is contained in:
Folkert 2022-04-24 17:10:28 +02:00
parent b8db6aae8d
commit 0569d23385
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -292,7 +292,7 @@ pub(crate) struct Sccs {
} }
impl Sccs { impl Sccs {
fn components(&self) -> impl Iterator<Item = impl Iterator<Item = usize> + '_> + '_ { pub fn components(&self) -> impl Iterator<Item = impl Iterator<Item = usize> + '_> + '_ {
// work around a panic when requesting a chunk size of 0 // work around a panic when requesting a chunk size of 0
let length = if self.matrix.length == 0 { let length = if self.matrix.length == 0 {
// the `.take(self.components)` ensures the resulting iterator will be empty // the `.take(self.components)` ensures the resulting iterator will be empty
@ -309,4 +309,18 @@ impl Sccs {
.take(self.components) .take(self.components)
.map(|row| row.iter_ones()) .map(|row| row.iter_ones())
} }
pub fn rows(&self) -> std::iter::Take<bitvec::slice::Chunks<'_, Element, Order>> {
// work around a panic when requesting a chunk size of 0
let length = if self.matrix.length == 0 {
// the `.take(self.components)` ensures the resulting iterator will be empty
assert!(self.components == 0);
1
} else {
self.matrix.length
};
self.matrix.bitvec.chunks(length).take(self.components)
}
} }