Skip to content

Commit

Permalink
binarity optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Miezhiko <Miezhiko@gmail.com>
  • Loading branch information
Miezhiko committed Nov 3, 2021
1 parent 70cfd79 commit 04162f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "stalin-binary-search"
description = "alike binary search but any checking element which is not target one is eliminated"
license = "AGPL-3.0-only"
version = "0.0.3"
version = "0.0.4"
authors = ["Miezhiko <Miezhiko@gmail.com>"]
repository = "https://github.com/Miezhiko/stalin-binary-search"
edition = "2021"
Expand Down
10 changes: 5 additions & 5 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl<T: PartialOrd> StalinFind<T> for Vec<T> {
} else {
self.stalin(i, 0, self.len() - 1)
}
} else if self[m - 1] > i {
self.stalin(i, l, m - 1)
} else if self[m - 1] < i {
self.stalin(i, m, r - 1)
} else {
self.stalin(i, m - 1, r - 1)
self.stalin(i, l, m - 1)
}
}
}
Expand Down Expand Up @@ -87,11 +87,11 @@ mod tests {
let mut unsorted = vec![33, 55, 3, 4, 7657, 6, 7, 8];
assert_eq!(
unsorted.stalin_find(3),
Some(2),
Some(0),
);
assert_eq!(
unsorted,
vec![33, 55, 3, 7657, 7, 8],
vec![3, 7657, 7, 8],
);
if let Some(find_7) = unsorted.stalin_find(7) {
assert_eq!(
Expand Down

0 comments on commit 04162f6

Please sign in to comment.