NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
MapTool.cxx
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#include "NAGASH/MapTool.h"
7using namespace std;
8using namespace NAGASH;
9
11unsigned int MapTool::EditDistance(const TString &s1, const TString &s2) const
12{
13 const std::size_t len1 = s1.Length(), len2 = s2.Length();
14 std::vector<std::vector<unsigned int>> d(len1 + 1, std::vector<unsigned int>(len2 + 1));
15
16 d[0][0] = 0;
17 for (unsigned int i = 1; i <= len1; ++i)
18 d[i][0] = i;
19 for (unsigned int i = 1; i <= len2; ++i)
20 d[0][i] = i;
21
22 for (unsigned int i = 1; i <= len1; ++i)
23 for (unsigned int j = 1; j <= len2; ++j)
24 d[i][j] = std::min({d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1)});
25 return d[len1][len2];
26}
27
29unsigned int MapTool::EditDistance(const std::string &s1, const std::string &s2) const
30{
31 const std::size_t len1 = s1.size(), len2 = s2.size();
32 std::vector<std::vector<unsigned int>> d(len1 + 1, std::vector<unsigned int>(len2 + 1));
33
34 d[0][0] = 0;
35 for (unsigned int i = 1; i <= len1; ++i)
36 d[i][0] = i;
37 for (unsigned int i = 1; i <= len2; ++i)
38 d[0][i] = i;
39
40 for (unsigned int i = 1; i <= len1; ++i)
41 for (unsigned int j = 1; j <= len2; ++j)
42 d[i][j] = std::min({d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1)});
43 return d[len1][len2];
44}
unsigned int EditDistance(const TString &s1, const TString &s2) const
Calculate the edit distance between two strings.
Definition MapTool.cxx:11