added CHAR_OFFSET
authorAndrew Tridgell <tridge@samba.org>
Thu, 4 Jul 1996 13:08:07 +0000 (13:08 +0000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 4 Jul 1996 13:08:07 +0000 (13:08 +0000)
checksum.c
match.c
rsync.h

index 6be1993..2015836 100644 (file)
@@ -37,11 +37,12 @@ uint32 get_checksum1(char *buf,int len)
 
     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;
-       s1 += (buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3] + 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]+1); s2 += s1;
+       s1 += (buf[i]+CHAR_OFFSET); s2 += s1;
     }
     return (s1 & 0xffff) + (s2 << 16);
 }
diff --git a/match.c b/match.c
index e15f440..5c78ce3 100644 (file)
--- a/match.c
+++ b/match.c
@@ -222,11 +222,11 @@ static void hash_search(int f,struct sum_struct *s,
     /* Trim off the first byte from the checksum */
     map = window_ptr(buf,offset,k+1);
     s1 -= map[0] + 1;
-    s2 -= k * (map[0]+1);
+    s2 -= k * (map[0]+CHAR_OFFSET);
 
     /* Add on the next byte (if there is one) to the checksum */
     if (k < (len-offset)) {
-      s1 += (map[k]+1);
+      s1 += (map[k]+CHAR_OFFSET);
       s2 += s1;
     } else {
       --k;
diff --git a/rsync.h b/rsync.h
index 9301062..ce36018 100644 (file)
--- a/rsync.h
+++ b/rsync.h
 #define RSYNC_NAME "rsync"
 #define BACKUP_SUFFIX "~"
 
+/* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
+   imcompatible with older versions :-( */
+#define CHAR_OFFSET 0
+
+
 #define FILE_VALID 1
 #define SAME_MODE (1<<1)
 #define SAME_RDEV (1<<2)