Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
xxhash.h
Go to the documentation of this file.
1/*
2 xxHash - Extremely Fast Hash algorithm
3 Header File
4 Copyright (C) 2012-2016, Yann Collet.
5
6 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
10 met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following disclaimer
16 in the documentation and/or other materials provided with the
17 distribution.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 You can contact the author at :
32 - xxHash source repository : https://github.com/Cyan4973/xxHash
33*/
34
35/* Notice extracted from xxHash homepage :
36
37xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
38It also successfully passes all tests from the SMHasher suite.
39
40Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
41
42Name Speed Q.Score Author
43xxHash 5.4 GB/s 10
44CrapWow 3.2 GB/s 2 Andrew
45MumurHash 3a 2.7 GB/s 10 Austin Appleby
46SpookyHash 2.0 GB/s 10 Bob Jenkins
47SBox 1.4 GB/s 9 Bret Mulvey
48Lookup3 1.2 GB/s 9 Bob Jenkins
49SuperFastHash 1.2 GB/s 1 Paul Hsieh
50CityHash64 1.05 GB/s 10 Pike & Alakuijala
51FNV 0.55 GB/s 5 Fowler, Noll, Vo
52CRC32 0.43 GB/s 9
53MD5-32 0.33 GB/s 10 Ronald L. Rivest
54SHA1-32 0.28 GB/s 10
55
56Q.Score is a measure of quality of the hash function.
57It depends on successfully passing SMHasher test set.
5810 is a perfect score.
59
60A 64-bits version, named XXH64, is available since r35.
61It offers much better speed, but for 64-bits applications only.
62Name Speed on 64 bits Speed on 32 bits
63XXH64 13.8 GB/s 1.9 GB/s
64XXH32 6.8 GB/s 6.0 GB/s
65*/
66
67#ifndef XXHASH_H_5627135585666179
68#define XXHASH_H_5627135585666179 1
69
70#if defined (__cplusplus)
71extern "C" {
72#endif
73
74
75/* ****************************
76* Definitions
77******************************/
78#include <stddef.h> /* size_t */
79typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
80
81
82/* ****************************
83* API modifier
84******************************/
94#ifdef XXH_PRIVATE_API
95# ifndef XXH_STATIC_LINKING_ONLY
96# define XXH_STATIC_LINKING_ONLY
97# endif
98# if defined(__GNUC__)
99# define XXH_PUBLIC_API static __inline __attribute__((unused))
100# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
101# define XXH_PUBLIC_API static inline
102# elif defined(_MSC_VER)
103# define XXH_PUBLIC_API static __inline
104# else
105# define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */
106# endif
107#else
108# define XXH_PUBLIC_API /* do nothing */
109#endif /* XXH_PRIVATE_API */
110
122#ifdef XXH_NAMESPACE
123# define XXH_CAT(A,B) A##B
124# define XXH_NAME2(A,B) XXH_CAT(A,B)
125# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
126# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
127# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
128# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
129# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
130# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
131# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
132# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
133# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
134# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
135# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
136# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
137# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
138# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
139# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
140# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
141# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
142# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
143# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
144#endif
145
146
147/* *************************************
148* Version
149***************************************/
150#define XXH_VERSION_MAJOR 0
151#define XXH_VERSION_MINOR 6
152#define XXH_VERSION_RELEASE 2
153#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
154XXH_PUBLIC_API unsigned XXH_versionNumber (void);
155
156
157/*-**********************************************************************
158* 32-bits hash
159************************************************************************/
160typedef unsigned int XXH32_hash_t;
161
167XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
168
169/*====== Streaming ======*/
170typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
173XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dst_state, const XXH32_state_t* src_state);
174
175XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed);
176XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
178
179/*
180These functions generate the xxHash of an input provided in multiple segments.
181Note that, for small input, they are slower than single-call functions, due to state management.
182For small input, prefer `XXH32()` and `XXH64()` .
183
184XXH state must first be allocated, using XXH*_createState() .
185
186Start a new hash by initializing state with a seed, using XXH*_reset().
187
188Then, feed the hash state by calling XXH*_update() as many times as necessary.
189Obviously, input must be allocated and read accessible.
190The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
191
192Finally, a hash value can be produced anytime, by using XXH*_digest().
193This function returns the nn-bits hash as an int or long long.
194
195It's still possible to continue inserting input into the hash state after a digest,
196and generate some new hashes later on, by calling again XXH*_digest().
197
198When done, free XXH state space if it was allocated dynamically.
199*/
200
201/*====== Canonical representation ======*/
202
203typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
206
207/* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
208* The canonical representation uses human-readable write convention, aka big-endian (large digits first).
209* These functions allow transformation of hash result into and from its canonical format.
210* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
211*/
212
213
214#ifndef XXH_NO_LONG_LONG
215/*-**********************************************************************
216* 64-bits hash
217************************************************************************/
218typedef unsigned long long XXH64_hash_t;
219
225XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
226
227/*====== Streaming ======*/
228typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
231XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dst_state, const XXH64_state_t* src_state);
232
233XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
234XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
236
237/*====== Canonical representation ======*/
238typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
241#endif /* XXH_NO_LONG_LONG */
242
243
244#ifdef XXH_STATIC_LINKING_ONLY
245
246/* ================================================================================================
247 This section contains definitions which are not guaranteed to remain stable.
248 They may change in future versions, becoming incompatible with a different version of the library.
249 They shall only be used with static linking.
250 Never use these definitions in association with dynamic linking !
251=================================================================================================== */
252
253/* These definitions are only meant to make possible
254 static allocation of XXH state, on stack or in a struct for example.
255 Never use members directly. */
256
257struct XXH32_state_s {
258 unsigned total_len_32;
259 unsigned large_len;
260 unsigned v1;
261 unsigned v2;
262 unsigned v3;
263 unsigned v4;
264 unsigned mem32[4]; /* buffer defined as U32 for alignment */
265 unsigned memsize;
266 unsigned reserved; /* never read nor write, will be removed in a future version */
267}; /* typedef'd to XXH32_state_t */
268
269#ifndef XXH_NO_LONG_LONG /* remove 64-bits support */
270struct XXH64_state_s {
271 unsigned long long total_len;
272 unsigned long long v1;
273 unsigned long long v2;
274 unsigned long long v3;
275 unsigned long long v4;
276 unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
277 unsigned memsize;
278 unsigned reserved[2]; /* never read nor write, will be removed in a future version */
279}; /* typedef'd to XXH64_state_t */
280#endif
281
282#ifdef XXH_PRIVATE_API
283# include "xxhash.c" /* include xxhash function bodies as `static`, for inlining */
284#endif
285
286#endif /* XXH_STATIC_LINKING_ONLY */
287
288
289#if defined (__cplusplus)
290}
291#endif
292
293#endif /* XXHASH_H_5627135585666179 */
#define reserved
Definition pkcs11.h:187
struct XXH32_state_s XXH32_state_t
Definition xxhash.h:170
struct XXH64_state_s XXH64_state_t
Definition xxhash.h:228
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t *src)
Definition xxhash.c:510
XXH_PUBLIC_API XXH32_hash_t XXH32_digest(const XXH32_state_t *statePtr)
Definition xxhash.c:484
unsigned long long XXH64_hash_t
Definition xxhash.h:218
XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t *dst_state, const XXH64_state_t *src_state)
Definition xxhash.c:730
XXH_errorcode
Definition xxhash.h:79
@ XXH_ERROR
Definition xxhash.h:79
@ XXH_OK
Definition xxhash.h:79
XXH_PUBLIC_API XXH32_state_t * XXH32_createState(void)
Definition xxhash.c:350
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *statePtr, const void *input, size_t length)
Definition xxhash.c:802
#define XXH_PUBLIC_API
Definition xxhash.h:108
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition xxhash.c:365
XXH_PUBLIC_API XXH64_hash_t XXH64(const void *input, size_t length, unsigned long long seed)
Definition xxhash.c:692
XXH_PUBLIC_API XXH64_state_t * XXH64_createState(void)
Definition xxhash.c:720
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition xxhash.c:735
XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t *dst_state, const XXH32_state_t *src_state)
Definition xxhash.c:360
XXH_PUBLIC_API XXH32_hash_t XXH32(const void *input, size_t length, unsigned int seed)
Definition xxhash.c:320
XXH_PUBLIC_API XXH64_hash_t XXH64_digest(const XXH64_state_t *statePtr)
Definition xxhash.c:863
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t *statePtr)
Definition xxhash.c:354
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *statePtr, const void *input, size_t length)
Definition xxhash.c:436
unsigned int XXH32_hash_t
Definition xxhash.h:160
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t *src)
Definition xxhash.c:883
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t *dst, XXH32_hash_t hash)
Definition xxhash.c:503
XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t *statePtr)
Definition xxhash.c:724
XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t *dst, XXH64_hash_t hash)
Definition xxhash.c:876
XXH_PUBLIC_API unsigned XXH_versionNumber(void)
Definition xxhash.c:243