<s>
A	O
rolling	B-Error_Name
hash	I-Error_Name
(	O
also	O
known	O
as	O
recursive	O
hashing	O
or	O
rolling	B-Error_Name
checksum	I-Error_Name
)	O
is	O
a	O
hash	B-Error_Name
function	I-Error_Name
where	O
the	O
input	O
is	O
hashed	O
in	O
a	O
window	O
that	O
moves	O
through	O
the	O
input	O
.	O
</s>
<s>
A	O
few	O
hash	B-Error_Name
functions	I-Error_Name
allow	O
a	O
rolling	B-Error_Name
hash	I-Error_Name
to	O
be	O
computed	O
very	O
quickly	O
—	O
the	O
new	O
hash	B-Error_Name
value	I-Error_Name
is	O
rapidly	O
calculated	O
given	O
only	O
the	O
old	O
hash	B-Error_Name
value	I-Error_Name
,	O
the	O
old	O
value	O
removed	O
from	O
the	O
window	O
,	O
and	O
the	O
new	O
value	O
added	O
to	O
the	O
window	O
—	O
similar	O
to	O
the	O
way	O
a	O
moving	O
average	O
function	O
can	O
be	O
computed	O
much	O
more	O
quickly	O
than	O
other	O
low-pass	O
filters	O
.	O
</s>
<s>
One	O
of	O
the	O
main	O
applications	O
is	O
the	O
Rabin	B-Algorithm
–	I-Algorithm
Karp	I-Algorithm
string	I-Algorithm
search	I-Algorithm
algorithm	I-Algorithm
,	O
which	O
uses	O
the	O
rolling	B-Error_Name
hash	I-Error_Name
described	O
below	O
.	O
</s>
<s>
Another	O
popular	O
application	O
is	O
the	O
rsync	B-Application
program	O
,	O
which	O
uses	O
a	O
checksum	O
based	O
on	O
Mark	O
Adler	O
's	O
adler-32	B-Algorithm
as	O
its	O
rolling	B-Error_Name
hash	I-Error_Name
.	O
</s>
<s>
Low	O
Bandwidth	O
Network	O
Filesystem	O
(	O
LBFS	O
)	O
uses	O
a	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
as	O
its	O
rolling	B-Error_Name
hash	I-Error_Name
.	O
</s>
<s>
FastCDC	O
(	O
Fast	O
Content-Defined	O
Chunking	O
)	O
uses	O
a	O
compute-efficient	O
Gear	O
fingerprint	O
as	O
its	O
rolling	B-Error_Name
hash	I-Error_Name
.	O
</s>
<s>
At	O
best	O
,	O
rolling	B-Error_Name
hash	I-Error_Name
values	O
are	O
pairwise	O
independent	O
or	O
strongly	O
universal	B-Algorithm
.	O
</s>
<s>
They	O
cannot	O
be	O
3-wise	B-Error_Name
independent	I-Error_Name
,	O
for	O
example	O
.	O
</s>
<s>
The	O
Rabin	B-Algorithm
–	I-Algorithm
Karp	I-Algorithm
string	I-Algorithm
search	I-Algorithm
algorithm	I-Algorithm
is	O
often	O
explained	O
using	O
a	O
rolling	B-Error_Name
hash	I-Error_Name
function	O
that	O
only	O
uses	O
multiplications	O
and	O
additions	O
:	O
</s>
<s>
where	O
is	O
a	O
constant	O
,	O
and	O
are	O
the	O
input	O
characters	O
(	O
but	O
this	O
function	O
is	O
not	O
a	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
,	O
see	O
below	O
)	O
.	O
</s>
<s>
See	O
linear	B-Algorithm
congruential	I-Algorithm
generator	I-Algorithm
for	O
more	O
discussion	O
.	O
</s>
<s>
The	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
is	O
another	O
hash	B-Error_Name
,	O
which	O
also	O
interprets	O
the	O
input	O
as	O
a	O
polynomial	O
,	O
but	O
over	O
the	O
Galois	O
field	O
GF(2 )	O
.	O
</s>
<s>
The	O
hash	B-Error_Name
is	O
the	O
result	O
of	O
the	O
division	O
of	O
that	O
polynomial	O
by	O
an	O
irreducible	O
polynomial	O
over	O
GF(2 )	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
update	O
a	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
using	O
only	O
the	O
entering	O
and	O
the	O
leaving	O
byte	O
,	O
making	O
it	O
effectively	O
a	O
rolling	B-Error_Name
hash	I-Error_Name
.	O
</s>
<s>
Because	O
it	O
shares	O
the	O
same	O
author	O
as	O
the	O
Rabin	B-Algorithm
–	I-Algorithm
Karp	I-Algorithm
string	I-Algorithm
search	I-Algorithm
algorithm	I-Algorithm
,	O
which	O
is	O
often	O
explained	O
with	O
another	O
,	O
simpler	O
rolling	B-Error_Name
hash	I-Error_Name
,	O
and	O
because	O
this	O
simpler	O
rolling	B-Error_Name
hash	I-Error_Name
is	O
also	O
a	O
polynomial	O
,	O
both	O
rolling	B-Error_Name
hashes	I-Error_Name
are	O
often	O
mistaken	O
for	O
each	O
other	O
.	O
</s>
<s>
The	O
backup	O
software	O
restic	O
uses	O
a	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
for	O
splitting	O
files	O
,	O
with	O
blob	O
size	O
varying	O
between	O
and	O
.	O
</s>
<s>
It	O
is	O
a	O
form	O
of	O
tabulation	B-Algorithm
hashing	I-Algorithm
:	O
it	O
presumes	O
that	O
there	O
is	O
some	O
hash	B-Error_Name
function	I-Error_Name
from	O
characters	O
to	O
integers	O
in	O
the	O
interval	O
.	O
</s>
<s>
This	O
hash	B-Error_Name
function	I-Error_Name
might	O
be	O
simply	O
an	O
array	O
or	O
a	O
hash	B-Algorithm
table	I-Algorithm
mapping	O
characters	O
to	O
random	O
integers	O
.	O
</s>
<s>
Let	O
the	O
function	O
be	O
a	O
cyclic	O
binary	O
rotation	O
(	O
or	O
circular	B-Algorithm
shift	I-Algorithm
)	O
:	O
it	O
rotates	O
the	O
bits	O
by	O
1	O
to	O
the	O
left	O
,	O
pushing	O
the	O
latest	O
bit	O
in	O
the	O
first	O
position	O
.	O
</s>
<s>
Computing	O
the	O
hash	B-Error_Name
values	I-Error_Name
in	O
a	O
rolling	O
fashion	O
is	O
done	O
as	O
follows	O
.	O
</s>
<s>
Let	O
be	O
the	O
previous	O
hash	B-Error_Name
value	I-Error_Name
.	O
</s>
<s>
Hashing	O
by	O
cyclic	O
polynomials	O
is	O
strongly	O
universal	B-Algorithm
or	O
pairwise	O
independent	O
:	O
simply	O
keep	O
the	O
first	O
bits	O
.	O
</s>
<s>
One	O
of	O
the	O
interesting	O
use	O
cases	O
of	O
the	O
rolling	B-Error_Name
hash	I-Error_Name
function	O
is	O
that	O
it	O
can	O
create	O
dynamic	O
,	O
content-based	O
chunks	O
of	O
a	O
stream	O
or	O
file	O
.	O
</s>
<s>
A	O
simple	O
approach	O
to	O
making	O
dynamic	O
chunks	O
is	O
to	O
calculate	O
a	O
rolling	B-Error_Name
hash	I-Error_Name
,	O
and	O
if	O
the	O
hash	B-Error_Name
value	I-Error_Name
matches	O
an	O
arbitrary	O
pattern	O
(	O
e.g.	O
</s>
<s>
all	O
zeroes	O
)	O
in	O
the	O
lower	O
N	O
bits	O
(	O
with	O
a	O
probability	O
of	O
,	O
given	O
the	O
hash	B-Error_Name
has	O
a	O
uniform	O
probability	O
distribution	O
)	O
then	O
it	O
’s	O
chosen	O
to	O
be	O
a	O
chunk	O
boundary	O
.	O
</s>
<s>
Once	O
the	O
boundaries	O
are	O
known	O
,	O
the	O
chunks	O
need	O
to	O
be	O
compared	O
by	O
cryptographic	O
hash	B-Error_Name
value	I-Error_Name
to	O
detect	O
changes	O
.	O
</s>
<s>
Such	O
content-defined	O
chunking	O
is	O
often	O
used	O
for	O
data	B-General_Concept
deduplication	I-General_Concept
.	O
</s>
<s>
is	O
a	O
"	O
hash	B-Error_Name
value	I-Error_Name
"	O
consisting	O
of	O
the	O
bottom	O
12	O
bits	O
of	O
.	O
</s>
<s>
The	O
Content-Defined	O
Chunking	O
algorithm	O
needs	O
to	O
compute	O
the	O
hash	B-Error_Name
value	I-Error_Name
of	O
a	O
data	O
stream	O
byte	O
by	O
byte	O
and	O
split	O
the	O
data	O
stream	O
into	O
chunks	O
when	O
the	O
hash	B-Error_Name
value	I-Error_Name
meets	O
a	O
predefined	O
value	O
.	O
</s>
<s>
It	O
uses	O
a	O
fast	O
rolling	O
Gear	O
hash	B-Error_Name
algorithm	I-Error_Name
,	O
skipping	O
the	O
minimum	O
length	O
,	O
normalizing	O
the	O
chunk-size	O
distribution	O
,	O
and	O
last	O
but	O
not	O
the	O
least	O
,	O
rolling	O
two	O
bytes	O
each	O
time	O
to	O
speed	O
up	O
the	O
CDC	O
algorithm	O
,	O
which	O
can	O
achieve	O
about	O
10X	O
higher	O
throughput	O
than	O
Rabin-based	O
CDC	O
approach	O
.	O
</s>
<s>
Here	O
FastCDC	O
uses	O
Gear	O
hashing	B-Error_Name
algorithm	I-Error_Name
which	O
can	O
calculate	O
the	O
rolling	B-Error_Name
hashing	I-Error_Name
results	O
quickly	O
and	O
keep	O
the	O
uniform	O
distribution	O
of	O
the	O
hashing	O
results	O
as	O
Rabin	O
.	O
</s>
<s>
Compared	O
with	O
the	O
traditional	O
Rabin	O
hashing	B-Error_Name
algorithm	I-Error_Name
,	O
it	O
achieves	O
a	O
much	O
faster	O
speed	O
.	O
</s>
<s>
All	O
rolling	B-Error_Name
hash	I-Error_Name
functions	O
can	O
be	O
computed	O
in	O
time	O
linear	O
in	O
the	O
number	O
of	O
characters	O
and	O
updated	O
in	O
constant	O
time	O
when	O
characters	O
are	O
shifted	O
by	O
one	O
position	O
.	O
</s>
<s>
In	O
particular	O
,	O
computing	O
the	O
Rabin-Karp	B-Algorithm
rolling	B-Error_Name
hash	I-Error_Name
of	O
a	O
string	O
of	O
length	O
requires	O
modular	O
arithmetic	O
operations	O
,	O
and	O
hashing	O
by	O
cyclic	O
polynomials	O
requires	O
bitwise	O
exclusive	O
ors	O
and	O
circular	B-Algorithm
shifts	I-Algorithm
.	O
</s>
