xxhash.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #include <contrib/libs/zstd06/renames.h>
  2. /*
  3. xxHash - Extremely Fast Hash algorithm
  4. Header File
  5. Copyright (C) 2012-2016, Yann Collet.
  6. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are
  9. met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the following disclaimer
  14. in the documentation and/or other materials provided with the
  15. distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. You can contact the author at :
  28. - xxHash source repository : https://github.com/Cyan4973/xxHash
  29. */
  30. /* Notice extracted from xxHash homepage :
  31. xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
  32. It also successfully passes all tests from the SMHasher suite.
  33. Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
  34. Name Speed Q.Score Author
  35. xxHash 5.4 GB/s 10
  36. CrapWow 3.2 GB/s 2 Andrew
  37. MumurHash 3a 2.7 GB/s 10 Austin Appleby
  38. SpookyHash 2.0 GB/s 10 Bob Jenkins
  39. SBox 1.4 GB/s 9 Bret Mulvey
  40. Lookup3 1.2 GB/s 9 Bob Jenkins
  41. SuperFastHash 1.2 GB/s 1 Paul Hsieh
  42. CityHash64 1.05 GB/s 10 Pike & Alakuijala
  43. FNV 0.55 GB/s 5 Fowler, Noll, Vo
  44. CRC32 0.43 GB/s 9
  45. MD5-32 0.33 GB/s 10 Ronald L. Rivest
  46. SHA1-32 0.28 GB/s 10
  47. Q.Score is a measure of quality of the hash function.
  48. It depends on successfully passing SMHasher test set.
  49. 10 is a perfect score.
  50. A 64-bits version, named XXH64, is available since r35.
  51. It offers much better speed, but for 64-bits applications only.
  52. Name Speed on 64 bits Speed on 32 bits
  53. XXH64 13.8 GB/s 1.9 GB/s
  54. XXH32 6.8 GB/s 6.0 GB/s
  55. */
  56. #ifndef XXHASH_H_5627135585666179
  57. #define XXHASH_H_5627135585666179 1
  58. #if defined (__cplusplus)
  59. extern "C" {
  60. #endif
  61. /* ****************************
  62. * Definitions
  63. ******************************/
  64. #include <stddef.h> /* size_t */
  65. typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
  66. /* ****************************
  67. * API modifier
  68. ******************************/
  69. /*!XXH_PRIVATE_API
  70. * Transforms all publics symbols within `xxhash.c` into private ones.
  71. * Methodology :
  72. * instead of : #include "xxhash.h"
  73. * do :
  74. * #define XXH_PRIVATE_API
  75. * #include "xxhash.c" // note the .c , instead of .h
  76. * also : don't compile and link xxhash.c separately
  77. */
  78. #ifdef XXH_PRIVATE_API
  79. # if defined(__GNUC__)
  80. # define XXH_PUBLIC_API static __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
  91. /*!XXH_NAMESPACE, aka Namespace Emulation :
  92. If you want to include _and expose_ xxHash functions from within your own library,
  93. but also want to avoid symbol collisions with another library which also includes xxHash,
  94. you can use XXH_NAMESPACE, to automatically prefix any public symbol from `xxhash.c`
  95. with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values).
  96. Note that no change is required within the calling program as long as it also includes `xxhash.h` :
  97. regular symbol name will be automatically translated by this header.
  98. */
  99. #ifdef XXH_NAMESPACE
  100. # define XXH_CAT(A,B) A##B
  101. # define XXH_NAME2(A,B) XXH_CAT(A,B)
  102. # define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
  103. # define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
  104. # define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
  105. # define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
  106. # define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
  107. # define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
  108. # define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
  109. # define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
  110. # define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
  111. # define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
  112. # define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
  113. # define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
  114. # define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
  115. #endif
  116. /* *************************************
  117. * Version
  118. ***************************************/
  119. #define XXH_VERSION_MAJOR 0
  120. #define XXH_VERSION_MINOR 6
  121. #define XXH_VERSION_RELEASE 0
  122. #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
  123. XXH_PUBLIC_API unsigned XXH_versionNumber (void);
  124. /* ****************************
  125. * Simple Hash Functions
  126. ******************************/
  127. typedef unsigned int XXH32_hash_t;
  128. typedef unsigned long long XXH64_hash_t;
  129. XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
  130. XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
  131. /*!
  132. XXH32() :
  133. Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
  134. The memory between input & input+length must be valid (allocated and read-accessible).
  135. "seed" can be used to alter the result predictably.
  136. Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
  137. XXH64() :
  138. Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
  139. "seed" can be used to alter the result predictably.
  140. This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
  141. */
  142. /* ****************************
  143. * Streaming Hash Functions
  144. ******************************/
  145. typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
  146. typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
  147. /*! Dynamic allocation of states
  148. Compatible with dynamic libraries */
  149. XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
  150. XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
  151. XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
  152. XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
  153. /* hash streaming */
  154. XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed);
  155. XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
  156. XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr);
  157. XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
  158. XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
  159. XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
  160. /*!
  161. These functions generate the xxHash of an input provided in multiple segments,
  162. as opposed to provided as a single block.
  163. XXH state must first be allocated, using either static or dynamic method provided above.
  164. Start a new hash by initializing state with a seed, using XXHnn_reset().
  165. Then, feed the hash state by calling XXHnn_update() as many times as necessary.
  166. Obviously, input must be valid, hence allocated and read accessible.
  167. The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
  168. Finally, a hash value can be produced anytime, by using XXHnn_digest().
  169. This function returns the nn-bits hash as an int or long long.
  170. It's still possible to continue inserting input into the hash state after a digest,
  171. and later on generate some new hashes, by calling again XXHnn_digest().
  172. When done, free XXH state space if it was allocated dynamically.
  173. */
  174. /* **************************
  175. * Canonical representation
  176. ****************************/
  177. typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
  178. typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
  179. XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash);
  180. XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
  181. XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
  182. XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
  183. /*! Default result type for XXH functions are primitive unsigned 32 and 64 bits.
  184. * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
  185. * These functions allow transformation of hash result into and from its canonical format.
  186. * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
  187. */
  188. #ifdef XXH_STATIC_LINKING_ONLY
  189. /* This part contains definition which shall only be used with static linking.
  190. The prototypes / types defined here are not guaranteed to remain stable.
  191. They could change in a future version, becoming incompatible with a different version of the library */
  192. struct XXH32_state_s {
  193. unsigned long long total_len;
  194. unsigned seed;
  195. unsigned v1;
  196. unsigned v2;
  197. unsigned v3;
  198. unsigned v4;
  199. unsigned mem32[4]; /* buffer defined as U32 for alignment */
  200. unsigned memsize;
  201. }; /* typedef'd to XXH32_state_t */
  202. struct XXH64_state_s {
  203. unsigned long long total_len;
  204. unsigned long long seed;
  205. unsigned long long v1;
  206. unsigned long long v2;
  207. unsigned long long v3;
  208. unsigned long long v4;
  209. unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
  210. unsigned memsize;
  211. }; /* typedef'd to XXH64_state_t */
  212. #endif
  213. #if defined (__cplusplus)
  214. }
  215. #endif
  216. #endif /* XXHASH_H_5627135585666179 */