Hello again:
Yesterday I wrote a function that would perform the old adler32 hash on given data. My function works perfectly well and so far always has found the correct hash. The problem is big files. I made a file exactly 1 MB and hashed it with various commercial software. They took no more than 5-10 secs. Mine takes 1hr and 5mins....
Since this is a fairly simple hash algo, I was hoping that someone here would recognize and optimizations that could be made to my code. I wrote it from scratch and hopefully right off the bat I am not too inefficient!
Code:
unsigned int adler32(unsigned char *data, unsigned int len)
{
unsigned int A = 1, B = 0;
unsigned int i, j;
for (i = 0; i < len; i++)
{
A += data[i];
for (j = i + 1; j > 0; j--)
B += data[j-1];
B++;
A %= 65521;
B %= 65521;
}
return (B * 65536) + A;
}