This commit is contained in:
Folkert 2022-04-24 18:46:16 +02:00
parent c5f433ab94
commit 0aa7cb8479
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 2 additions and 150 deletions

View file

@ -36,40 +36,10 @@ impl ReferenceMatrix {
self.bitvec.set(row * self.length + col, value)
}
#[inline(always)]
pub fn get(&self, index: usize) -> bool {
self.bitvec[index]
}
#[inline(always)]
pub fn get_row_col(&self, row: usize, col: usize) -> bool {
self.bitvec[row * self.length + col]
}
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
@ -81,6 +51,7 @@ impl ReferenceMatrix {
//
// Thank you, Samuel!
impl ReferenceMatrix {
#[allow(dead_code)]
pub fn topological_sort_into_groups(&self) -> TopologicalSort {
if self.length == 0 {
return TopologicalSort::Groups { groups: Vec::new() };
@ -178,6 +149,7 @@ impl ReferenceMatrix {
}
}
#[allow(dead_code)]
pub(crate) enum TopologicalSort {
/// There were no cycles, all nodes have been partitioned into groups
Groups { groups: Vec<Vec<u32>> },