Merge pull request #2226 from aria2/fix-levenshtein-init

Fix levenshtein init
This commit is contained in:
Tatsuhiro Tsujikawa 2024-06-30 17:47:48 +09:00 committed by GitHub
commit bddce8063c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -103,10 +103,10 @@ int levenshtein(const char* a, const char* b, int swapcost, int subcost,
int blen = strlen(b);
std::vector<std::vector<int>> dp(3, std::vector<int>(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] &&
@ -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()) {