$treeview $search $mathjax $extrastylesheet
librsync
2.3.0
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * 00003 * rollsum -- the librsync rolling checksum 00004 * 00005 * Copyright (C) 2003 by Donovan Baarda <abo@minkirri.apana.org.au> 00006 * based on work, Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net> 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation; either version 2.1 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 #include "rollsum.h" 00023 00024 #define DO1(buf,i) {s1 += buf[i]; s2 += s1;} 00025 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 00026 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 00027 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 00028 #define DO16(buf) DO8(buf,0); DO8(buf,8); 00029 00030 void RollsumUpdate(Rollsum *sum, const unsigned char *buf, size_t len) 00031 { 00032 /* ANSI C says no overflow for unsigned. zlib's adler32 goes to extra 00033 effort to avoid overflow for its mod prime, which we don't have. */ 00034 size_t n = len; 00035 uint_fast16_t s1 = sum->s1; 00036 uint_fast16_t s2 = sum->s2; 00037 00038 while (n >= 16) { 00039 DO16(buf); 00040 buf += 16; 00041 n -= 16; 00042 } 00043 while (n != 0) { 00044 s1 += *buf++; 00045 s2 += s1; 00046 n--; 00047 } 00048 /* Increment s1 and s2 by the amounts added by the char offset. */ 00049 s1 += len * ROLLSUM_CHAR_OFFSET; 00050 s2 += ((len * (len + 1)) / 2) * ROLLSUM_CHAR_OFFSET; 00051 sum->count += len; /* Increment sum count. */ 00052 sum->s1 = s1; 00053 sum->s2 = s2; 00054 }