mirror of https://github.com/aria2/aria2
Fixed typo and code cleanup
parent
53fd815111
commit
1ff1505916
|
@ -92,7 +92,11 @@ void overrideWithEnv
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int levenstein
|
// Calculates Damerau–Levenshtein distance between c-string a and b
|
||||||
|
// with given costs. swapcost, subcost, addcost and delcost are cost
|
||||||
|
// to swap 2 adjacent characters, substitute characters, add character
|
||||||
|
// and delete character respectively.
|
||||||
|
int levenshtein
|
||||||
(const char* a,
|
(const char* a,
|
||||||
const char* b,
|
const char* b,
|
||||||
int swapcost,
|
int swapcost,
|
||||||
|
@ -109,11 +113,7 @@ int levenstein
|
||||||
for(int i = 1; i <= alen; ++i) {
|
for(int i = 1; i <= alen; ++i) {
|
||||||
dp[0][0] = i;
|
dp[0][0] = i;
|
||||||
for(int j = 1; j <= blen; ++j) {
|
for(int j = 1; j <= blen; ++j) {
|
||||||
if(a[i-1] == b[j-1]) {
|
dp[0][j] = dp[1][j-1]+(a[i-1] == b[j-1] ? 0 : subcost);
|
||||||
dp[0][j] = dp[1][j-1];
|
|
||||||
} else {
|
|
||||||
dp[0][j] = dp[1][j-1]+subcost;
|
|
||||||
}
|
|
||||||
if(i >= 2 && j >= 2 && a[i-1] != b[j-1] &&
|
if(i >= 2 && j >= 2 && a[i-1] != b[j-1] &&
|
||||||
a[i-2] == b[j-1] && a[i-1] == b[j-2]) {
|
a[i-2] == b[j-1] && a[i-1] == b[j-2]) {
|
||||||
dp[0][j] = std::min(dp[0][j], dp[2][j-2]+swapcost);
|
dp[0][j] = std::min(dp[0][j], dp[2][j-2]+swapcost);
|
||||||
|
@ -152,7 +152,7 @@ void showCandidates
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// cost values are borrowed from git, help.c.
|
// cost values are borrowed from git, help.c.
|
||||||
int sim = levenstein(optstr, pref->k, 0, 2, 1, 4);
|
int sim = levenshtein(optstr, pref->k, 0, 2, 1, 4);
|
||||||
cands.push_back(std::make_pair(sim, pref));
|
cands.push_back(std::make_pair(sim, pref));
|
||||||
}
|
}
|
||||||
if(cands.empty()) {
|
if(cands.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue