Skip to content

Commit

Permalink
Fix binary_search
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Jul 1, 2019
1 parent 13a9b35 commit 99f5f88
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ fn binary_search<'a>(
arr: &'a [CrateId],
details: &crate::CrateDetails,
) -> Result<(usize, &'a CrateId), usize> {
arr.binary_search_by(|i| i.name.cmp(&details.name))
.and_then(|i| {
let lowest = VersionReq::exact(&Version::new(0, 0, 0));

match arr.binary_search_by(|i| match i.name.cmp(&details.name) {
cmp::Ordering::Equal => i.version.cmp(&lowest),
o => o,
}) {
Ok(i) => Ok((i, &arr[i])),
Err(i) => {
for (j, crate_) in arr[i..].iter().enumerate() {
if crate_.name != details.name {
break;
Expand All @@ -92,9 +98,9 @@ fn binary_search<'a>(
return Ok((i + j, crate_));
}
}

Err(i)
})
}
}
}

use petgraph::Graph;
Expand Down

0 comments on commit 99f5f88

Please sign in to comment.