Skip to content

Commit

Permalink
cleanup sliding window bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Dec 27, 2023
1 parent 3a0a7e6 commit cb48a05
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,17 @@ where
let mut matches = 0;

for (i, a_elem) in a.into_iter().enumerate() {
let min_bound =
// prevent integer wrapping
if i > search_range {
max(0, i - search_range)
} else {
0
};

let max_bound = min(b_len - 1, i + search_range);
// prevent integer wrapping
let min_bound = if i > search_range {
i - search_range
} else {
0
};

if min_bound > max_bound {
continue;
}
let max_bound = min(b_len, i + search_range + 1);

for (j, b_elem) in b.into_iter().enumerate() {
if min_bound <= j && j <= max_bound && a_elem == b_elem && !b_flags[j] {
for (j, b_elem) in b.into_iter().enumerate().take(max_bound).skip(min_bound) {
if a_elem == b_elem && !b_flags[j] {
a_flags[i] = true;
b_flags[j] = true;
matches += 1;
Expand Down

0 comments on commit cb48a05

Please sign in to comment.