Sunday, 11 August 2013

Code optimization for string comparisons

Code optimization for string comparisons

I have a function code for string comparison as below :
int calcMis(char *string,int i, int j,int len)
{
int mis=0;
int k=0;
while(k<len)
{
if(string[i+k]!=string[j+k])
mis+=1;
if((mis+len-k-1)<=max)
return 1;
else if(mis>max)
return 0;
k+=1;
}
}
This codes checks for two part of the same strings but starting at i and j
and having same length as len. The function aims at identifying the number
of mismatches between the two strings. If the number of mismatches >=max
it should return 1 else 0. Is there any better method than this. Is there
any optimizations possible in this code?

No comments:

Post a Comment