-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditThread.java
More file actions
45 lines (33 loc) · 1018 Bytes
/
EditThread.java
File metadata and controls
45 lines (33 loc) · 1018 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
44
45
package editDistance;
public class EditThread extends Thread {
private int editMatrix[][];
int iStart;
int iStop;
int jStart;
int jStop;
String firstString;
String secondString;
public EditThread(int editMatrix[][], int iStart, int iStop, int jStart, int jStop, String firstString, String secondString) {
this.editMatrix = editMatrix;
this.iStart = iStart;
this.iStop = iStop;
this.jStart = jStart;
this.jStop = jStop;
this.firstString = firstString;
this.secondString = secondString;
}
private static int min3(int a, int b, int c) {
return (a < b ? Math.min(a, c) : Math.min(b, c));
}
public void run() {
int i, j;
for (i = iStart; i <= iStop; i++) {
for (j = jStart; j <= jStop; j++) {
this.editMatrix[i][j] = min3(
this.editMatrix[i - 1][j] + 1,
this.editMatrix[i][j - 1] + 1,
this.editMatrix[i - 1][j - 1] + (this.firstString.charAt(i - 1) != this.secondString.charAt(j - 1) ? 1 : 0));
}
}
}
}