mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
add recursivity checker
This commit is contained in:
parent
9bc00321b6
commit
31fc223517
1 changed files with 25 additions and 0 deletions
|
@ -39,6 +39,31 @@ impl ReferenceMatrix {
|
||||||
pub fn get(&self, index: usize) -> bool {
|
pub fn get(&self, index: usize) -> bool {
|
||||||
self.bitvec[index]
|
self.bitvec[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_recursive(&self, index: usize) -> bool {
|
||||||
|
let mut scheduled = self.row_slice(index).to_bitvec();
|
||||||
|
let mut visited = self.row_slice(index).to_bitvec();
|
||||||
|
|
||||||
|
// yes this is a bit inefficient because rows are visited repeatedly.
|
||||||
|
while scheduled.any() {
|
||||||
|
for one in scheduled.iter_ones() {
|
||||||
|
if one == index {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
visited |= self.row_slice(one)
|
||||||
|
}
|
||||||
|
|
||||||
|
// i.e. visited did not change
|
||||||
|
if visited.count_ones() == scheduled.count_ones() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduled |= &visited;
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Topological sort and strongly-connected components
|
// Topological sort and strongly-connected components
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue