isomorfeus-ferret 0.12.6 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +101 -19
  3. data/README.md +85 -16
  4. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +22 -30
  5. data/ext/isomorfeus_ferret_ext/bm_hash.c +6 -12
  6. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +3 -6
  7. data/ext/isomorfeus_ferret_ext/bm_store.c +11 -22
  8. data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
  9. data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
  10. data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
  11. data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
  12. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
  13. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
  14. data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
  15. data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
  16. data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
  17. data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
  18. data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
  19. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
  20. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
  21. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
  22. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
  23. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
  24. data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
  25. data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
  26. data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
  27. data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
  28. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
  29. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
  30. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
  31. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
  32. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
  33. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
  34. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
  35. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
  36. data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
  37. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
  38. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
  39. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
  40. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
  41. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
  42. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
  43. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
  44. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
  45. data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
  46. data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
  47. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
  48. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
  49. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
  50. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
  51. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
  52. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
  53. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
  54. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
  55. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
  56. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
  57. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
  58. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
  59. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
  60. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
  61. data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
  62. data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
  63. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
  64. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
  65. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
  66. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
  67. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
  68. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
  69. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
  70. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
  71. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
  72. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
  73. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
  74. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
  75. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
  76. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
  77. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
  78. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
  79. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
  80. data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
  81. data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
  82. data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
  83. data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
  84. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
  85. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
  86. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
  87. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
  88. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
  89. data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
  90. data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
  91. data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
  92. data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
  93. data/ext/isomorfeus_ferret_ext/bzlib.c +1572 -0
  94. data/ext/isomorfeus_ferret_ext/bzlib.h +282 -0
  95. data/ext/isomorfeus_ferret_ext/bzlib_blocksort.c +1094 -0
  96. data/ext/isomorfeus_ferret_ext/bzlib_compress.c +672 -0
  97. data/ext/isomorfeus_ferret_ext/bzlib_crctable.c +104 -0
  98. data/ext/isomorfeus_ferret_ext/bzlib_decompress.c +652 -0
  99. data/ext/isomorfeus_ferret_ext/bzlib_huffman.c +205 -0
  100. data/ext/isomorfeus_ferret_ext/bzlib_private.h +509 -0
  101. data/ext/isomorfeus_ferret_ext/bzlib_randtable.c +84 -0
  102. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -53
  103. data/ext/isomorfeus_ferret_ext/frb_analysis.c +785 -1192
  104. data/ext/isomorfeus_ferret_ext/frb_index.c +513 -464
  105. data/ext/isomorfeus_ferret_ext/frb_qparser.c +48 -60
  106. data/ext/isomorfeus_ferret_ext/frb_search.c +1520 -1002
  107. data/ext/isomorfeus_ferret_ext/frb_store.c +96 -96
  108. data/ext/isomorfeus_ferret_ext/frb_threading.h +0 -1
  109. data/ext/isomorfeus_ferret_ext/frb_utils.c +147 -196
  110. data/ext/isomorfeus_ferret_ext/frt_analysis.c +695 -1090
  111. data/ext/isomorfeus_ferret_ext/frt_analysis.h +174 -170
  112. data/ext/isomorfeus_ferret_ext/frt_array.c +2 -4
  113. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +9 -16
  114. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +32 -81
  115. data/ext/isomorfeus_ferret_ext/frt_document.c +15 -20
  116. data/ext/isomorfeus_ferret_ext/frt_document.h +10 -9
  117. data/ext/isomorfeus_ferret_ext/frt_except.c +5 -12
  118. data/ext/isomorfeus_ferret_ext/frt_field_index.c +3 -3
  119. data/ext/isomorfeus_ferret_ext/frt_field_index.h +6 -7
  120. data/ext/isomorfeus_ferret_ext/frt_filter.c +35 -46
  121. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +2 -0
  122. data/ext/isomorfeus_ferret_ext/frt_global.c +91 -200
  123. data/ext/isomorfeus_ferret_ext/frt_global.h +7 -18
  124. data/ext/isomorfeus_ferret_ext/frt_hash.c +1 -2
  125. data/ext/isomorfeus_ferret_ext/frt_ind.c +32 -35
  126. data/ext/isomorfeus_ferret_ext/frt_ind.h +9 -9
  127. data/ext/isomorfeus_ferret_ext/frt_index.c +714 -384
  128. data/ext/isomorfeus_ferret_ext/frt_index.h +274 -290
  129. data/ext/isomorfeus_ferret_ext/frt_lang.c +0 -2
  130. data/ext/isomorfeus_ferret_ext/frt_mempool.c +1 -2
  131. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +4 -7
  132. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +68 -91
  133. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +35 -38
  134. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +53 -72
  135. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +25 -32
  136. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +21 -23
  137. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +66 -103
  138. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +207 -195
  139. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +20 -16
  140. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +17 -14
  141. data/ext/isomorfeus_ferret_ext/frt_q_range.c +102 -131
  142. data/ext/isomorfeus_ferret_ext/frt_q_span.c +179 -178
  143. data/ext/isomorfeus_ferret_ext/frt_q_term.c +47 -60
  144. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +18 -16
  145. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +46 -84
  146. data/ext/isomorfeus_ferret_ext/frt_search.c +105 -146
  147. data/ext/isomorfeus_ferret_ext/frt_search.h +331 -320
  148. data/ext/isomorfeus_ferret_ext/frt_similarity.c +5 -13
  149. data/ext/isomorfeus_ferret_ext/frt_similarity.h +7 -12
  150. data/ext/isomorfeus_ferret_ext/frt_sort.c +105 -149
  151. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -7
  152. data/ext/isomorfeus_ferret_ext/frt_store.h +10 -2
  153. data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -1
  154. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +22 -112
  155. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +2 -32
  156. data/ext/isomorfeus_ferret_ext/lz4.c +2495 -0
  157. data/ext/isomorfeus_ferret_ext/lz4.h +774 -0
  158. data/ext/isomorfeus_ferret_ext/lz4frame.c +1899 -0
  159. data/ext/isomorfeus_ferret_ext/lz4frame.h +623 -0
  160. data/ext/isomorfeus_ferret_ext/lz4hc.c +1615 -0
  161. data/ext/isomorfeus_ferret_ext/lz4hc.h +413 -0
  162. data/ext/isomorfeus_ferret_ext/lz4xxhash.c +1030 -0
  163. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +328 -0
  164. data/ext/isomorfeus_ferret_ext/stem_modules.h +0 -86
  165. data/ext/isomorfeus_ferret_ext/test.c +0 -17
  166. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -12
  167. data/ext/isomorfeus_ferret_ext/test_analysis.c +590 -583
  168. data/ext/isomorfeus_ferret_ext/test_compound_io.c +1 -1
  169. data/ext/isomorfeus_ferret_ext/test_document.c +19 -15
  170. data/ext/isomorfeus_ferret_ext/test_except.c +1 -2
  171. data/ext/isomorfeus_ferret_ext/test_fields.c +111 -100
  172. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +10 -27
  173. data/ext/isomorfeus_ferret_ext/test_filter.c +11 -8
  174. data/ext/isomorfeus_ferret_ext/test_global.c +0 -46
  175. data/ext/isomorfeus_ferret_ext/test_hash.c +2 -2
  176. data/ext/isomorfeus_ferret_ext/test_hashset.c +1 -1
  177. data/ext/isomorfeus_ferret_ext/test_highlighter.c +15 -11
  178. data/ext/isomorfeus_ferret_ext/test_index.c +373 -363
  179. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +5 -3
  180. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +5 -3
  181. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +13 -10
  182. data/ext/isomorfeus_ferret_ext/test_q_parser.c +45 -7
  183. data/ext/isomorfeus_ferret_ext/test_q_span.c +15 -12
  184. data/ext/isomorfeus_ferret_ext/test_ram_store.c +3 -3
  185. data/ext/isomorfeus_ferret_ext/test_search.c +60 -64
  186. data/ext/isomorfeus_ferret_ext/test_segments.c +5 -4
  187. data/ext/isomorfeus_ferret_ext/test_sort.c +17 -14
  188. data/ext/isomorfeus_ferret_ext/test_store.c +2 -0
  189. data/ext/isomorfeus_ferret_ext/test_term.c +3 -1
  190. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -10
  191. data/ext/isomorfeus_ferret_ext/test_test.c +1 -2
  192. data/ext/isomorfeus_ferret_ext/test_threading.c +9 -10
  193. data/ext/isomorfeus_ferret_ext/testhelper.c +1 -2
  194. data/lib/isomorfeus/ferret/version.rb +1 -1
  195. metadata +113 -58
  196. data/ext/isomorfeus_ferret_ext/email.rl +0 -21
  197. data/ext/isomorfeus_ferret_ext/frt_scanner.c +0 -900
  198. data/ext/isomorfeus_ferret_ext/frt_scanner.h +0 -28
  199. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +0 -6706
  200. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +0 -4420
  201. data/ext/isomorfeus_ferret_ext/scanner.h +0 -28
  202. data/ext/isomorfeus_ferret_ext/scanner.in +0 -43
  203. data/ext/isomorfeus_ferret_ext/scanner.rl +0 -84
  204. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +0 -200
  205. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +0 -85
  206. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +0 -1167
  207. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +0 -6
  208. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +0 -1433
  209. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +0 -6
  210. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +0 -301
  211. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +0 -6
  212. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +0 -590
  213. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +0 -6
  214. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +0 -1049
  215. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +0 -6
  216. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +0 -705
  217. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +0 -6
  218. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +0 -1239
  219. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +0 -6
  220. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +0 -477
  221. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +0 -6
  222. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +0 -1217
  223. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +0 -7
  224. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +0 -394
  225. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +0 -6
  226. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +0 -457
  227. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +0 -6
  228. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +0 -1009
  229. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +0 -6
  230. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +0 -259
  231. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +0 -6
  232. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +0 -704
  233. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +0 -6
  234. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +0 -948
  235. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +0 -6
  236. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +0 -1028
  237. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +0 -6
  238. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +0 -275
  239. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +0 -6
  240. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +0 -849
  241. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +0 -6
  242. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +0 -952
  243. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +0 -6
  244. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +0 -669
  245. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +0 -6
  246. data/ext/isomorfeus_ferret_ext/stem_modules.txt +0 -63
  247. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +0 -1854
  248. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +0 -1999
  249. data/ext/isomorfeus_ferret_ext/url.rl +0 -27
