diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-06 17:29:06 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-06 18:58:08 -0700 |
commit | ec97545637a6310367ce9a3bdf2b3206e0b85d3b (patch) | |
tree | 7fe0c4305ff6253cc6720032f971b5867a05645b /match.c | |
parent | 98a8729f88d9bfc8d1a20e72bcf7549fc9ea4466 (diff) |
Rearrance calculate_score inner loop for clarity
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -112,19 +112,17 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ score_t score = SCORE_MIN; - int match = tolower(needle[i]) == tolower(haystack[j]); - D[i][j] = SCORE_MIN; - if(match){ - if(i && j){ + if(tolower(needle[i]) == tolower(haystack[j])){ + if(!i){ + score = (j * SCORE_GAP_LEADING) + match_bonus[j]; + }else if(j){ score = max(score, M[i-1][j-1] + match_bonus[j]); /* consecutive match, doesn't stack with match_bonus */ score = max(score, D[i-1][j-1] + SCORE_MATCH_CONSECUTIVE); - }else if(!i){ - score = (j * SCORE_GAP_LEADING) + match_bonus[j]; } - D[i][j] = score; } + D[i][j] = score; if(j){ if(i == n-1){ score = max(score, M[i][j-1] + SCORE_GAP_TRAILING); |