benchmark silo added
[c11concurrency-benchmarks.git] / silo / third-party / lz4 / xxhash.h
1 /*\r
2    xxHash - Fast Hash algorithm\r
3    Header File\r
4    Copyright (C) 2012-2013, Yann Collet.\r
5    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
6 \r
7    Redistribution and use in source and binary forms, with or without\r
8    modification, are permitted provided that the following conditions are\r
9    met:\r
10   \r
11        * Redistributions of source code must retain the above copyright\r
12    notice, this list of conditions and the following disclaimer.\r
13        * Redistributions in binary form must reproduce the above\r
14    copyright notice, this list of conditions and the following disclaimer\r
15    in the documentation and/or other materials provided with the\r
16    distribution.\r
17   \r
18    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
19    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
20    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
21    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
22    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
26    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
28    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29 \r
30    You can contact the author at :\r
31    - xxHash source repository : http://code.google.com/p/xxhash/\r
32 */\r
33 \r
34 /* Notice extracted from xxHash homepage :\r
35 \r
36 xxHash is an extremely fast Hash algorithm, running at RAM speed limits.\r
37 It also successfully passes all tests from the SMHasher suite.\r
38 \r
39 Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)\r
40 \r
41 Name            Speed       Q.Score   Author\r
42 xxHash          5.4 GB/s     10\r
43 CrapWow         3.2 GB/s      2       Andrew\r
44 MumurHash 3a    2.7 GB/s     10       Austin Appleby\r
45 SpookyHash      2.0 GB/s     10       Bob Jenkins\r
46 SBox            1.4 GB/s      9       Bret Mulvey\r
47 Lookup3         1.2 GB/s      9       Bob Jenkins\r
48 SuperFastHash   1.2 GB/s      1       Paul Hsieh\r
49 CityHash64      1.05 GB/s    10       Pike & Alakuijala\r
50 FNV             0.55 GB/s     5       Fowler, Noll, Vo\r
51 CRC32           0.43 GB/s     9\r
52 MD5-32          0.33 GB/s    10       Ronald L. Rivest\r
53 SHA1-32         0.28 GB/s    10\r
54 \r
55 Q.Score is a measure of quality of the hash function. \r
56 It depends on successfully passing SMHasher test set. \r
57 10 is a perfect score.\r
58 */\r
59 \r
60 #pragma once\r
61 \r
62 #if defined (__cplusplus)\r
63 extern "C" {\r
64 #endif\r
65 \r
66 \r
67 //****************************\r
68 // Type\r
69 //****************************\r
70 typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;\r
71 \r
72 \r
73 \r
74 //****************************\r
75 // Simple Hash Functions\r
76 //****************************\r
77 \r
78 unsigned int XXH32 (const void* input, int len, unsigned int seed);\r
79 \r
80 /*\r
81 XXH32() :\r
82     Calculate the 32-bits hash of sequence of length "len" stored at memory address "input".\r
83     The memory between input & input+len must be valid (allocated and read-accessible).\r
84     "seed" can be used to alter the result predictably.\r
85     This function successfully passes all SMHasher tests.\r
86     Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s\r
87     Note that "len" is type "int", which means it is limited to 2^31-1.\r
88     If your data is larger, use the advanced functions below.\r
89 */\r
90 \r
91 \r
92 \r
93 //****************************\r
94 // Advanced Hash Functions\r
95 //****************************\r
96 \r
97 void*         XXH32_init   (unsigned int seed);\r
98 XXH_errorcode XXH32_update (void* state, const void* input, int len);\r
99 unsigned int  XXH32_digest (void* state);\r
100 \r
101 /*\r
102 These functions calculate the xxhash of an input provided in several small packets,\r
103 as opposed to an input provided as a single block.\r
104 \r
105 It must be started with :\r
106 void* XXH32_init()\r
107 The function returns a pointer which holds the state of calculation.\r
108 \r
109 This pointer must be provided as "void* state" parameter for XXH32_update().\r
110 XXH32_update() can be called as many times as necessary.\r
111 The user must provide a valid (allocated) input.\r
112 The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.\r
113 Note that "len" is type "int", which means it is limited to 2^31-1. \r
114 If your data is larger, it is recommended to chunk your data into blocks \r
115 of size for example 2^30 (1GB) to avoid any "int" overflow issue.\r
116 \r
117 Finally, you can end the calculation anytime, by using XXH32_digest().\r
118 This function returns the final 32-bits hash.\r
119 You must provide the same "void* state" parameter created by XXH32_init().\r
120 Memory will be freed by XXH32_digest().\r
121 */\r
122 \r
123 \r
124 int           XXH32_sizeofState();\r
125 XXH_errorcode XXH32_resetState(void* state, unsigned int seed);\r
126 \r
127 #define       XXH32_SIZEOFSTATE 48\r
128 typedef struct { long long ll[(XXH32_SIZEOFSTATE+(sizeof(long long)-1))/sizeof(long long)]; } XXH32_stateSpace_t;\r
129 /*\r
130 These functions allow user application to make its own allocation for state.\r
131 \r
132 XXH32_sizeofState() is used to know how much space must be allocated for the xxHash 32-bits state.\r
133 Note that the state must be aligned to access 'long long' fields. Memory must be allocated and referenced by a pointer.\r
134 This pointer must then be provided as 'state' into XXH32_resetState(), which initializes the state.\r
135 \r
136 For static allocation purposes (such as allocation on stack, or freestanding systems without malloc()),\r
137 use the structure XXH32_stateSpace_t, which will ensure that memory space is large enough and correctly aligned to access 'long long' fields.\r
138 */\r
139 \r
140 \r
141 unsigned int XXH32_intermediateDigest (void* state);\r
142 /*\r
143 This function does the same as XXH32_digest(), generating a 32-bit hash,\r
144 but preserve memory context.\r
145 This way, it becomes possible to generate intermediate hashes, and then continue feeding data with XXH32_update().\r
146 To free memory context, use XXH32_digest(), or free().\r
147 */\r
148 \r
149 \r
150 \r
151 //****************************\r
152 // Deprecated function names\r
153 //****************************\r
154 // The following translations are provided to ease code transition\r
155 // You are encouraged to no longer this function names\r
156 #define XXH32_feed   XXH32_update\r
157 #define XXH32_result XXH32_digest\r
158 #define XXH32_getIntermediateResult XXH32_intermediateDigest\r
159 \r
160 \r
161 \r
162 #if defined (__cplusplus)\r
163 }\r
164 #endif\r