rsync关于adler-32的描述

本文介绍了一种用于rsync算法中的弱滚动校验和算法,该算法能够在已知缓冲区X1..Xn的校验和基础上高效计算出X2..Xn+1的校验和,具有计算速度快的特点。通过递归关系简化了计算过程,使得能够快速地在文件的不同偏移位置上计算长度为S的数据块校验和。尽管简单,但在实践中发现其作为初步匹配检查时错误匹配的概率较低。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Rolling checksum

The weak rolling checksum used in the rsync algorithm needs to have the property that it is very cheap to calculate the checksum of a buffer X2 .. Xn+1 given the checksum of buffer X1 .. Xn and the values of the bytes X1 and Xn+1.

The weak checksum algorithm we used in our implementation was inspired by Mark Adler's adler-32 checksum. Our checksum is defined by 

\begin{displaymath}a(k,l) = (\sum_{i=k}^l X_i) \bmod M \end{displaymath}


\begin{displaymath}b(k,l) = (\sum_{i=k}^l (l-i+1)X_i) \bmod M \end{displaymath}


s( k, l) =  a( k, l) + 2 16  b( k, l)

where s(k,l) is the rolling checksum of the bytes $X_k \ldots X_l$. For simplicity and speed, we use M = 216.

The important property of this checksum is that successive values can be computed very efficiently using the recurrence relations


\begin{displaymath}a(k+1,l+1) = (a(k,l) - X_k + X_{l+1}) \bmod M \end{displaymath}


\begin{displaymath}b(k+1,l+1) = (b(k,l) - (l-k+1) X_k + a(k+1,l+1)) \bmod M \end{displaymath}

Thus the checksum can be calculated for blocks of length S at all possible offsets within a file in a ``rolling'' fashion, with very little computation at each point.

Despite its simplicity, this checksum was found to be quite adequate as a first level check for a match of two file blocks. We have found in practice that the probability of this checksum matching when the blocks are not equal is quite low. This is important because the much more expensive strong checksum must be calculated for each block where the weak checksum matches.


源文:http://rsync.samba.org/tech_report/node3.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值