| ... | ... |
@@ -16,23 +16,28 @@ int has_match(const char *needle, const char *haystack){
|
| 16 | 16 |
return 1; |
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 |
+#define max(a, b) (((a) > (b)) ? (a) : (b)) |
|
| 20 |
+typedef double score_t; |
|
| 21 |
+#define SCORE_MAX DBL_MAX |
|
| 22 |
+#define SCORE_MIN -DBL_MAX |
|
| 23 |
+ |
|
| 19 | 24 |
/* print one of the internal matrices */ |
| 20 |
-void mat_print(int *mat, int n, int m){
|
|
| 25 |
+void mat_print(score_t *mat, int n, int m){
|
|
| 21 | 26 |
int i, j; |
| 22 | 27 |
for(i = 0; i < n; i++){
|
| 23 | 28 |
for(j = 0; j < m; j++){
|
| 24 |
- fprintf(stderr, " %3i", mat[i*m + j]); |
|
| 29 |
+ score_t val = mat[i*m + j]; |
|
| 30 |
+ if(val == SCORE_MIN){
|
|
| 31 |
+ fprintf(stderr, " -inf"); |
|
| 32 |
+ }else{
|
|
| 33 |
+ fprintf(stderr, " %.2f", val); |
|
| 34 |
+ } |
|
| 25 | 35 |
} |
| 26 | 36 |
fprintf(stderr, "\n"); |
| 27 | 37 |
} |
| 28 | 38 |
fprintf(stderr, "\n\n"); |
| 29 | 39 |
} |
| 30 | 40 |
|
| 31 |
-#define max(a, b) (((a) > (b)) ? (a) : (b)) |
|
| 32 |
-typedef double score_t; |
|
| 33 |
-#define SCORE_MAX DBL_MAX |
|
| 34 |
-#define SCORE_MIN -DBL_MAX |
|
| 35 |
- |
|
| 36 | 41 |
double calculate_score(const char *needle, const char *haystack, size_t *positions){
|
| 37 | 42 |
if(!*haystack || !*needle) |
| 38 | 43 |
return SCORE_MIN; |
| ... | ... |
@@ -89,6 +94,11 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio |
| 89 | 94 |
} |
| 90 | 95 |
} |
| 91 | 96 |
|
| 97 |
+#if 0 |
|
| 98 |
+ mat_print(&D[0][0], n, m); |
|
| 99 |
+ mat_print(&M[0][0], n, m); |
|
| 100 |
+#endif |
|
| 101 |
+ |
|
| 92 | 102 |
/* backtrace to find the positions of optimal matching */ |
| 93 | 103 |
if(positions){
|
| 94 | 104 |
for(int i = n-1, j = m-1; i >= 0; i--){
|