1262395Sbapt/*
2262395Sbapt   xxHash - Fast Hash algorithm
3262395Sbapt   Header File
4262395Sbapt   Copyright (C) 2012-2013, Yann Collet.
5262395Sbapt   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6262395Sbapt
7262395Sbapt   Redistribution and use in source and binary forms, with or without
8262395Sbapt   modification, are permitted provided that the following conditions are
9262395Sbapt   met:
10262395Sbapt
11262395Sbapt       * Redistributions of source code must retain the above copyright
12262395Sbapt   notice, this list of conditions and the following disclaimer.
13262395Sbapt       * Redistributions in binary form must reproduce the above
14262395Sbapt   copyright notice, this list of conditions and the following disclaimer
15262395Sbapt   in the documentation and/or other materials provided with the
16262395Sbapt   distribution.
17262395Sbapt
18262395Sbapt   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19262395Sbapt   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20262395Sbapt   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21262395Sbapt   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22262395Sbapt   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23262395Sbapt   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24262395Sbapt   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25262395Sbapt   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26262395Sbapt   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27262395Sbapt   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28262395Sbapt   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29262395Sbapt
30262395Sbapt   You can contact the author at :
31262395Sbapt   - xxHash source repository : http://code.google.com/p/xxhash/
32262395Sbapt*/
33262395Sbapt
34262395Sbapt/* Notice extracted from xxHash homepage :
35262395Sbapt
36262395SbaptxxHash is an extremely fast Hash algorithm, running at RAM speed limits.
37262395SbaptIt also successfully passes all tests from the SMHasher suite.
38262395Sbapt
39262395SbaptComparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
40262395Sbapt
41262395SbaptName            Speed       Q.Score   Author
42262395SbaptxxHash          5.4 GB/s     10
43262395SbaptCrapWow         3.2 GB/s      2       Andrew
44262395SbaptMumurHash 3a    2.7 GB/s     10       Austin Appleby
45262395SbaptSpookyHash      2.0 GB/s     10       Bob Jenkins
46262395SbaptSBox            1.4 GB/s      9       Bret Mulvey
47262395SbaptLookup3         1.2 GB/s      9       Bob Jenkins
48262395SbaptSuperFastHash   1.2 GB/s      1       Paul Hsieh
49262395SbaptCityHash64      1.05 GB/s    10       Pike & Alakuijala
50262395SbaptFNV             0.55 GB/s     5       Fowler, Noll, Vo
51262395SbaptCRC32           0.43 GB/s     9
52262395SbaptMD5-32          0.33 GB/s    10       Ronald L. Rivest
53262395SbaptSHA1-32         0.28 GB/s    10
54262395Sbapt
55262395SbaptQ.Score is a measure of quality of the hash function.
56262395SbaptIt depends on successfully passing SMHasher test set.
57262395Sbapt10 is a perfect score.
58262395Sbapt*/
59262395Sbapt
60262395Sbapt#pragma once
61262395Sbapt
62262395Sbapt#if defined (__cplusplus)
63262395Sbaptextern "C" {
64262395Sbapt#endif
65262395Sbapt
66262395Sbapt
67262395Sbapt//****************************
68262395Sbapt// Type
69262395Sbapt//****************************
70262395Sbapttypedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
71262395Sbapt
72262395Sbapt
73262395Sbapt
74262395Sbapt//****************************
75262395Sbapt// Simple Hash Functions
76262395Sbapt//****************************
77262395Sbapt
78262395Sbaptunsigned int XXH32 (const void* input, int len, unsigned int seed);
79262395Sbapt
80262395Sbapt/*
81262395SbaptXXH32() :
82262395Sbapt    Calculate the 32-bits hash of sequence of length "len" stored at memory address "input".
83262395Sbapt    The memory between input & input+len must be valid (allocated and read-accessible).
84262395Sbapt    "seed" can be used to alter the result predictably.
85262395Sbapt    This function successfully passes all SMHasher tests.
86262395Sbapt    Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
87262395Sbapt    Note that "len" is type "int", which means it is limited to 2^31-1.
88262395Sbapt    If your data is larger, use the advanced functions below.
89262395Sbapt*/
90262395Sbapt
91262395Sbapt
92262395Sbapt
93262395Sbapt//****************************
94262395Sbapt// Advanced Hash Functions
95262395Sbapt//****************************
96262395Sbapt
97262395Sbaptvoid*         XXH32_init   (unsigned int seed);
98262395SbaptXXH_errorcode XXH32_update (void* state, const void* input, int len);
99262395Sbaptunsigned int  XXH32_digest (void* state);
100262395Sbapt
101262395Sbapt/*
102262395SbaptThese functions calculate the xxhash of an input provided in several small packets,
103262395Sbaptas opposed to an input provided as a single block.
104262395Sbapt
105262395SbaptIt must be started with :
106262395Sbaptvoid* XXH32_init()
107262395SbaptThe function returns a pointer which holds the state of calculation.
108262395Sbapt
109262395SbaptThis pointer must be provided as "void* state" parameter for XXH32_update().
110262395SbaptXXH32_update() can be called as many times as necessary.
111262395SbaptThe user must provide a valid (allocated) input.
112262395SbaptThe function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
113262395SbaptNote that "len" is type "int", which means it is limited to 2^31-1.
114262395SbaptIf your data is larger, it is recommended to chunk your data into blocks
115262395Sbaptof size for example 2^30 (1GB) to avoid any "int" overflow issue.
116262395Sbapt
117262395SbaptFinally, you can end the calculation anytime, by using XXH32_digest().
118262395SbaptThis function returns the final 32-bits hash.
119262395SbaptYou must provide the same "void* state" parameter created by XXH32_init().
120262395SbaptMemory will be freed by XXH32_digest().
121262395Sbapt*/
122262395Sbapt
123262395Sbapt
124262395Sbaptint           XXH32_sizeofState(void);
125262395SbaptXXH_errorcode XXH32_resetState(void* state, unsigned int seed);
126262395Sbapt
127262395Sbapt#define       XXH32_SIZEOFSTATE 48
128262395Sbapttypedef struct { long long ll[(XXH32_SIZEOFSTATE+(sizeof(long long)-1))/sizeof(long long)]; } XXH32_stateSpace_t;
129262395Sbapt/*
130262395SbaptThese functions allow user application to make its own allocation for state.
131262395Sbapt
132262395SbaptXXH32_sizeofState() is used to know how much space must be allocated for the xxHash 32-bits state.
133262395SbaptNote that the state must be aligned to access 'long long' fields. Memory must be allocated and referenced by a pointer.
134262395SbaptThis pointer must then be provided as 'state' into XXH32_resetState(), which initializes the state.
135262395Sbapt
136262395SbaptFor static allocation purposes (such as allocation on stack, or freestanding systems without malloc()),
137262395Sbaptuse the structure XXH32_stateSpace_t, which will ensure that memory space is large enough and correctly aligned to access 'long long' fields.
138262395Sbapt*/
139262395Sbapt
140262395Sbapt
141262395Sbaptunsigned int XXH32_intermediateDigest (void* state);
142262395Sbapt/*
143262395SbaptThis function does the same as XXH32_digest(), generating a 32-bit hash,
144262395Sbaptbut preserve memory context.
145262395SbaptThis way, it becomes possible to generate intermediate hashes, and then continue feeding data with XXH32_update().
146262395SbaptTo free memory context, use XXH32_digest(), or free().
147262395Sbapt*/
148262395Sbapt
149262395Sbapt
150262395Sbapt
151262395Sbapt//****************************
152262395Sbapt// Deprecated function names
153262395Sbapt//****************************
154262395Sbapt// The following translations are provided to ease code transition
155262395Sbapt// You are encouraged to no longer this function names
156262395Sbapt#define XXH32_feed   XXH32_update
157262395Sbapt#define XXH32_result XXH32_digest
158262395Sbapt#define XXH32_getIntermediateResult XXH32_intermediateDigest
159262395Sbapt
160262395Sbapt
161262395Sbapt
162262395Sbapt#if defined (__cplusplus)
163262395Sbapt}
164262395Sbapt#endif
165