From cfa7e9cde0b5c1e5f1453d409e2efbd303e1fa64 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 30 Jun 2024 10:00:07 +0900 Subject: [PATCH 1/2] Fix levenshtein initialization --- src/option_processing.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/option_processing.cc b/src/option_processing.cc index a671b23a..fe9810de 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -103,10 +103,10 @@ int levenshtein(const char* a, const char* b, int swapcost, int subcost, int blen = strlen(b); std::vector> dp(3, std::vector(blen + 1)); for (int i = 0; i <= blen; ++i) { - dp[1][i] = i; + dp[1][i] = i * addcost; } for (int i = 1; i <= alen; ++i) { - dp[0][0] = i; + dp[0][0] = i * delcost; for (int j = 1; j <= blen; ++j) { dp[0][j] = dp[1][j - 1] + (a[i - 1] == b[j - 1] ? 0 : subcost); if (i >= 2 && j >= 2 && a[i - 1] != b[j - 1] && a[i - 2] == b[j - 1] && From 1a4cb1d070110f842cc54b5e675108295b88c234 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 30 Jun 2024 10:00:30 +0900 Subject: [PATCH 2/2] Update levenshtein costs --- src/option_processing.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/option_processing.cc b/src/option_processing.cc index fe9810de..d95ce753 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -148,7 +148,7 @@ void showCandidates(const std::string& unknownOption, continue; } // cost values are borrowed from git, help.c. - int sim = levenshtein(optstr, pref->k, 0, 2, 1, 4); + int sim = levenshtein(optstr, pref->k, 0, 2, 1, 3); cands.push_back(std::make_pair(sim, pref)); } if (cands.empty()) {