Skip to content
Snippets Groups Projects
Unverified Commit feb45d0a authored by Pieter Eendebak's avatar Pieter Eendebak Committed by GitHub
Browse files

suggestions.c: Improve efficiency of levenshtein_distance method (#91835)

parent 341689cb
Branches
Tags
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment