Skip to content

Improve efficiency of lehvenshtein_distance method #91835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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