Use mutable reachability rows in isolated SCC probe
This commit is contained in:
@@ -22,14 +22,14 @@ fn charge(work: &mut usize, count: usize) -> Result<(), ModelError> {
|
|||||||
fn components(arcs: &[BTreeSet<usize>], work: &mut usize) -> Result<Vec<Vec<usize>>, ModelError> {
|
fn components(arcs: &[BTreeSet<usize>], work: &mut usize) -> Result<Vec<Vec<usize>>, ModelError> {
|
||||||
let n = arcs.len();
|
let n = arcs.len();
|
||||||
let mut reach = vec![vec![false; n]; n];
|
let mut reach = vec![vec![false; n]; n];
|
||||||
for start in 0..n {
|
for (start, reachable) in reach.iter_mut().enumerate() {
|
||||||
let mut todo = vec![start];
|
let mut todo = vec![start];
|
||||||
reach[start][start] = true;
|
reachable[start] = true;
|
||||||
while let Some(at) = todo.pop() {
|
while let Some(at) = todo.pop() {
|
||||||
for &next in &arcs[at] {
|
for &next in &arcs[at] {
|
||||||
charge(work, 1)?;
|
charge(work, 1)?;
|
||||||
if !reach[start][next] {
|
if !reachable[next] {
|
||||||
reach[start][next] = true;
|
reachable[next] = true;
|
||||||
todo.push(next);
|
todo.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,6 +583,5 @@ mod tests {
|
|||||||
positions,
|
positions,
|
||||||
vec![Position { x: 0.0, y: 0.0 }, Position { x: 0.0, y: 216.0 }]
|
vec![Position { x: 0.0, y: 0.0 }, Position { x: 0.0, y: 216.0 }]
|
||||||
);
|
);
|
||||||
assert!(224.0_f32 / 376.0 > 0.5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user