Skip to content

Commit

Permalink
Use a SmallBitVec in detect_cycles.
Browse files Browse the repository at this point in the history
  • Loading branch information
linabutler committed Feb 13, 2019
1 parent 80453aa commit 4b64d1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ repository = "https://github.com/linacambridge/dogear"
authors = ["Lina Cambridge <lina@mozilla.com>"]
license = "Apache-2.0"
exclude = [".travis", ".travis.yml"]

[dependencies]
smallbitvec = "2.3.0"
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate smallbitvec;

#[macro_use]
mod driver;
mod error;
Expand Down
6 changes: 4 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::{cmp::Ordering,
ops::Deref,
ptr};

use smallbitvec::SmallBitVec;

use crate::error::{ErrorKind, Result};
use crate::guid::{Guid, ROOT_GUID};

Expand Down Expand Up @@ -760,7 +762,7 @@ impl ResolvedParent {
/// algorithm. Returns the index of the entry where the cycle was detected,
/// or `None` if there aren't any cycles.
fn detect_cycles(parents: &[ResolvedParent]) -> Option<Index> {
let mut seen = vec![false; parents.len()];
let mut seen = SmallBitVec::from_elem(parents.len(), false);
for (entry_index, parent) in parents.iter().enumerate() {
if seen[entry_index] {
continue;
Expand All @@ -780,7 +782,7 @@ fn detect_cycles(parents: &[ResolvedParent]) -> Option<Index> {
.and_then(|index| parents[index].index())
.and_then(|index| parents[index].index());
}
seen[entry_index] = true;
seen.set(entry_index, true);
}
None
}
Expand Down

0 comments on commit 4b64d1c

Please sign in to comment.