diff --git a/Cargo.toml b/Cargo.toml index 09faf8e..db0ed76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ repository = "https://github.com/linacambridge/dogear" authors = ["Lina Cambridge "] license = "Apache-2.0" exclude = [".travis", ".travis.yml"] + +[dependencies] +smallbitvec = "2.3.0" diff --git a/src/lib.rs b/src/lib.rs index a36a20d..364c437 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/tree.rs b/src/tree.rs index 3b275fc..d312689 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -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}; @@ -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 { - 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; @@ -780,7 +782,7 @@ fn detect_cycles(parents: &[ResolvedParent]) -> Option { .and_then(|index| parents[index].index()) .and_then(|index| parents[index].index()); } - seen[entry_index] = true; + seen.set(entry_index, true); } None }