\doxysubsection{rollsum.\+h}
\label{rollsum_8h_source}\index{rollsum.h@{rollsum.h}}
\mbox{\hyperlink{rollsum_8h}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * rollsum -\/-\/ the librsync rolling checksum}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 2003 by Donovan Baarda <abo@minkirri.apana.org.au>}}
\DoxyCodeLine{00006 \textcolor{comment}{ * based on work, Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00007 \textcolor{comment}{ *}}
\DoxyCodeLine{00008 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{00009 \textcolor{comment}{ * it under the terms of the GNU Lesser General Public License as published by}}
\DoxyCodeLine{00010 \textcolor{comment}{ * the Free Software Foundation; either version 2.1 of the License, or}}
\DoxyCodeLine{00011 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{00012 \textcolor{comment}{ *}}
\DoxyCodeLine{00013 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00014 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00015 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00016 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00017 \textcolor{comment}{ *}}
\DoxyCodeLine{00018 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public License}}
\DoxyCodeLine{00019 \textcolor{comment}{ * along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00020 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00021 \textcolor{comment}{ */}}
\DoxyCodeLine{00022 \textcolor{comment}{}}
\DoxyCodeLine{00023 \textcolor{comment}{/** \(\backslash\)file rollsum.h}}
\DoxyCodeLine{00024 \textcolor{comment}{ * The Rollsum class implementation of the original rsync rollsum. */}}
\DoxyCodeLine{00025 \textcolor{preprocessor}{\#ifndef ROLLSUM\_H}}
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#  define ROLLSUM\_H}}
\DoxyCodeLine{00027 }
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#  include <stddef.h>}}
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#  include <stdint.h>}}
\DoxyCodeLine{00030 }
\DoxyCodeLine{00031 \textcolor{comment}{/* We should make this something other than zero to improve the checksum}}
\DoxyCodeLine{00032 \textcolor{comment}{   algorithm: tridge suggests a prime number. */}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#  define ROLLSUM\_CHAR\_OFFSET 31}}
\DoxyCodeLine{00034 \textcolor{comment}{}}
\DoxyCodeLine{00035 \textcolor{comment}{/** The Rollsum state type. */}}
\DoxyCodeLine{00036 \textcolor{keyword}{typedef} \textcolor{keyword}{struct }Rollsum \{}
\DoxyCodeLine{00037     \textcolor{keywordtype}{size\_t} count;               \textcolor{comment}{/**< count of bytes included in sum */}}
\DoxyCodeLine{00038     uint\_fast16\_t s1;           \textcolor{comment}{/**< s1 part of sum */}}
\DoxyCodeLine{00039     uint\_fast16\_t s2;           \textcolor{comment}{/**< s2 part of sum */}}
\DoxyCodeLine{00040 \} Rollsum;}
\DoxyCodeLine{00041 }
\DoxyCodeLine{00042 \textcolor{keywordtype}{void} RollsumUpdate(Rollsum *sum, \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *buf, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{00043 }
\DoxyCodeLine{00044 \textcolor{comment}{/* static inline implementations of simple routines */}}
\DoxyCodeLine{00045 }
\DoxyCodeLine{00046 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} RollsumInit(Rollsum *sum)}
\DoxyCodeLine{00047 \{}
\DoxyCodeLine{00048     sum-\/>count = sum-\/>s1 = sum-\/>s2 = 0;}
\DoxyCodeLine{00049 \}}
\DoxyCodeLine{00050 }
\DoxyCodeLine{00051 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} RollsumRotate(Rollsum *sum, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} out,}
\DoxyCodeLine{00052                                  \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} in)}
\DoxyCodeLine{00053 \{}
\DoxyCodeLine{00054     sum-\/>s1 += in -\/ out;}
\DoxyCodeLine{00055     sum-\/>s2 += sum-\/>s1 -\/ (uint\_fast16\_t)sum-\/>count * (out + ROLLSUM\_CHAR\_OFFSET);}
\DoxyCodeLine{00056 \}}
\DoxyCodeLine{00057 }
\DoxyCodeLine{00058 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} RollsumRollin(Rollsum *sum, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} in)}
\DoxyCodeLine{00059 \{}
\DoxyCodeLine{00060     sum-\/>s1 += in + ROLLSUM\_CHAR\_OFFSET;}
\DoxyCodeLine{00061     sum-\/>s2 += sum-\/>s1;}
\DoxyCodeLine{00062     sum-\/>count++;}
\DoxyCodeLine{00063 \}}
\DoxyCodeLine{00064 }
\DoxyCodeLine{00065 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} RollsumRollout(Rollsum *sum, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} out)}
\DoxyCodeLine{00066 \{}
\DoxyCodeLine{00067     sum-\/>s1 -\/= out + ROLLSUM\_CHAR\_OFFSET;}
\DoxyCodeLine{00068     sum-\/>s2 -\/= (uint\_fast16\_t)sum-\/>count * (out + ROLLSUM\_CHAR\_OFFSET);}
\DoxyCodeLine{00069     sum-\/>count-\/-\/;}
\DoxyCodeLine{00070 \}}
\DoxyCodeLine{00071 }
\DoxyCodeLine{00072 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint32\_t RollsumDigest(Rollsum *sum)}
\DoxyCodeLine{00073 \{}
\DoxyCodeLine{00074     \textcolor{keywordflow}{return} ((uint32\_t)sum-\/>s2 << 16) | ((uint32\_t)sum-\/>s1 \& 0xffff);}
\DoxyCodeLine{00075 \}}
\DoxyCodeLine{00076 }
\DoxyCodeLine{00077 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* !ROLLSUM\_H */}\textcolor{preprocessor}{}}

\end{DoxyCode}
