NetBurner 3.5.6
PDF Version
xxhash.h
1/*
2 * xxHash - Extremely Fast Hash algorithm
3 * Header File
4 * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
5 *
6 * You can contact the author at :
7 * - xxHash source repository : https://github.com/Cyan4973/xxHash
8 *
9 * This source code is licensed under both the BSD-style license (found in the
10 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 * in the COPYING file in the root directory of this source tree).
12 * You may select, at your option, one of the above-listed licenses.
13*/
14
15/* Notice extracted from xxHash homepage :
16
17xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
18It also successfully passes all tests from the SMHasher suite.
19
20Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
21
22Name Speed Q.Score Author
23xxHash 5.4 GB/s 10
24CrapWow 3.2 GB/s 2 Andrew
25MumurHash 3a 2.7 GB/s 10 Austin Appleby
26SpookyHash 2.0 GB/s 10 Bob Jenkins
27SBox 1.4 GB/s 9 Bret Mulvey
28Lookup3 1.2 GB/s 9 Bob Jenkins
29SuperFastHash 1.2 GB/s 1 Paul Hsieh
30CityHash64 1.05 GB/s 10 Pike & Alakuijala
31FNV 0.55 GB/s 5 Fowler, Noll, Vo
32CRC32 0.43 GB/s 9
33MD5-32 0.33 GB/s 10 Ronald L. Rivest
34SHA1-32 0.28 GB/s 10
35
36Q.Score is a measure of quality of the hash function.
37It depends on successfully passing SMHasher test set.
3810 is a perfect score.
39
40A 64-bits version, named XXH64, is available since r35.
41It offers much better speed, but for 64-bits applications only.
42Name Speed on 64 bits Speed on 32 bits
43XXH64 13.8 GB/s 1.9 GB/s
44XXH32 6.8 GB/s 6.0 GB/s
45*/
46
47#if defined (__cplusplus)
48extern "C" {
49#endif
50
51#ifndef XXHASH_H_5627135585666179
52#define XXHASH_H_5627135585666179 1
53
54
55/* ****************************
56* Definitions
57******************************/
58#include <stddef.h> /* size_t */
59#include <stdint.h> /* uintxx_t */
60typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
61
62
63/* ****************************
64* API modifier
65******************************/
75#ifdef XXH_PRIVATE_API
76# ifndef XXH_STATIC_LINKING_ONLY
77# define XXH_STATIC_LINKING_ONLY
78# endif
79# if defined(__GNUC__)
80# define XXH_PUBLIC_API static __inline __attribute__((unused))
81# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
82# define XXH_PUBLIC_API static inline
83# elif defined(_MSC_VER)
84# define XXH_PUBLIC_API static __inline
85# else
86# define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */
87# endif
88#else
89# define XXH_PUBLIC_API /* do nothing */
90#endif /* XXH_PRIVATE_API */
91
103#ifdef XXH_NAMESPACE
104# define XXH_CAT(A,B) A##B
105# define XXH_NAME2(A,B) XXH_CAT(A,B)
106# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
107# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
108# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
109# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
110# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
111# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
112# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
113# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
114# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
115# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
116# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
117# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
118# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
119# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
120# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
121# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
122# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
123# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
124# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
125#endif
126
127
128/* *************************************
129* Version
130***************************************/
131#define XXH_VERSION_MAJOR 0
132#define XXH_VERSION_MINOR 6
133#define XXH_VERSION_RELEASE 2
134#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
135XXH_PUBLIC_API unsigned XXH_versionNumber (void);
136
137
138/* ****************************
139* Simple Hash Functions
140******************************/
141typedef unsigned int XXH32_hash_t;
142typedef unsigned long long XXH64_hash_t;
143
144XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
145XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
146
160/* ****************************
161* Streaming Hash Functions
162******************************/
163typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
164typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
165
168XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
169XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
170
171XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
172XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
173
174
175/* hash streaming */
176
177XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed);
178XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
179XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr);
180
181XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
182XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
183XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
184
185/*
186These functions generate the xxHash of an input provided in multiple segments.
187Note that, for small input, they are slower than single-call functions, due to state management.
188For small input, prefer `XXH32()` and `XXH64()` .
189
190XXH state must first be allocated, using XXH*_createState() .
191
192Start a new hash by initializing state with a seed, using XXH*_reset().
193
194Then, feed the hash state by calling XXH*_update() as many times as necessary.
195Obviously, input must be allocated and read accessible.
196The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
197
198Finally, a hash value can be produced anytime, by using XXH*_digest().
199This function returns the nn-bits hash as an int or long long.
200
201It's still possible to continue inserting input into the hash state after a digest,
202and generate some new hashes later on, by calling again XXH*_digest().
203
204When done, free XXH state space if it was allocated dynamically.
205*/
206
207
208/* **************************
209* Utils
210****************************/
211#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* ! C99 */
212# define restrict /* disable restrict */
213#endif
214
215XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state);
216XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state);
217
218
219/* **************************
220* Canonical representation
221****************************/
222/* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
223* The canonical representation uses human-readable write convention, aka big-endian (large digits first).
224* These functions allow transformation of hash result into and from its canonical format.
225* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
226*/
227typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
228typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
229
230XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash);
231XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
232
233XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
234XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
235
236#endif /* XXHASH_H_5627135585666179 */
237
238
239
240/* ================================================================================================
241 This section contains definitions which are not guaranteed to remain stable.
242 They may change in future versions, becoming incompatible with a different version of the library.
243 They shall only be used with static linking.
244 Never use these definitions in association with dynamic linking !
245=================================================================================================== */
246#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345)
247#define XXH_STATIC_H_3543687687345
248
249/* These definitions are only meant to allow allocation of XXH state
250 statically, on stack, or in a struct for example.
251 Do not use members directly. */
252
253 struct XXH32_state_s {
254 uint32_t total_len_32;
255 uint32_t large_len;
256 uint32_t v1;
257 uint32_t v2;
258 uint32_t v3;
259 uint32_t v4;
260 uint32_t mem32[4]; /* buffer defined as U32 for alignment */
261 uint32_t memsize;
262 uint32_t reserved; /* never read nor write, will be removed in a future version */
263 }; /* typedef'd to XXH32_state_t */
264
265 struct XXH64_state_s {
266 uint64_t total_len;
267 uint64_t v1;
268 uint64_t v2;
269 uint64_t v3;
270 uint64_t v4;
271 uint64_t mem64[4]; /* buffer defined as U64 for alignment */
272 unsigned memsize;
273 unsigned reserved[2]; /* never read nor write, will be removed in a future version */
274 }; /* typedef'd to XXH64_state_t */
275
276
277# ifdef XXH_PRIVATE_API
278# include "xxhash.c" /* include xxhash functions as `static`, for inlining */
279# endif
280
281#endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */
282
283
284#if defined (__cplusplus)
285}
286#endif