use bitvec for group (internally)

This commit is contained in:
Folkert 2022-05-06 21:56:48 +02:00
parent 990823e6b7
commit 3e38dc80f5
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 14 additions and 4 deletions

View file

@ -131,6 +131,16 @@ impl ReferenceMatrix {
/// Get the strongly-connected components of the set of input nodes. /// Get the strongly-connected components of the set of input nodes.
pub fn strongly_connected_components(&self, nodes: &[u32]) -> Sccs { pub fn strongly_connected_components(&self, nodes: &[u32]) -> Sccs {
let mut bitvec = BitVec::repeat(false, self.length);
for value in nodes {
bitvec.set(*value as usize, true);
}
self.strongly_connected_components_help(&bitvec)
}
fn strongly_connected_components_help(&self, nodes: &BitSlice) -> Sccs {
let mut params = Params::new(self.length, nodes); let mut params = Params::new(self.length, nodes);
'outer: loop { 'outer: loop {
@ -180,11 +190,11 @@ struct Params {
} }
impl Params { impl Params {
fn new(length: usize, group: &[u32]) -> Self { fn new(length: usize, group: &BitSlice) -> Self {
let mut preorders = vec![Preorder::Removed; length]; let mut preorders = vec![Preorder::Removed; length];
for value in group { for index in group.iter_ones() {
preorders[*value as usize] = Preorder::Empty; preorders[index] = Preorder::Empty;
} }
Self { Self {

View file

@ -1159,7 +1159,7 @@ pub fn load<'a>(
) -> Result<LoadResult<'a>, LoadingProblem<'a>> { ) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
// When compiling to wasm, we cannot spawn extra threads // When compiling to wasm, we cannot spawn extra threads
// so we have a single-threaded implementation // so we have a single-threaded implementation
if threading == Threading::Single || cfg!(target_family = "wasm") { if true || threading == Threading::Single || cfg!(target_family = "wasm") {
load_single_threaded( load_single_threaded(
arena, arena,
load_start, load_start,