The weak checksum in checksum.c (see snippet below) differs
substantially from the one discussed in Andrew Tridgell's doctoral
thesis on rsync and elsewhere that I've been able to find. I didn't
find discussion of the change in the mailing list archives. Well, so
I'm curious what the benefit of the change is.
(I'm using a rolling checksum in another app, thus the reason for this
nitty inspection.)
Can anyone provide a pointer to help me understand why this changed?
Thanks much.
In checksum.c:
uint32 get_checksum1(char *buf1,int len)
{
int i;
uint32 s1, s2;
schar *buf = (schar *)buf1;
s1 = s2 = 0;
for (i = 0; i < (len-4); i+=4) {
s2 += 4*(s1 + buf[i]) + 3*buf[i+1] + 2*buf[i+2] + buf[i+3] +
10*CHAR_OFFSET;
s1 += (buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3] + 4*CHAR_OFFSET);
}
for (; i < len; i++) {
s1 += (buf[i]+CHAR_OFFSET); s2 += s1;
}
return (s1 & 0xffff) + (s2 << 16);
}
What I understood from documentation:
/* Rolling checksum from Tridgell's PhD thesis. */
int get_weak_checksum(signed char *buf, int len)
{
int s;
int s1, s2;
int len4;
s1 = s2 = 0;
len4 = len / 4;
for(i = 0; i < len - 4; i += 4) {
s = (buf[i] << 24) + (buf[i+1] << 16)
+ (buf[i+2] << 8) + (buf[i+3]);
s1 += s;
s2 += (len4 - 4 * i) * s;
}
return (s2 << 16) + (s1 & 0xffff);
}
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/>
--
To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html