fix function

This commit is contained in:
Danila Kutenin 2019-02-02 18:13:31 +03:00
parent 7d6e4083fa
commit 9c7b62e95b

View File

@ -7,8 +7,6 @@
#include <queue>
#include <utility>
#include <iostream>
namespace DB
{
@ -29,45 +27,37 @@ public:
private:
static size_t LevenshteinDistance(const String & lhs, const String & rhs)
static size_t levenshteinDistance(const String & lhs, const String & rhs)
{
size_t n = lhs.size();
size_t m = rhs.size();
std::vector<std::vector<size_t>> d(n + 1, std::vector<size_t>(m + 1));
std::vector<std::vector<size_t>> dp(n + 1, std::vector<size_t>(m + 1));
for (size_t i = 1; i <= n; ++i)
d[i][0] = i;
dp[i][0] = i;
for (size_t i = 1; i <= m; ++i)
d[0][i] = i;
dp[0][i] = i;
for (size_t j = 1; j <= m; ++j)
{
for (size_t i = 1; i <= n; ++i)
{
if (std::tolower(lhs[i - 1]) == std::tolower(rhs[j - 1]))
{
d[i][j] = d[i - 1][j - 1];
}
dp[i][j] = dp[i - 1][j - 1];
else
{
size_t dist1 = d[i - 1][j] + 1;
size_t dist2 = d[i][j - 1] + 1;
size_t dist3 = d[i - 1][j - 1] + 1;
d[i][j] = std::min(dist1, std::min(dist2, dist3));
}
dp[i][j] = std::min(dp[i - 1][j] + 1, std::min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1));
}
}
return d[n][m];
return dp[n][m];
}
static void appendToQueue(size_t ind, const String & name, DistanceIndexQueue & queue, const std::vector<String> & prompting_strings)
{
std::cout << prompting_strings[ind] << std::endl;
if (prompting_strings[ind].size() <= name.size() + MistakeFactor && prompting_strings[ind].size() + MistakeFactor >= name.size())
{
size_t distance = LevenshteinDistance(prompting_strings[ind], name);
size_t distance = levenshteinDistance(prompting_strings[ind], name);
if (distance <= MistakeFactor) {
queue.emplace(distance, ind);
if (queue.size() > MaxNumHints)