Hashes.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #pragma once
  2. #include "Types.h"
  3. #include "MurmurHash1.h"
  4. #include "MurmurHash2.h"
  5. #include "MurmurHash3.h"
  6. #if defined(__x86_64__)
  7. #include "xxhash.h"
  8. #include "metrohash.h"
  9. #include "cmetrohash.h"
  10. #include "opt_cmetrohash.h"
  11. #endif
  12. #include "fasthash.h"
  13. //jodyhash
  14. void jodyhash ( const void * key, int len, uint32_t seed, void * out );
  15. //----------
  16. // These are _not_ hash functions (even though people tend to use crc32 as one...)
  17. void BadHash ( const void * key, int len, uint32_t seed, void * out );
  18. void sumhash ( const void * key, int len, uint32_t seed, void * out );
  19. void sumhash32 ( const void * key, int len, uint32_t seed, void * out );
  20. void DoNothingHash ( const void * key, int len, uint32_t seed, void * out );
  21. void NoopOAATReadHash ( const void * key, int len, uint32_t seed, void * out );
  22. void crc32 ( const void * key, int len, uint32_t seed, void * out );
  23. void randhash_32 ( const void * key, int len, uint32_t seed, void * out );
  24. void randhash_64 ( const void * key, int len, uint32_t seed, void * out );
  25. void randhash_128 ( const void * key, int len, uint32_t seed, void * out );
  26. //----------
  27. // Cryptographic hashes
  28. void md5_32 ( const void * key, int len, uint32_t seed, void * out );
  29. void sha1_32a ( const void * key, int len, uint32_t seed, void * out );
  30. #if 0
  31. void sha1_64a ( const void * key, int len, uint32_t seed, void * out );
  32. void sha2_32a ( const void * key, int len, uint32_t seed, void * out );
  33. void sha2_64a ( const void * key, int len, uint32_t seed, void * out );
  34. void BLAKE2_32a ( const void * key, int len, uint32_t seed, void * out );
  35. void BLAKE2_64a ( const void * key, int len, uint32_t seed, void * out );
  36. void bcrypt_64a ( const void * key, int len, uint32_t seed, void * out );
  37. void scrypt_64a ( const void * key, int len, uint32_t seed, void * out );
  38. #endif
  39. //----------
  40. // General purpose hashes
  41. #ifdef __SSE2__
  42. void hasshe2_test ( const void * key, int len, uint32_t seed, void * out );
  43. #endif
  44. #if defined(__SSE4_2__) && defined(__x86_64__)
  45. void crc32c_hw_test ( const void * key, int len, uint32_t seed, void * out );
  46. void crc32c_hw1_test ( const void * key, int len, uint32_t seed, void * out );
  47. void crc64c_hw_test ( const void * key, int len, uint32_t seed, void * out );
  48. void CityHashCrc64_test ( const void * key, int len, uint32_t seed, void * out );
  49. void CityHashCrc128_test ( const void * key, int len, uint32_t seed, void * out );
  50. void falkhash_test_cxx ( const void * key, int len, uint32_t seed, void * out );
  51. #endif
  52. void FNV32a ( const void * key, int len, uint32_t seed, void * out );
  53. void FNV32a_YoshimitsuTRIAD( const void * key, int len, uint32_t seed, void * out );
  54. void FNV64a ( const void * key, int len, uint32_t seed, void * out );
  55. void Bernstein ( const void * key, int len, uint32_t seed, void * out );
  56. void sdbm ( const void * key, int len, uint32_t seed, void * out );
  57. void x17_test ( const void * key, int len, uint32_t seed, void * out );
  58. void JenkinsOOAT ( const void * key, int len, uint32_t seed, void * out );
  59. void JenkinsOOAT_perl ( const void * key, int len, uint32_t seed, void * out );
  60. void GoodOAAT ( const void * key, int len, uint32_t seed, void * out );
  61. void MicroOAAT ( const void * key, int len, uint32_t seed, void * out );
  62. void SuperFastHash ( const void * key, int len, uint32_t seed, void * out );
  63. void lookup3_test ( const void * key, int len, uint32_t seed, void * out );
  64. void MurmurOAAT_test ( const void * key, int len, uint32_t seed, void * out );
  65. void Crap8_test ( const void * key, int len, uint32_t seed, void * out );
  66. void CityHash32_test ( const void * key, int len, uint32_t seed, void * out );
  67. void CityHash64_test ( const void * key, int len, uint32_t seed, void * out );
  68. void CityHash128_test ( const void * key, int len, uint32_t seed, void * out );
  69. void FarmHash32_test ( const void * key, int len, uint32_t seed, void * out );
  70. void FarmHash64_test ( const void * key, int len, uint32_t seed, void * out );
  71. void FarmHash128_test ( const void * key, int len, uint32_t seed, void * out );
  72. void farmhash32_c_test ( const void * key, int len, uint32_t seed, void * out );
  73. void farmhash64_c_test ( const void * key, int len, uint32_t seed, void * out );
  74. void farmhash128_c_test ( const void * key, int len, uint32_t seed, void * out );
  75. void SpookyHash32_test ( const void * key, int len, uint32_t seed, void * out );
  76. void SpookyHash64_test ( const void * key, int len, uint32_t seed, void * out );
  77. void SpookyHash128_test ( const void * key, int len, uint32_t seed, void * out );
  78. uint32_t MurmurOAAT ( const void * key, int len, uint32_t seed );
  79. //----------
  80. // MurmurHash2
  81. void MurmurHash2_test ( const void * key, int len, uint32_t seed, void * out );
  82. void MurmurHash2A_test ( const void * key, int len, uint32_t seed, void * out );
  83. void siphash_test ( const void * key, int len, uint32_t seed, void * out );
  84. void siphash13_test ( const void * key, int len, uint32_t seed, void * out );
  85. void halfsiphash_test ( const void * key, int len, uint32_t seed, void * out );
  86. //-----------------------------------------------------------------------------
  87. // Test harnesses for Murmur1/2
  88. inline void MurmurHash1_test ( const void * key, int len, uint32_t seed, void * out )
  89. {
  90. *(uint32_t*)out = MurmurHash1(key,len,seed);
  91. }
  92. inline void MurmurHash2_test ( const void * key, int len, uint32_t seed, void * out )
  93. {
  94. *(uint32_t*)out = MurmurHash2(key,len,seed);
  95. }
  96. inline void MurmurHash2A_test ( const void * key, int len, uint32_t seed, void * out )
  97. {
  98. *(uint32_t*)out = MurmurHash2A(key,len,seed);
  99. }
  100. inline void MurmurHash64A_test ( const void * key, int len, uint32_t seed, void * out )
  101. {
  102. *(uint64_t*)out = MurmurHash64A(key,len,seed);
  103. }
  104. inline void MurmurHash64B_test ( const void * key, int len, uint32_t seed, void * out )
  105. {
  106. *(uint64_t*)out = MurmurHash64B(key,len,seed);
  107. }
  108. #if defined(__x86_64__)
  109. inline void xxHash32_test( const void * key, int len, uint32_t seed, void * out ) {
  110. *(uint32_t*)out = (uint32_t) XXH32(key, (size_t) len, (unsigned) seed);
  111. }
  112. inline void xxHash64_test( const void * key, int len, uint32_t seed, void * out ) {
  113. *(uint64_t*)out = (uint64_t) XXH64(key, (size_t) len, (unsigned long long) seed);
  114. }
  115. inline void metrohash64_1_test ( const void * key, int len, uint32_t seed, void * out ) {
  116. metrohash64_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  117. }
  118. inline void metrohash64_2_test ( const void * key, int len, uint32_t seed, void * out ) {
  119. metrohash64_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  120. }
  121. inline void metrohash128_1_test ( const void * key, int len, uint32_t seed, void * out ) {
  122. metrohash128_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  123. }
  124. inline void metrohash128_2_test ( const void * key, int len, uint32_t seed, void * out ) {
  125. metrohash128_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  126. }
  127. #if defined(__SSE4_2__) && defined(__x86_64__)
  128. inline void metrohash64crc_1_test ( const void * key, int len, uint32_t seed, void * out ) {
  129. metrohash64crc_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  130. }
  131. inline void metrohash64crc_2_test ( const void * key, int len, uint32_t seed, void * out ) {
  132. metrohash64crc_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  133. }
  134. inline void metrohash128crc_1_test ( const void * key, int len, uint32_t seed, void * out ) {
  135. metrohash128crc_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  136. }
  137. inline void metrohash128crc_2_test ( const void * key, int len, uint32_t seed, void * out ) {
  138. metrohash128crc_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  139. }
  140. #endif
  141. inline void cmetrohash64_1_test ( const void * key, int len, uint32_t seed, void * out ) {
  142. cmetrohash64_1((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  143. }
  144. inline void cmetrohash64_1_optshort_test ( const void * key, int len, uint32_t seed, void * out ) {
  145. cmetrohash64_1_optshort((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  146. }
  147. inline void cmetrohash64_2_test ( const void * key, int len, uint32_t seed, void * out ) {
  148. cmetrohash64_2((const uint8_t *)key,(uint64_t)len,seed,(uint8_t *)out);
  149. }
  150. inline void fasthash32_test ( const void * key, int len, uint32_t seed, void * out ) {
  151. *(uint32_t*)out = fasthash32(key, (size_t) len, seed);
  152. }
  153. inline void fasthash64_test ( const void * key, int len, uint32_t seed, void * out ) {
  154. *(uint64_t*)out = fasthash64(key, (size_t) len, (uint64_t)seed);
  155. }
  156. #endif
  157. //-----------------------------------------------------------------------------
  158. #include "t1ha.h"
  159. inline void t1ha_test(const void * key, int len, uint32_t seed, void * out)
  160. {
  161. *(uint64_t*)out = t1ha(key, len, seed);
  162. }
  163. void mum_hash_test(const void * key, int len, uint32_t seed, void * out);
  164. #if (defined(__SSE4_2__) && defined(__x86_64__)) || defined(_M_X64)
  165. inline void t1ha_crc_test(const void * key, int len, uint32_t seed, void * out)
  166. {
  167. *(uint64_t*)out = t1ha_ia32crc(key, len, seed);
  168. }
  169. #endif
  170. inline void t1ha_64be_test(const void * key, int len, uint32_t seed, void * out)
  171. {
  172. *(uint64_t*)out = t1ha_64be(key, len, seed);
  173. }
  174. inline void t1ha_32le_test(const void * key, int len, uint32_t seed, void * out)
  175. {
  176. *(uint64_t*)out = t1ha_32le(key, len, seed);
  177. }
  178. inline void t1ha_32be_test(const void * key, int len, uint32_t seed, void * out)
  179. {
  180. *(uint64_t*)out = t1ha_32be(key, len, seed);
  181. }
  182. #if defined(__AES__) || defined(_M_X64) || defined(_M_IX86)
  183. inline void t1ha_aes_test(const void * key, int len, uint32_t seed, void * out)
  184. {
  185. *(uint64_t*)out = t1ha_ia32aes(key, len, seed);
  186. }
  187. #endif