Skip to content

Commit

Permalink
suggestions.c: Improve efficiency of levenshtein_distance method (pyt…
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt authored May 2, 2022
1 parent 341689c commit feb45d0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ levenshtein_distance(const char *a, size_t a_size,
// Instead of producing the whole traditional len(a)-by-len(b)
// matrix, we can update just one row in place.
// Initialize the buffer row
size_t tmp = MOVE_COST;
for (size_t i = 0; i < a_size; i++) {
// cost from b[:0] to a[:i+1]
buffer[i] = (i + 1) * MOVE_COST;
buffer[i] = tmp;
tmp += MOVE_COST;
}

size_t result = 0;
Expand Down

0 comments on commit feb45d0

Please sign in to comment.