@@ -0,0 +1,1030 @@
1
+ /*
2
+ * xxHash - Fast Hash algorithm
3
+ * Copyright (C) 2012-2016, Yann Collet
4
+ *
5
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
+ *
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
+ *
11
+ * * Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above
14
+ * copyright notice, this list of conditions and the following disclaimer
15
+ * in the documentation and/or other materials provided with the
16
+ * distribution.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ *
30
+ * You can contact the author at :
31
+ * - xxHash homepage: http://www.xxhash.com
32
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
33
+ */
34
+
35
+
36
+ /* *************************************
37
+ * Tuning parameters
38
+ ***************************************/
39
+ /*!XXH_FORCE_MEMORY_ACCESS :
40
+ * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
41
+ * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
42
+ * The below switch allow to select different access method for improved performance.
43
+ * Method 0 (default) : use `memcpy()`. Safe and portable.
44
+ * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
45
+ * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
46
+ * Method 2 : direct access. This method doesn't depend on compiler but violate C standard.
47
+ * It can generate buggy code on targets which do not support unaligned memory accesses.
48
+ * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
49
+ * See http://stackoverflow.com/a/32095106/646947 for details.
50
+ * Prefer these methods in priority order (0 > 1 > 2)
51
+ */
52
+ #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
53
+ # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
54
+ || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
55
+ || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
56
+ # define XXH_FORCE_MEMORY_ACCESS 2
57
+ # elif (defined(__INTEL_COMPILER) && !defined(_WIN32)) || \
58
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
59
+ || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
60
+ || defined(__ARM_ARCH_7S__) ))
61
+ # define XXH_FORCE_MEMORY_ACCESS 1
62
+ # endif
63
+ #endif
64
+
65
+ /*!XXH_ACCEPT_NULL_INPUT_POINTER :
66
+ * If input pointer is NULL, xxHash default behavior is to dereference it, triggering a segfault.
67
+ * When this macro is enabled, xxHash actively checks input for null pointer.
68
+ * It it is, result for null input pointers is the same as a null-length input.
69
+ */
70
+ #ifndef XXH_ACCEPT_NULL_INPUT_POINTER /* can be defined externally */
71
+ # define XXH_ACCEPT_NULL_INPUT_POINTER 0
72
+ #endif
73
+
74
+ /*!XXH_FORCE_NATIVE_FORMAT :
75
+ * By default, xxHash library provides endian-independent Hash values, based on little-endian convention.
76
+ * Results are therefore identical for little-endian and big-endian CPU.
77
+ * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
78
+ * Should endian-independence be of no importance for your application, you may set the #define below to 1,
79
+ * to improve speed for Big-endian CPU.
80
+ * This option has no impact on Little_Endian CPU.
81
+ */
82
+ #ifndef XXH_FORCE_NATIVE_FORMAT /* can be defined externally */
83
+ # define XXH_FORCE_NATIVE_FORMAT 0
84
+ #endif
85
+
86
+ /*!XXH_FORCE_ALIGN_CHECK :
87
+ * This is a minor performance trick, only useful with lots of very small keys.
88
+ * It means : check for aligned/unaligned input.
89
+ * The check costs one initial branch per hash;
90
+ * set it to 0 when the input is guaranteed to be aligned,
91
+ * or when alignment doesn't matter for performance.
92
+ */
93
+ #ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */
94
+ # if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
95
+ # define XXH_FORCE_ALIGN_CHECK 0
96
+ # else
97
+ # define XXH_FORCE_ALIGN_CHECK 1
98
+ # endif
99
+ #endif
100
+
101
+
102
+ /* *************************************
103
+ * Includes & Memory related functions
104
+ ***************************************/
105
+ /*! Modify the local functions below should you wish to use some other memory routines
106
+ * for malloc(), free() */
107
+ #include <stdlib.h>
108
+ static void* XXH_malloc(size_t s) { return malloc(s); }
109
+ static void XXH_free (void* p) { free(p); }
110
+ /*! and for memcpy() */
111
+ #include <string.h>
112
+ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
113
+
114
+ #include <assert.h> /* assert */
115
+
116
+ #define XXH_STATIC_LINKING_ONLY
117
+ #include "lz4xxhash.h"
118
+
119
+
120
+ /* *************************************
121
+ * Compiler Specific Options
122
+ ***************************************/
123
+ #ifdef _MSC_VER /* Visual Studio */
124
+ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
125
+ # define FORCE_INLINE static __forceinline
126
+ #else
127
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
128
+ # ifdef __GNUC__
129
+ # define FORCE_INLINE static inline __attribute__((always_inline))
130
+ # else
131
+ # define FORCE_INLINE static inline
132
+ # endif
133
+ # else
134
+ # define FORCE_INLINE static
135
+ # endif /* __STDC_VERSION__ */
136
+ #endif
137
+
138
+
139
+ /* *************************************
140
+ * Basic Types
141
+ ***************************************/
142
+ #ifndef MEM_MODULE
143
+ # if !defined (__VMS) \
144
+ && (defined (__cplusplus) \
145
+ || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
146
+ # include <stdint.h>
147
+ typedef uint8_t BYTE;
148
+ typedef uint16_t U16;
149
+ typedef uint32_t U32;
150
+ # else
151
+ typedef unsigned char BYTE;
152
+ typedef unsigned short U16;
153
+ typedef unsigned int U32;
154
+ # endif
155
+ #endif
156
+
157
+ #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
158
+
159
+ /* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */
160
+ static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; }
161
+
162
+ #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
163
+
164
+ /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
165
+ /* currently only defined for gcc and icc */
166
+ typedef union { U32 u32; } __attribute__((packed)) unalign;
167
+ static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
168
+
169
+ #else
170
+
171
+ /* portable and safe solution. Generally efficient.
172
+ * see : http://stackoverflow.com/a/32095106/646947
173
+ */
174
+ static U32 XXH_read32(const void* memPtr)
175
+ {
176
+ U32 val;
177
+ memcpy(&val, memPtr, sizeof(val));
178
+ return val;
179
+ }
180
+
181
+ #endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
182
+
183
+
184
+ /* ****************************************
185
+ * Compiler-specific Functions and Macros
186
+ ******************************************/
187
+ #define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
188
+
189
+ /* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
190
+ #if defined(_MSC_VER)
191
+ # define XXH_rotl32(x,r) _rotl(x,r)
192
+ # define XXH_rotl64(x,r) _rotl64(x,r)
193
+ #else
194
+ # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
195
+ # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
196
+ #endif
197
+
198
+ #if defined(_MSC_VER) /* Visual Studio */
199
+ # define XXH_swap32 _byteswap_ulong
200
+ #elif XXH_GCC_VERSION >= 403
201
+ # define XXH_swap32 __builtin_bswap32
202
+ #else
203
+ static U32 XXH_swap32 (U32 x)
204
+ {
205
+ return ((x << 24) & 0xff000000 ) |
206
+ ((x << 8) & 0x00ff0000 ) |
207
+ ((x >> 8) & 0x0000ff00 ) |
208
+ ((x >> 24) & 0x000000ff );
209
+ }
210
+ #endif
211
+
212
+
213
+ /* *************************************
214
+ * Architecture Macros
215
+ ***************************************/
216
+ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
217
+
218
+ /* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example on the compiler command line */
219
+ #ifndef XXH_CPU_LITTLE_ENDIAN
220
+ static int XXH_isLittleEndian(void)
221
+ {
222
+ const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
223
+ return one.c[0];
224
+ }
225
+ # define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
226
+ #endif
227
+
228
+
229
+ /* ***************************
230
+ * Memory reads
231
+ *****************************/
232
+ typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
233
+
234
+ FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
235
+ {
236
+ if (align==XXH_unaligned)
237
+ return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
238
+ else
239
+ return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
240
+ }
241
+
242
+ FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
243
+ {
244
+ return XXH_readLE32_align(ptr, endian, XXH_unaligned);
245
+ }
246
+
247
+ static U32 XXH_readBE32(const void* ptr)
248
+ {
249
+ return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
250
+ }
251
+
252
+
253
+ /* *************************************
254
+ * Macros
255
+ ***************************************/
256
+ #define XXH_STATIC_ASSERT(c) { enum { XXH_sa = 1/(int)(!!(c)) }; } /* use after variable declarations */
257
+ XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
258
+
259
+
260
+ /* *******************************************************************
261
+ * 32-bit hash functions
262
+ *********************************************************************/
263
+ static const U32 PRIME32_1 = 2654435761U;
264
+ static const U32 PRIME32_2 = 2246822519U;
265
+ static const U32 PRIME32_3 = 3266489917U;
266
+ static const U32 PRIME32_4 = 668265263U;
267
+ static const U32 PRIME32_5 = 374761393U;
268
+
269
+ static U32 XXH32_round(U32 seed, U32 input)
270
+ {
271
+ seed += input * PRIME32_2;
272
+ seed = XXH_rotl32(seed, 13);
273
+ seed *= PRIME32_1;
274
+ return seed;
275
+ }
276
+
277
+ /* mix all bits */
278
+ static U32 XXH32_avalanche(U32 h32)
279
+ {
280
+ h32 ^= h32 >> 15;
281
+ h32 *= PRIME32_2;
282
+ h32 ^= h32 >> 13;
283
+ h32 *= PRIME32_3;
284
+ h32 ^= h32 >> 16;
285
+ return(h32);
286
+ }
287
+
288
+ #define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
289
+
290
+ static U32
291
+ XXH32_finalize(U32 h32, const void* ptr, size_t len,
292
+ XXH_endianess endian, XXH_alignment align)
293
+
294
+ {
295
+ const BYTE* p = (const BYTE*)ptr;
296
+
297
+ #define PROCESS1 \
298
+ h32 += (*p++) * PRIME32_5; \
299
+ h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
300
+
301
+ #define PROCESS4 \
302
+ h32 += XXH_get32bits(p) * PRIME32_3; \
303
+ p+=4; \
304
+ h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
305
+
306
+ switch(len&15) /* or switch(bEnd - p) */
307
+ {
308
+ case 12: PROCESS4;
309
+ /* fallthrough */
310
+ case 8: PROCESS4;
311
+ /* fallthrough */
312
+ case 4: PROCESS4;
313
+ return XXH32_avalanche(h32);
314
+
315
+ case 13: PROCESS4;
316
+ /* fallthrough */
317
+ case 9: PROCESS4;
318
+ /* fallthrough */
319
+ case 5: PROCESS4;
320
+ PROCESS1;
321
+ return XXH32_avalanche(h32);
322
+
323
+ case 14: PROCESS4;
324
+ /* fallthrough */
325
+ case 10: PROCESS4;
326
+ /* fallthrough */
327
+ case 6: PROCESS4;
328
+ PROCESS1;
329
+ PROCESS1;
330
+ return XXH32_avalanche(h32);
331
+
332
+ case 15: PROCESS4;
333
+ /* fallthrough */
334
+ case 11: PROCESS4;
335
+ /* fallthrough */
336
+ case 7: PROCESS4;
337
+ /* fallthrough */
338
+ case 3: PROCESS1;
339
+ /* fallthrough */
340
+ case 2: PROCESS1;
341
+ /* fallthrough */
342
+ case 1: PROCESS1;
343
+ /* fallthrough */
344
+ case 0: return XXH32_avalanche(h32);
345
+ }
346
+ assert(0);
347
+ return h32; /* reaching this point is deemed impossible */
348
+ }
349
+
350
+
351
+ FORCE_INLINE U32
352
+ XXH32_endian_align(const void* input, size_t len, U32 seed,
353
+ XXH_endianess endian, XXH_alignment align)
354
+ {
355
+ const BYTE* p = (const BYTE*)input;
356
+ const BYTE* bEnd = p + len;
357
+ U32 h32;
358
+
359
+ #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
360
+ if (p==NULL) {
361
+ len=0;
362
+ bEnd=p=(const BYTE*)(size_t)16;
363
+ }
364
+ #endif
365
+
366
+ if (len>=16) {
367
+ const BYTE* const limit = bEnd - 15;
368
+ U32 v1 = seed + PRIME32_1 + PRIME32_2;
369
+ U32 v2 = seed + PRIME32_2;
370
+ U32 v3 = seed + 0;
371
+ U32 v4 = seed - PRIME32_1;
372
+
373
+ do {
374
+ v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4;
375
+ v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4;
376
+ v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4;
377
+ v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4;
378
+ } while (p < limit);
379
+
380
+ h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7)
381
+ + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
382
+ } else {
383
+ h32 = seed + PRIME32_5;
384
+ }
385
+
386
+ h32 += (U32)len;
387
+
388
+ return XXH32_finalize(h32, p, len&15, endian, align);
389
+ }
390
+
391
+
392
+ XXH_PUBLIC_API unsigned int XXH32 (const void* input, size_t len, unsigned int seed)
393
+ {
394
+ #if 0
395
+ /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
396
+ XXH32_state_t state;
397
+ XXH32_reset(&state, seed);
398
+ XXH32_update(&state, input, len);
399
+ return XXH32_digest(&state);
400
+ #else
401
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
402
+
403
+ if (XXH_FORCE_ALIGN_CHECK) {
404
+ if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
405
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
406
+ return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
407
+ else
408
+ return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
409
+ } }
410
+
411
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
412
+ return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
413
+ else
414
+ return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
415
+ #endif
416
+ }
417
+
418
+
419
+
420
+ /*====== Hash streaming ======*/
421
+
422
+ XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void)
423
+ {
424
+ return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
425
+ }
426
+ XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
427
+ {
428
+ XXH_free(statePtr);
429
+ return XXH_OK;
430
+ }
431
+
432
+ XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dstState, const XXH32_state_t* srcState)
433
+ {
434
+ memcpy(dstState, srcState, sizeof(*dstState));
435
+ }
436
+
437
+ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
438
+ {
439
+ XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
440
+ memset(&state, 0, sizeof(state));
441
+ state.v1 = seed + PRIME32_1 + PRIME32_2;
442
+ state.v2 = seed + PRIME32_2;
443
+ state.v3 = seed + 0;
444
+ state.v4 = seed - PRIME32_1;
445
+ /* do not write into reserved, planned to be removed in a future version */
446
+ memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
447
+ return XXH_OK;
448
+ }
449
+
450
+
451
+ FORCE_INLINE XXH_errorcode
452
+ XXH32_update_endian(XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
453
+ {
454
+ if (input==NULL)
455
+ #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
456
+ return XXH_OK;
457
+ #else
458
+ return XXH_ERROR;
459
+ #endif
460
+
461
+ { const BYTE* p = (const BYTE*)input;
462
+ const BYTE* const bEnd = p + len;
463
+
464
+ state->total_len_32 += (unsigned)len;
465
+ state->large_len |= (len>=16) | (state->total_len_32>=16);
466
+
467
+ if (state->memsize + len < 16) { /* fill in tmp buffer */
468
+ XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
469
+ state->memsize += (unsigned)len;
470
+ return XXH_OK;
471
+ }
472
+
473
+ if (state->memsize) { /* some data left from previous update */
474
+ XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
475
+ { const U32* p32 = state->mem32;
476
+ state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++;
477
+ state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++;
478
+ state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++;
479
+ state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian));
480
+ }
481
+ p += 16-state->memsize;
482
+ state->memsize = 0;
483
+ }
484
+
485
+ if (p <= bEnd-16) {
486
+ const BYTE* const limit = bEnd - 16;
487
+ U32 v1 = state->v1;
488
+ U32 v2 = state->v2;
489
+ U32 v3 = state->v3;
490
+ U32 v4 = state->v4;
491
+
492
+ do {
493
+ v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4;
494
+ v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4;
495
+ v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4;
496
+ v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4;
497
+ } while (p<=limit);
498
+
499
+ state->v1 = v1;
500
+ state->v2 = v2;
501
+ state->v3 = v3;
502
+ state->v4 = v4;
503
+ }
504
+
505
+ if (p < bEnd) {
506
+ XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
507
+ state->memsize = (unsigned)(bEnd-p);
508
+ }
509
+ }
510
+
511
+ return XXH_OK;
512
+ }
513
+
514
+
515
+ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len)
516
+ {
517
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
518
+
519
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
520
+ return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
521
+ else
522
+ return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
523
+ }
524
+
525
+
526
+ FORCE_INLINE U32
527
+ XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
528
+ {
529
+ U32 h32;
530
+
531
+ if (state->large_len) {
532
+ h32 = XXH_rotl32(state->v1, 1)
533
+ + XXH_rotl32(state->v2, 7)
534
+ + XXH_rotl32(state->v3, 12)
535
+ + XXH_rotl32(state->v4, 18);
536
+ } else {
537
+ h32 = state->v3 /* == seed */ + PRIME32_5;
538
+ }
539
+
540
+ h32 += state->total_len_32;
541
+
542
+ return XXH32_finalize(h32, state->mem32, state->memsize, endian, XXH_aligned);
543
+ }
544
+
545
+
546
+ XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)
547
+ {
548
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
549
+
550
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
551
+ return XXH32_digest_endian(state_in, XXH_littleEndian);
552
+ else
553
+ return XXH32_digest_endian(state_in, XXH_bigEndian);
554
+ }
555
+
556
+
557
+ /*====== Canonical representation ======*/
558
+
559
+ /*! Default XXH result types are basic unsigned 32 and 64 bits.
560
+ * The canonical representation follows human-readable write convention, aka big-endian (large digits first).
561
+ * These functions allow transformation of hash result into and from its canonical format.
562
+ * This way, hash values can be written into a file or buffer, remaining comparable across different systems.
563
+ */
564
+
565
+ XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash)
566
+ {
567
+ XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
568
+ if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
569
+ memcpy(dst, &hash, sizeof(*dst));
570
+ }
571
+
572
+ XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src)
573
+ {
574
+ return XXH_readBE32(src);
575
+ }
576
+
577
+
578
+ #ifndef XXH_NO_LONG_LONG
579
+
580
+ /* *******************************************************************
581
+ * 64-bit hash functions
582
+ *********************************************************************/
583
+
584
+ /*====== Memory access ======*/
585
+
586
+ #ifndef MEM_MODULE
587
+ # define MEM_MODULE
588
+ # if !defined (__VMS) \
589
+ && (defined (__cplusplus) \
590
+ || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
591
+ # include <stdint.h>
592
+ typedef uint64_t U64;
593
+ # else
594
+ /* if compiler doesn't support unsigned long long, replace by another 64-bit type */
595
+ typedef unsigned long long U64;
596
+ # endif
597
+ #endif
598
+
599
+
600
+ #if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
601
+
602
+ /* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */
603
+ static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; }
604
+
605
+ #elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
606
+
607
+ /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
608
+ /* currently only defined for gcc and icc */
609
+ typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign64;
610
+ static U64 XXH_read64(const void* ptr) { return ((const unalign64*)ptr)->u64; }
611
+
612
+ #else
613
+
614
+ /* portable and safe solution. Generally efficient.
615
+ * see : http://stackoverflow.com/a/32095106/646947
616
+ */
617
+
618
+ static U64 XXH_read64(const void* memPtr)
619
+ {
620
+ U64 val;
621
+ memcpy(&val, memPtr, sizeof(val));
622
+ return val;
623
+ }
624
+
625
+ #endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
626
+
627
+ #if defined(_MSC_VER) /* Visual Studio */
628
+ # define XXH_swap64 _byteswap_uint64
629
+ #elif XXH_GCC_VERSION >= 403
630
+ # define XXH_swap64 __builtin_bswap64
631
+ #else
632
+ static U64 XXH_swap64 (U64 x)
633
+ {
634
+ return ((x << 56) & 0xff00000000000000ULL) |
635
+ ((x << 40) & 0x00ff000000000000ULL) |
636
+ ((x << 24) & 0x0000ff0000000000ULL) |
637
+ ((x << 8) & 0x000000ff00000000ULL) |
638
+ ((x >> 8) & 0x00000000ff000000ULL) |
639
+ ((x >> 24) & 0x0000000000ff0000ULL) |
640
+ ((x >> 40) & 0x000000000000ff00ULL) |
641
+ ((x >> 56) & 0x00000000000000ffULL);
642
+ }
643
+ #endif
644
+
645
+ FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
646
+ {
647
+ if (align==XXH_unaligned)
648
+ return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
649
+ else
650
+ return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
651
+ }
652
+
653
+ FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
654
+ {
655
+ return XXH_readLE64_align(ptr, endian, XXH_unaligned);
656
+ }
657
+
658
+ static U64 XXH_readBE64(const void* ptr)
659
+ {
660
+ return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr);
661
+ }
662
+
663
+
664
+ /*====== xxh64 ======*/
665
+
666
+ static const U64 PRIME64_1 = 11400714785074694791ULL;
667
+ static const U64 PRIME64_2 = 14029467366897019727ULL;
668
+ static const U64 PRIME64_3 = 1609587929392839161ULL;
669
+ static const U64 PRIME64_4 = 9650029242287828579ULL;
670
+ static const U64 PRIME64_5 = 2870177450012600261ULL;
671
+
672
+ static U64 XXH64_round(U64 acc, U64 input)
673
+ {
674
+ acc += input * PRIME64_2;
675
+ acc = XXH_rotl64(acc, 31);
676
+ acc *= PRIME64_1;
677
+ return acc;
678
+ }
679
+
680
+ static U64 XXH64_mergeRound(U64 acc, U64 val)
681
+ {
682
+ val = XXH64_round(0, val);
683
+ acc ^= val;
684
+ acc = acc * PRIME64_1 + PRIME64_4;
685
+ return acc;
686
+ }
687
+
688
+ static U64 XXH64_avalanche(U64 h64)
689
+ {
690
+ h64 ^= h64 >> 33;
691
+ h64 *= PRIME64_2;
692
+ h64 ^= h64 >> 29;
693
+ h64 *= PRIME64_3;
694
+ h64 ^= h64 >> 32;
695
+ return h64;
696
+ }
697
+
698
+
699
+ #define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
700
+
701
+ static U64
702
+ XXH64_finalize(U64 h64, const void* ptr, size_t len,
703
+ XXH_endianess endian, XXH_alignment align)
704
+ {
705
+ const BYTE* p = (const BYTE*)ptr;
706
+
707
+ #define PROCESS1_64 \
708
+ h64 ^= (*p++) * PRIME64_5; \
709
+ h64 = XXH_rotl64(h64, 11) * PRIME64_1;
710
+
711
+ #define PROCESS4_64 \
712
+ h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; \
713
+ p+=4; \
714
+ h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
715
+
716
+ #define PROCESS8_64 { \
717
+ U64 const k1 = XXH64_round(0, XXH_get64bits(p)); \
718
+ p+=8; \
719
+ h64 ^= k1; \
720
+ h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \
721
+ }
722
+
723
+ switch(len&31) {
724
+ case 24: PROCESS8_64;
725
+ /* fallthrough */
726
+ case 16: PROCESS8_64;
727
+ /* fallthrough */
728
+ case 8: PROCESS8_64;
729
+ return XXH64_avalanche(h64);
730
+
731
+ case 28: PROCESS8_64;
732
+ /* fallthrough */
733
+ case 20: PROCESS8_64;
734
+ /* fallthrough */
735
+ case 12: PROCESS8_64;
736
+ /* fallthrough */
737
+ case 4: PROCESS4_64;
738
+ return XXH64_avalanche(h64);
739
+
740
+ case 25: PROCESS8_64;
741
+ /* fallthrough */
742
+ case 17: PROCESS8_64;
743
+ /* fallthrough */
744
+ case 9: PROCESS8_64;
745
+ PROCESS1_64;
746
+ return XXH64_avalanche(h64);
747
+
748
+ case 29: PROCESS8_64;
749
+ /* fallthrough */
750
+ case 21: PROCESS8_64;
751
+ /* fallthrough */
752
+ case 13: PROCESS8_64;
753
+ /* fallthrough */
754
+ case 5: PROCESS4_64;
755
+ PROCESS1_64;
756
+ return XXH64_avalanche(h64);
757
+
758
+ case 26: PROCESS8_64;
759
+ /* fallthrough */
760
+ case 18: PROCESS8_64;
761
+ /* fallthrough */
762
+ case 10: PROCESS8_64;
763
+ PROCESS1_64;
764
+ PROCESS1_64;
765
+ return XXH64_avalanche(h64);
766
+
767
+ case 30: PROCESS8_64;
768
+ /* fallthrough */
769
+ case 22: PROCESS8_64;
770
+ /* fallthrough */
771
+ case 14: PROCESS8_64;
772
+ /* fallthrough */
773
+ case 6: PROCESS4_64;
774
+ PROCESS1_64;
775
+ PROCESS1_64;
776
+ return XXH64_avalanche(h64);
777
+
778
+ case 27: PROCESS8_64;
779
+ /* fallthrough */
780
+ case 19: PROCESS8_64;
781
+ /* fallthrough */
782
+ case 11: PROCESS8_64;
783
+ PROCESS1_64;
784
+ PROCESS1_64;
785
+ PROCESS1_64;
786
+ return XXH64_avalanche(h64);
787
+
788
+ case 31: PROCESS8_64;
789
+ /* fallthrough */
790
+ case 23: PROCESS8_64;
791
+ /* fallthrough */
792
+ case 15: PROCESS8_64;
793
+ /* fallthrough */
794
+ case 7: PROCESS4_64;
795
+ /* fallthrough */
796
+ case 3: PROCESS1_64;
797
+ /* fallthrough */
798
+ case 2: PROCESS1_64;
799
+ /* fallthrough */
800
+ case 1: PROCESS1_64;
801
+ /* fallthrough */
802
+ case 0: return XXH64_avalanche(h64);
803
+ }
804
+
805
+ /* impossible to reach */
806
+ assert(0);
807
+ return 0; /* unreachable, but some compilers complain without it */
808
+ }
809
+
810
+ FORCE_INLINE U64
811
+ XXH64_endian_align(const void* input, size_t len, U64 seed,
812
+ XXH_endianess endian, XXH_alignment align)
813
+ {
814
+ const BYTE* p = (const BYTE*)input;
815
+ const BYTE* bEnd = p + len;
816
+ U64 h64;
817
+
818
+ #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
819
+ if (p==NULL) {
820
+ len=0;
821
+ bEnd=p=(const BYTE*)(size_t)32;
822
+ }
823
+ #endif
824
+
825
+ if (len>=32) {
826
+ const BYTE* const limit = bEnd - 32;
827
+ U64 v1 = seed + PRIME64_1 + PRIME64_2;
828
+ U64 v2 = seed + PRIME64_2;
829
+ U64 v3 = seed + 0;
830
+ U64 v4 = seed - PRIME64_1;
831
+
832
+ do {
833
+ v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
834
+ v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
835
+ v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
836
+ v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
837
+ } while (p<=limit);
838
+
839
+ h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
840
+ h64 = XXH64_mergeRound(h64, v1);
841
+ h64 = XXH64_mergeRound(h64, v2);
842
+ h64 = XXH64_mergeRound(h64, v3);
843
+ h64 = XXH64_mergeRound(h64, v4);
844
+
845
+ } else {
846
+ h64 = seed + PRIME64_5;
847
+ }
848
+
849
+ h64 += (U64) len;
850
+
851
+ return XXH64_finalize(h64, p, len, endian, align);
852
+ }
853
+
854
+
855
+ XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed)
856
+ {
857
+ #if 0
858
+ /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
859
+ XXH64_state_t state;
860
+ XXH64_reset(&state, seed);
861
+ XXH64_update(&state, input, len);
862
+ return XXH64_digest(&state);
863
+ #else
864
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
865
+
866
+ if (XXH_FORCE_ALIGN_CHECK) {
867
+ if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
868
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
869
+ return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
870
+ else
871
+ return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
872
+ } }
873
+
874
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
875
+ return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
876
+ else
877
+ return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
878
+ #endif
879
+ }
880
+
881
+ /*====== Hash Streaming ======*/
882
+
883
+ XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void)
884
+ {
885
+ return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
886
+ }
887
+ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
888
+ {
889
+ XXH_free(statePtr);
890
+ return XXH_OK;
891
+ }
892
+
893
+ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dstState, const XXH64_state_t* srcState)
894
+ {
895
+ memcpy(dstState, srcState, sizeof(*dstState));
896
+ }
897
+
898
+ XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
899
+ {
900
+ XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
901
+ memset(&state, 0, sizeof(state));
902
+ state.v1 = seed + PRIME64_1 + PRIME64_2;
903
+ state.v2 = seed + PRIME64_2;
904
+ state.v3 = seed + 0;
905
+ state.v4 = seed - PRIME64_1;
906
+ /* do not write into reserved, planned to be removed in a future version */
907
+ memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
908
+ return XXH_OK;
909
+ }
910
+
911
+ FORCE_INLINE XXH_errorcode
912
+ XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
913
+ {
914
+ if (input==NULL)
915
+ #if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1)
916
+ return XXH_OK;
917
+ #else
918
+ return XXH_ERROR;
919
+ #endif
920
+
921
+ { const BYTE* p = (const BYTE*)input;
922
+ const BYTE* const bEnd = p + len;
923
+
924
+ state->total_len += len;
925
+
926
+ if (state->memsize + len < 32) { /* fill in tmp buffer */
927
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
928
+ state->memsize += (U32)len;
929
+ return XXH_OK;
930
+ }
931
+
932
+ if (state->memsize) { /* tmp buffer is full */
933
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
934
+ state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian));
935
+ state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian));
936
+ state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian));
937
+ state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian));
938
+ p += 32-state->memsize;
939
+ state->memsize = 0;
940
+ }
941
+
942
+ if (p+32 <= bEnd) {
943
+ const BYTE* const limit = bEnd - 32;
944
+ U64 v1 = state->v1;
945
+ U64 v2 = state->v2;
946
+ U64 v3 = state->v3;
947
+ U64 v4 = state->v4;
948
+
949
+ do {
950
+ v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8;
951
+ v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8;
952
+ v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8;
953
+ v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8;
954
+ } while (p<=limit);
955
+
956
+ state->v1 = v1;
957
+ state->v2 = v2;
958
+ state->v3 = v3;
959
+ state->v4 = v4;
960
+ }
961
+
962
+ if (p < bEnd) {
963
+ XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
964
+ state->memsize = (unsigned)(bEnd-p);
965
+ }
966
+ }
967
+
968
+ return XXH_OK;
969
+ }
970
+
971
+ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len)
972
+ {
973
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
974
+
975
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
976
+ return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
977
+ else
978
+ return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
979
+ }
980
+
981
+ FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
982
+ {
983
+ U64 h64;
984
+
985
+ if (state->total_len >= 32) {
986
+ U64 const v1 = state->v1;
987
+ U64 const v2 = state->v2;
988
+ U64 const v3 = state->v3;
989
+ U64 const v4 = state->v4;
990
+
991
+ h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
992
+ h64 = XXH64_mergeRound(h64, v1);
993
+ h64 = XXH64_mergeRound(h64, v2);
994
+ h64 = XXH64_mergeRound(h64, v3);
995
+ h64 = XXH64_mergeRound(h64, v4);
996
+ } else {
997
+ h64 = state->v3 /*seed*/ + PRIME64_5;
998
+ }
999
+
1000
+ h64 += (U64) state->total_len;
1001
+
1002
+ return XXH64_finalize(h64, state->mem64, (size_t)state->total_len, endian, XXH_aligned);
1003
+ }
1004
+
1005
+ XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t* state_in)
1006
+ {
1007
+ XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
1008
+
1009
+ if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
1010
+ return XXH64_digest_endian(state_in, XXH_littleEndian);
1011
+ else
1012
+ return XXH64_digest_endian(state_in, XXH_bigEndian);
1013
+ }
1014
+
1015
+
1016
+ /*====== Canonical representation ======*/
1017
+
1018
+ XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
1019
+ {
1020
+ XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
1021
+ if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
1022
+ memcpy(dst, &hash, sizeof(*dst));
1023
+ }
1024
+
1025
+ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src)
1026
+ {
1027
+ return XXH_readBE64(src);
1028
+ }
1029
+
1030
+ #endif /* XXH_NO_LONG_LONG */