\doxysubsection{sumset.\+h}
\label{sumset_8h_source}\index{sumset.h@{sumset.h}}
\mbox{\hyperlink{sumset_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}{ * librsync -\/-\/ the library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ * Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>}}
\DoxyCodeLine{00007 \textcolor{comment}{ *}}
\DoxyCodeLine{00008 \textcolor{comment}{ * This program is free software; you can redistribute it and/or}}
\DoxyCodeLine{00009 \textcolor{comment}{ * modify it under the terms of the GNU Lesser General Public License}}
\DoxyCodeLine{00010 \textcolor{comment}{ * as published by the Free Software Foundation; either version 2.1 of}}
\DoxyCodeLine{00011 \textcolor{comment}{ * the License, or (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, but}}
\DoxyCodeLine{00014 \textcolor{comment}{ * WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00015 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU}}
\DoxyCodeLine{00016 \textcolor{comment}{ * 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}}
\DoxyCodeLine{00019 \textcolor{comment}{ * License 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 sumset.h}}
\DoxyCodeLine{00024 \textcolor{comment}{ * The rs\_signature class implementation of a file signature. */}}
\DoxyCodeLine{00025 \textcolor{preprocessor}{\#ifndef SUMSET\_H}}
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#  define SUMSET\_H}}
\DoxyCodeLine{00027 }
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#  include <assert.h>}}
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#  include <stddef.h>}}
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#  include "{}hashtable.h"{}}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#  include "{}checksum.h"{}}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#  include "{}librsync.h"{}}}
\DoxyCodeLine{00033 \textcolor{comment}{}}
\DoxyCodeLine{00034 \textcolor{comment}{/** Signature of a single block. */}}
\DoxyCodeLine{00035 \textcolor{keyword}{typedef} \textcolor{keyword}{struct }rs\_block\_sig \{}
\DoxyCodeLine{00036     rs\_weak\_sum\_t weak\_sum;     \textcolor{comment}{/**< Block's weak checksum. */}}
\DoxyCodeLine{00037     rs\_strong\_sum\_t strong\_sum; \textcolor{comment}{/**< Block's strong checksum. */}}
\DoxyCodeLine{00038 \} rs\_block\_sig\_t;}
\DoxyCodeLine{00039 \textcolor{comment}{}}
\DoxyCodeLine{00040 \textcolor{comment}{/** Signature of a whole file.}}
\DoxyCodeLine{00041 \textcolor{comment}{ *}}
\DoxyCodeLine{00042 \textcolor{comment}{ * This includes the all the block sums generated for a file and datastructures}}
\DoxyCodeLine{00043 \textcolor{comment}{ * for fast matching against them. */}}
\DoxyCodeLine{00044 \textcolor{keyword}{struct }rs\_signature \{}
\DoxyCodeLine{00045     \textcolor{keywordtype}{int} magic;                  \textcolor{comment}{/**< The signature magic value. */}}
\DoxyCodeLine{00046     \textcolor{keywordtype}{int} block\_len;              \textcolor{comment}{/**< The block length. */}}
\DoxyCodeLine{00047     \textcolor{keywordtype}{int} strong\_sum\_len;         \textcolor{comment}{/**< The block strong sum length. */}}
\DoxyCodeLine{00048     \textcolor{keywordtype}{int} count;                  \textcolor{comment}{/**< Total number of blocks. */}}
\DoxyCodeLine{00049     \textcolor{keywordtype}{int} size;                   \textcolor{comment}{/**< Total number of blocks allocated. */}}
\DoxyCodeLine{00050     \textcolor{keywordtype}{void} *block\_sigs;           \textcolor{comment}{/**< The packed block\_sigs for all blocks. */}}
\DoxyCodeLine{00051     hashtable\_t *hashtable;     \textcolor{comment}{/**< The hashtable for finding matches. */}}
\DoxyCodeLine{00052     \textcolor{comment}{/* The is extra stats not included in the hashtable stats. */}}
\DoxyCodeLine{00053 \textcolor{preprocessor}{\#  ifndef HASHTABLE\_NSTATS}}
\DoxyCodeLine{00054     \textcolor{keywordtype}{long} calc\_strong\_count;     \textcolor{comment}{/**< The count of strongsum calcs done. */}}
\DoxyCodeLine{00055 \textcolor{preprocessor}{\#  endif}}
\DoxyCodeLine{00056 \};}
\DoxyCodeLine{00057 \textcolor{comment}{}}
\DoxyCodeLine{00058 \textcolor{comment}{/** Initialize an rs\_signature instance.}}
\DoxyCodeLine{00059 \textcolor{comment}{ *}}
\DoxyCodeLine{00060 \textcolor{comment}{ * \(\backslash\)param *sig the signature to initialize.}}
\DoxyCodeLine{00061 \textcolor{comment}{ *}}
\DoxyCodeLine{00062 \textcolor{comment}{ * \(\backslash\)param magic -\/ the magic type to use (0 for "{}recommended"{}).}}
\DoxyCodeLine{00063 \textcolor{comment}{ *}}
\DoxyCodeLine{00064 \textcolor{comment}{ * \(\backslash\)param block\_len -\/ the block length to use (0 for "{}recommended"{}).}}
\DoxyCodeLine{00065 \textcolor{comment}{ *}}
\DoxyCodeLine{00066 \textcolor{comment}{ * \(\backslash\)param strong\_len -\/ the strongsum length to use (0 for "{}maximum"{}, -\/1 for}}
\DoxyCodeLine{00067 \textcolor{comment}{ * "{}minimum"{}). Must be <= the max strongsum size for the strongsum type}}
\DoxyCodeLine{00068 \textcolor{comment}{ * indicated by the magic value.}}
\DoxyCodeLine{00069 \textcolor{comment}{ *}}
\DoxyCodeLine{00070 \textcolor{comment}{ * \(\backslash\)param sig\_fsize -\/ the signature file size (-\/1 for "{}unknown"{}). Used to}}
\DoxyCodeLine{00071 \textcolor{comment}{ * preallocate required storage. */}}
\DoxyCodeLine{00072 rs\_result rs\_signature\_init(rs\_signature\_t *sig, rs\_magic\_number magic,}
\DoxyCodeLine{00073                             \textcolor{keywordtype}{size\_t} block\_len, \textcolor{keywordtype}{size\_t} strong\_len,}
\DoxyCodeLine{00074                             rs\_long\_t sig\_fsize);}
\DoxyCodeLine{00075 \textcolor{comment}{}}
\DoxyCodeLine{00076 \textcolor{comment}{/** Destroy an rs\_signature instance. */}}
\DoxyCodeLine{00077 \textcolor{keywordtype}{void} rs\_signature\_done(rs\_signature\_t *sig);}
\DoxyCodeLine{00078 \textcolor{comment}{}}
\DoxyCodeLine{00079 \textcolor{comment}{/** Add a block to an rs\_signature instance. */}}
\DoxyCodeLine{00080 rs\_block\_sig\_t *rs\_signature\_add\_block(rs\_signature\_t *sig,}
\DoxyCodeLine{00081                                        rs\_weak\_sum\_t weak\_sum,}
\DoxyCodeLine{00082                                        rs\_strong\_sum\_t *strong\_sum);}
\DoxyCodeLine{00083 \textcolor{comment}{}}
\DoxyCodeLine{00084 \textcolor{comment}{/** Find a matching block offset in a signature. */}}
\DoxyCodeLine{00085 rs\_long\_t rs\_signature\_find\_match(rs\_signature\_t *sig, rs\_weak\_sum\_t weak\_sum,}
\DoxyCodeLine{00086                                   \textcolor{keywordtype}{void} \textcolor{keyword}{const} *buf, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{00087 \textcolor{comment}{}}
\DoxyCodeLine{00088 \textcolor{comment}{/** Assert that rs\_sig\_args() args for rs\_signature\_init() are valid.}}
\DoxyCodeLine{00089 \textcolor{comment}{ *}}
\DoxyCodeLine{00090 \textcolor{comment}{ * We don't use a static inline function here so that assert failure output}}
\DoxyCodeLine{00091 \textcolor{comment}{ * points at where rs\_sig\_args\_check() was called from. */}}
\DoxyCodeLine{00092 \textcolor{preprocessor}{\#  define rs\_sig\_args\_check(magic, block\_len, strong\_len) do \{\(\backslash\)}}
\DoxyCodeLine{00093 \textcolor{preprocessor}{    assert(((magic) \& \string~0xff) == (RS\_MD4\_SIG\_MAGIC \& \string~0xff));\(\backslash\)}}
\DoxyCodeLine{00094 \textcolor{preprocessor}{    assert(((magic) \& 0xf0) == 0x30 || ((magic) \& 0xf0) == 0x40);\(\backslash\)}}
\DoxyCodeLine{00095 \textcolor{preprocessor}{    assert((((magic) \& 0x0f) == 0x06 \&\&\(\backslash\)}}
\DoxyCodeLine{00096 \textcolor{preprocessor}{            (int)(strong\_len) <= RS\_MD4\_SUM\_LENGTH) ||\(\backslash\)}}
\DoxyCodeLine{00097 \textcolor{preprocessor}{           (((magic) \& 0x0f) == 0x07 \&\&\(\backslash\)}}
\DoxyCodeLine{00098 \textcolor{preprocessor}{            (int)(strong\_len) <= RS\_BLAKE2\_SUM\_LENGTH));\(\backslash\)}}
\DoxyCodeLine{00099 \textcolor{preprocessor}{    assert(0 < (block\_len));\(\backslash\)}}
\DoxyCodeLine{00100 \textcolor{preprocessor}{    assert(0 < (strong\_len) \&\& (strong\_len) <= RS\_MAX\_STRONG\_SUM\_LENGTH);\(\backslash\)}}
\DoxyCodeLine{00101 \textcolor{preprocessor}{\} while (0)}}
\DoxyCodeLine{00102 \textcolor{comment}{}}
\DoxyCodeLine{00103 \textcolor{comment}{/** Assert that a signature is valid.}}
\DoxyCodeLine{00104 \textcolor{comment}{ *}}
\DoxyCodeLine{00105 \textcolor{comment}{ * We don't use a static inline function here so that assert failure output}}
\DoxyCodeLine{00106 \textcolor{comment}{ * points at where rs\_signature\_check() was called from. */}}
\DoxyCodeLine{00107 \textcolor{preprocessor}{\#  define rs\_signature\_check(sig) do \{\(\backslash\)}}
\DoxyCodeLine{00108 \textcolor{preprocessor}{    rs\_sig\_args\_check((sig)-\/>magic, (sig)-\/>block\_len, (sig)-\/>strong\_sum\_len);\(\backslash\)}}
\DoxyCodeLine{00109 \textcolor{preprocessor}{    assert(0 <= (sig)-\/>count \&\& (sig)-\/>count <= (sig)-\/>size);\(\backslash\)}}
\DoxyCodeLine{00110 \textcolor{preprocessor}{    assert(!(sig)-\/>hashtable || (sig)-\/>hashtable-\/>count <= (sig)-\/>count);\(\backslash\)}}
\DoxyCodeLine{00111 \textcolor{preprocessor}{\} while (0)}}
\DoxyCodeLine{00112 \textcolor{comment}{}}
\DoxyCodeLine{00113 \textcolor{comment}{/** Get the weaksum kind for a signature. */}}
\DoxyCodeLine{00114 \textcolor{keyword}{static} \textcolor{keyword}{inline} weaksum\_kind\_t rs\_signature\_weaksum\_kind(rs\_signature\_t \textcolor{keyword}{const}}
\DoxyCodeLine{00115                                                        *sig)}
\DoxyCodeLine{00116 \{}
\DoxyCodeLine{00117     \textcolor{keywordflow}{return} (sig-\/>magic \& 0xf0) == 0x30 ? RS\_ROLLSUM : RS\_RABINKARP;}
\DoxyCodeLine{00118 \}}
\DoxyCodeLine{00119 \textcolor{comment}{}}
\DoxyCodeLine{00120 \textcolor{comment}{/** Get the strongsum kind for a signature. */}}
\DoxyCodeLine{00121 \textcolor{keyword}{static} \textcolor{keyword}{inline} strongsum\_kind\_t rs\_signature\_strongsum\_kind(rs\_signature\_t \textcolor{keyword}{const}}
\DoxyCodeLine{00122                                                            *sig)}
\DoxyCodeLine{00123 \{}
\DoxyCodeLine{00124     \textcolor{keywordflow}{return} (sig-\/>magic \& 0x0f) == 0x06 ? RS\_MD4 : RS\_BLAKE2;}
\DoxyCodeLine{00125 \}}
\DoxyCodeLine{00126 \textcolor{comment}{}}
\DoxyCodeLine{00127 \textcolor{comment}{/** Calculate the weak sum of a buffer. */}}
\DoxyCodeLine{00128 \textcolor{keyword}{static} \textcolor{keyword}{inline} rs\_weak\_sum\_t rs\_signature\_calc\_weak\_sum(rs\_signature\_t \textcolor{keyword}{const}}
\DoxyCodeLine{00129                                                        *sig, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *buf,}
\DoxyCodeLine{00130                                                        \textcolor{keywordtype}{size\_t} len)}
\DoxyCodeLine{00131 \{}
\DoxyCodeLine{00132     \textcolor{keywordflow}{return} rs\_calc\_weak\_sum(rs\_signature\_weaksum\_kind(sig), buf, len);}
\DoxyCodeLine{00133 \}}
\DoxyCodeLine{00134 \textcolor{comment}{}}
\DoxyCodeLine{00135 \textcolor{comment}{/** Calculate the strong sum of a buffer. */}}
\DoxyCodeLine{00136 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} rs\_signature\_calc\_strong\_sum(rs\_signature\_t \textcolor{keyword}{const} *sig,}
\DoxyCodeLine{00137                                                 \textcolor{keywordtype}{void} \textcolor{keyword}{const} *buf, \textcolor{keywordtype}{size\_t} len,}
\DoxyCodeLine{00138                                                 rs\_strong\_sum\_t *sum)}
\DoxyCodeLine{00139 \{}
\DoxyCodeLine{00140     rs\_calc\_strong\_sum(rs\_signature\_strongsum\_kind(sig), buf, len, sum);}
\DoxyCodeLine{00141 \}}
\DoxyCodeLine{00142 }
\DoxyCodeLine{00143 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* !SUMSET\_H */}\textcolor{preprocessor}{}}

\end{DoxyCode}
