mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
add rows helper for Sccs
This commit is contained in:
parent
b8db6aae8d
commit
0569d23385
1 changed files with 15 additions and 1 deletions
|
@ -292,7 +292,7 @@ pub(crate) struct 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
|
||||
let length = if self.matrix.length == 0 {
|
||||
// the `.take(self.components)` ensures the resulting iterator will be empty
|
||||
|
@ -309,4 +309,18 @@ impl Sccs {
|
|||
.take(self.components)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue