forked from rohitsaluja22/OpenOCRCorrect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheddis.h
More file actions
43 lines (33 loc) · 863 Bytes
/
eddis.h
File metadata and controls
43 lines (33 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef EDDIS_H
#define EDDIS_H
#include <cassert>
#include <string>
#include <vector>
using namespace std;
inline size_t min(size_t x, size_t y, size_t z)
{
if (x < y)
return x < z ? x : z;
else
return y < z ? y : z;
}
size_t editDist(const string& A, const string& B)
{
size_t NA = A.size();
size_t NB = B.size();
vector<vector<size_t>> M(NA + 1, vector<size_t>(NB + 1));
for (size_t a = 0; a <= NA; ++a)
M[a][0] = a;
for (size_t b = 0; b <= NB; ++b)
M[0][b] = b;
for (size_t a = 1; a <= NA; ++a)
for (size_t b = 1; b <= NB; ++b)
{
size_t x = M[a-1][b] + 1;
size_t y = M[a][b-1] + 1;
size_t z = M[a-1][b-1] + (A[a-1] == B[b-1] ? 0 : 1);
M[a][b] = min(x,y,z);
}
return M[A.size()][B.size()];
}
#endif // EDDIS_H