Skip to content

Commit

Permalink
osa optimisation rapidfuzz#7
Browse files Browse the repository at this point in the history
little hard to walk through all of the std code, but I'm pretty certain
two separate range collect()'s are more efficient than the push() loop.

it's also more simple
  • Loading branch information
jnqnfe committed Nov 4, 2018
1 parent 04928f7 commit f2e5e16
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,13 @@ pub fn osa_distance(a: &str, b: &str) -> usize {
}
};

let mut prev_two_distances: Vec<usize> = Vec::with_capacity(b_numchars + 1);
let mut prev_distances: Vec<usize> = Vec::with_capacity(b_numchars + 1);
let mut prev_two_distances: Vec<usize> = (0..=b_numchars).collect();
let mut prev_distances: Vec<usize> = (0..=b_numchars).collect();
let mut curr_distances: Vec<usize> = vec![0; b_numchars + 1];

let mut prev_a_char = char::MAX;
let mut prev_b_char = char::MAX;

for i in 0..=b_numchars {
prev_two_distances.push(i);
prev_distances.push(i);
}

for (i, a_char) in a.chars().enumerate() {
curr_distances[0] = i + 1;

Expand Down

0 comments on commit f2e5e16

Please sign in to comment.