Skip to content

Commit

Permalink
variable names clarified
Browse files Browse the repository at this point in the history
  • Loading branch information
ugexe committed Jan 14, 2013
1 parent 39e4463 commit d86288e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
15 changes: 15 additions & 0 deletions MANIFEST
@@ -0,0 +1,15 @@
Changes
damerau-int.c
examples/benchmark.pl
examples/fuzzy_name_search.pl
lib/Text/Levenshtein/Damerau/XS.pm
LICENSE
Makefile.PL
MANIFEST This list of files
README
t/00_compile.t
t/01_imports.t
t/02_xs_edistance.t
XS.xs
xt/cxs_edistance.t
xt/pod.t
14 changes: 7 additions & 7 deletions damerau-int.c
Expand Up @@ -71,7 +71,7 @@ static void dict_free(item* head){
static int distance(unsigned int src[],unsigned int tgt[],unsigned int x,unsigned int y,unsigned int maxDistance){
item *head = NULL;
unsigned int xy_max = MAX(x,y);
unsigned int db,i1,j1,i,j;
unsigned int swapCount,targetCharCount,prevSwapCount,i,j;
unsigned int *scores = malloc( (x + 2) * (y + 2) * sizeof(unsigned int) );
unsigned int score_ceil = x + y;

Expand All @@ -88,25 +88,25 @@ static int distance(unsigned int src[],unsigned int tgt[],unsigned int x,unsigne
scores[(i+1) * (y + 2) + 1] = i;
scores[(i+1) * (y + 2) + 0] = score_ceil;

db = 0;
swapCount = 0;
for(j=1;j<=y;j++){
if(i == 1) {
head = uniquePush(head,tgt[j]);
scores[1 * (y + 2) + (j + 1)] = j;
scores[0 * (y + 2) + (j + 1)] = score_ceil;
}

i1 = find(head,tgt[j-1])->value;
j1 = db;
targetCharCount = find(head,tgt[j-1])->value;
prevSwapCount = swapCount;

if(src[i-1] == tgt[j-1]){
scores[(i+1) * (y + 2) + (j + 1)] = scores[i * (y + 2) + j];
db = j;
swapCount = j;
}else{
scores[(i+1) * (y + 2) + (j + 1)] = MIN(scores[i * (y + 2) + j], MIN(scores[(i+1) * (y + 2) + j], scores[i * (y + 2) + (j + 1)])) + 1;
}

scores[(i+1) * (y + 2) + (j + 1)] = MIN(scores[(i+1) * (y + 2) + (j + 1)], (scores[i1 * (y + 2) + j1] + i - i1 - 1 + j - j1));
scores[(i+1) * (y + 2) + (j + 1)] = MIN(scores[(i+1) * (y + 2) + (j + 1)], (scores[targetCharCount * (y + 2) + prevSwapCount] + i - targetCharCount - 1 + j - prevSwapCount));
}

/* We will return -1 here if the */
Expand All @@ -127,4 +127,4 @@ static int distance(unsigned int src[],unsigned int tgt[],unsigned int x,unsigne
free(scores);
return score;
}
}
}

0 comments on commit d86288e

Please sign in to comment.