Skip to content

Commit

Permalink
add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
anderj017 committed Sep 26, 2020
1 parent 23a7604 commit 7f47ea9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/levenshtein_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ impl LevenshteinDistanceCalc {
}

fn build_cache(&mut self, target_len: usize) {
// if we know the max length we can pre-allocate and don't need this
// save a branch that'll never be called
let alloc_size = max(self.cache.len(), target_len);
self.cache.reserve(alloc_size);
self.cache.clear();

self.cache.clear();
for i in 0..=target_len {
self.cache.push(i);
}
Expand Down Expand Up @@ -64,6 +66,8 @@ impl LevenshteinDistanceCalc {
}
}

// for some reason this is faster than std::cmp::min (1.8sec -> 1.5sec)
// maybe inlining is better for some reason? a bit worrying
fn min(a: usize, b: usize) -> usize {
if a < b {
a
Expand Down

0 comments on commit 7f47ea9

Please sign in to comment.