multi_compress 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -3
  3. data/GET_STARTED.md +3 -3
  4. data/README.md +75 -66
  5. data/THIRD_PARTY_NOTICES.md +24 -0
  6. data/ext/multi_compress/brotli_dec_static_init.c +3 -0
  7. data/ext/multi_compress/brotli_enc_static_init.c +3 -0
  8. data/ext/multi_compress/extconf.rb +22 -1
  9. data/ext/multi_compress/multi_compress.c +152 -72
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
  13. data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
  14. data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
  15. data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
  16. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
  17. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
  18. data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
  20. data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
  21. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
  22. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  23. data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
  24. data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
  25. data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
  26. data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
  27. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
  28. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
  29. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
  30. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
  31. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
  32. data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
  33. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
  34. data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
  35. data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
  36. data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
  37. data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
  38. data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
  40. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
  41. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  42. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  43. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
  44. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
  45. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  46. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
  47. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
  48. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  49. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  50. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  51. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
  52. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
  53. data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
  54. data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
  55. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  56. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  57. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
  58. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
  59. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  60. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  61. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  62. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  63. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
  65. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
  66. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
  67. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
  68. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
  69. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  70. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
  71. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
  72. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
  73. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
  74. data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  76. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  77. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  79. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
  83. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
  84. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
  85. data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
  87. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
  88. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
  89. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
  90. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
  91. data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
  92. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
  93. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
  94. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
  95. data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
  96. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
  97. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
  98. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  99. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  100. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  101. data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
  102. data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
  103. data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
  104. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
  105. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
  106. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
  107. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
  108. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
  109. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
  110. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
  111. data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
  112. data/ext/multi_compress/vendor/zstd/COPYING +339 -0
  113. data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
  114. data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
  115. data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
  116. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  117. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
  118. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
  119. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
  120. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
  121. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
  122. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
  123. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
  124. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
  125. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
  126. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
  127. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
  128. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
  129. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
  130. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
  131. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
  132. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
  133. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
  134. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
  135. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
  136. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
  137. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
  138. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
  139. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
  140. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
  141. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
  142. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
  143. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
  144. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
  145. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
  146. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
  147. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
  148. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
  149. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
  150. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
  170. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
  171. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
  172. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
  178. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
  179. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
  180. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  182. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
  183. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
  184. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
  187. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
  188. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
  189. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
  190. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
  191. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
  192. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
  193. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
  194. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
  195. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
  204. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
  205. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
  206. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
  207. data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
  208. data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
  209. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
  210. data/lib/multi_compress/version.rb +1 -1
  211. metadata +29 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -11,10 +11,6 @@
11
11
  #ifndef ZSTD_LAZY_H
12
12
  #define ZSTD_LAZY_H
13
13
 
14
- #if defined (__cplusplus)
15
- extern "C" {
16
- #endif
17
-
18
14
  #include "zstd_compress_internal.h"
19
15
 
20
16
  /**
@@ -25,101 +21,173 @@ extern "C" {
25
21
  */
26
22
  #define ZSTD_LAZY_DDSS_BUCKET_LOG 2
27
23
 
28
- U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip);
29
- void ZSTD_row_update(ZSTD_matchState_t* const ms, const BYTE* ip);
24
+ #define ZSTD_ROW_HASH_TAG_BITS 8 /* nb bits to use for the tag */
30
25
 
31
- void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t* ms, const BYTE* const ip);
26
+ #if !defined(ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR) \
27
+ || !defined(ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR) \
28
+ || !defined(ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR) \
29
+ || !defined(ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR)
30
+ U32 ZSTD_insertAndFindFirstIndex(ZSTD_MatchState_t* ms, const BYTE* ip);
31
+ void ZSTD_row_update(ZSTD_MatchState_t* const ms, const BYTE* ip);
32
+
33
+ void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_MatchState_t* ms, const BYTE* const ip);
32
34
 
33
35
  void ZSTD_preserveUnsortedMark (U32* const table, U32 const size, U32 const reducerValue); /*! used in ZSTD_reduceIndex(). preemptively increase value of ZSTD_DUBT_UNSORTED_MARK */
36
+ #endif
34
37
 
35
- size_t ZSTD_compressBlock_btlazy2(
36
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
38
+ #ifndef ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR
39
+ size_t ZSTD_compressBlock_greedy(
40
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
37
41
  void const* src, size_t srcSize);
38
- size_t ZSTD_compressBlock_lazy2(
39
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
42
+ size_t ZSTD_compressBlock_greedy_row(
43
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
40
44
  void const* src, size_t srcSize);
41
- size_t ZSTD_compressBlock_lazy(
42
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
45
+ size_t ZSTD_compressBlock_greedy_dictMatchState(
46
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
43
47
  void const* src, size_t srcSize);
44
- size_t ZSTD_compressBlock_greedy(
45
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
48
+ size_t ZSTD_compressBlock_greedy_dictMatchState_row(
49
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
46
50
  void const* src, size_t srcSize);
47
- size_t ZSTD_compressBlock_lazy2_row(
48
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
51
+ size_t ZSTD_compressBlock_greedy_dedicatedDictSearch(
52
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
49
53
  void const* src, size_t srcSize);
50
- size_t ZSTD_compressBlock_lazy_row(
51
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
54
+ size_t ZSTD_compressBlock_greedy_dedicatedDictSearch_row(
55
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
52
56
  void const* src, size_t srcSize);
53
- size_t ZSTD_compressBlock_greedy_row(
54
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
57
+ size_t ZSTD_compressBlock_greedy_extDict(
58
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
59
+ void const* src, size_t srcSize);
60
+ size_t ZSTD_compressBlock_greedy_extDict_row(
61
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
55
62
  void const* src, size_t srcSize);
56
63
 
57
- size_t ZSTD_compressBlock_btlazy2_dictMatchState(
58
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
64
+ #define ZSTD_COMPRESSBLOCK_GREEDY ZSTD_compressBlock_greedy
65
+ #define ZSTD_COMPRESSBLOCK_GREEDY_ROW ZSTD_compressBlock_greedy_row
66
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE ZSTD_compressBlock_greedy_dictMatchState
67
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE_ROW ZSTD_compressBlock_greedy_dictMatchState_row
68
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH ZSTD_compressBlock_greedy_dedicatedDictSearch
69
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH_ROW ZSTD_compressBlock_greedy_dedicatedDictSearch_row
70
+ #define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT ZSTD_compressBlock_greedy_extDict
71
+ #define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT_ROW ZSTD_compressBlock_greedy_extDict_row
72
+ #else
73
+ #define ZSTD_COMPRESSBLOCK_GREEDY NULL
74
+ #define ZSTD_COMPRESSBLOCK_GREEDY_ROW NULL
75
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE NULL
76
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DICTMATCHSTATE_ROW NULL
77
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH NULL
78
+ #define ZSTD_COMPRESSBLOCK_GREEDY_DEDICATEDDICTSEARCH_ROW NULL
79
+ #define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT NULL
80
+ #define ZSTD_COMPRESSBLOCK_GREEDY_EXTDICT_ROW NULL
81
+ #endif
82
+
83
+ #ifndef ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR
84
+ size_t ZSTD_compressBlock_lazy(
85
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
59
86
  void const* src, size_t srcSize);
60
- size_t ZSTD_compressBlock_lazy2_dictMatchState(
61
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
87
+ size_t ZSTD_compressBlock_lazy_row(
88
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
62
89
  void const* src, size_t srcSize);
63
90
  size_t ZSTD_compressBlock_lazy_dictMatchState(
64
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
65
- void const* src, size_t srcSize);
66
- size_t ZSTD_compressBlock_greedy_dictMatchState(
67
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
68
- void const* src, size_t srcSize);
69
- size_t ZSTD_compressBlock_lazy2_dictMatchState_row(
70
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
91
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
71
92
  void const* src, size_t srcSize);
72
93
  size_t ZSTD_compressBlock_lazy_dictMatchState_row(
73
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
94
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
74
95
  void const* src, size_t srcSize);
75
- size_t ZSTD_compressBlock_greedy_dictMatchState_row(
76
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
96
+ size_t ZSTD_compressBlock_lazy_dedicatedDictSearch(
97
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
77
98
  void const* src, size_t srcSize);
78
-
79
- size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch(
80
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
99
+ size_t ZSTD_compressBlock_lazy_dedicatedDictSearch_row(
100
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
81
101
  void const* src, size_t srcSize);
82
- size_t ZSTD_compressBlock_lazy_dedicatedDictSearch(
83
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
102
+ size_t ZSTD_compressBlock_lazy_extDict(
103
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
84
104
  void const* src, size_t srcSize);
85
- size_t ZSTD_compressBlock_greedy_dedicatedDictSearch(
86
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
105
+ size_t ZSTD_compressBlock_lazy_extDict_row(
106
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
87
107
  void const* src, size_t srcSize);
88
- size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch_row(
89
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
108
+
109
+ #define ZSTD_COMPRESSBLOCK_LAZY ZSTD_compressBlock_lazy
110
+ #define ZSTD_COMPRESSBLOCK_LAZY_ROW ZSTD_compressBlock_lazy_row
111
+ #define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE ZSTD_compressBlock_lazy_dictMatchState
112
+ #define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE_ROW ZSTD_compressBlock_lazy_dictMatchState_row
113
+ #define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH ZSTD_compressBlock_lazy_dedicatedDictSearch
114
+ #define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH_ROW ZSTD_compressBlock_lazy_dedicatedDictSearch_row
115
+ #define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT ZSTD_compressBlock_lazy_extDict
116
+ #define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT_ROW ZSTD_compressBlock_lazy_extDict_row
117
+ #else
118
+ #define ZSTD_COMPRESSBLOCK_LAZY NULL
119
+ #define ZSTD_COMPRESSBLOCK_LAZY_ROW NULL
120
+ #define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE NULL
121
+ #define ZSTD_COMPRESSBLOCK_LAZY_DICTMATCHSTATE_ROW NULL
122
+ #define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH NULL
123
+ #define ZSTD_COMPRESSBLOCK_LAZY_DEDICATEDDICTSEARCH_ROW NULL
124
+ #define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT NULL
125
+ #define ZSTD_COMPRESSBLOCK_LAZY_EXTDICT_ROW NULL
126
+ #endif
127
+
128
+ #ifndef ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR
129
+ size_t ZSTD_compressBlock_lazy2(
130
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
90
131
  void const* src, size_t srcSize);
91
- size_t ZSTD_compressBlock_lazy_dedicatedDictSearch_row(
92
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
132
+ size_t ZSTD_compressBlock_lazy2_row(
133
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
93
134
  void const* src, size_t srcSize);
94
- size_t ZSTD_compressBlock_greedy_dedicatedDictSearch_row(
95
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
135
+ size_t ZSTD_compressBlock_lazy2_dictMatchState(
136
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
96
137
  void const* src, size_t srcSize);
97
-
98
- size_t ZSTD_compressBlock_greedy_extDict(
99
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
138
+ size_t ZSTD_compressBlock_lazy2_dictMatchState_row(
139
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
100
140
  void const* src, size_t srcSize);
101
- size_t ZSTD_compressBlock_lazy_extDict(
102
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
141
+ size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch(
142
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
143
+ void const* src, size_t srcSize);
144
+ size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch_row(
145
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
103
146
  void const* src, size_t srcSize);
104
147
  size_t ZSTD_compressBlock_lazy2_extDict(
105
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
148
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
106
149
  void const* src, size_t srcSize);
107
- size_t ZSTD_compressBlock_greedy_extDict_row(
108
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
150
+ size_t ZSTD_compressBlock_lazy2_extDict_row(
151
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
109
152
  void const* src, size_t srcSize);
110
- size_t ZSTD_compressBlock_lazy_extDict_row(
111
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
153
+
154
+ #define ZSTD_COMPRESSBLOCK_LAZY2 ZSTD_compressBlock_lazy2
155
+ #define ZSTD_COMPRESSBLOCK_LAZY2_ROW ZSTD_compressBlock_lazy2_row
156
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE ZSTD_compressBlock_lazy2_dictMatchState
157
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE_ROW ZSTD_compressBlock_lazy2_dictMatchState_row
158
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH ZSTD_compressBlock_lazy2_dedicatedDictSearch
159
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH_ROW ZSTD_compressBlock_lazy2_dedicatedDictSearch_row
160
+ #define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT ZSTD_compressBlock_lazy2_extDict
161
+ #define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT_ROW ZSTD_compressBlock_lazy2_extDict_row
162
+ #else
163
+ #define ZSTD_COMPRESSBLOCK_LAZY2 NULL
164
+ #define ZSTD_COMPRESSBLOCK_LAZY2_ROW NULL
165
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE NULL
166
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DICTMATCHSTATE_ROW NULL
167
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH NULL
168
+ #define ZSTD_COMPRESSBLOCK_LAZY2_DEDICATEDDICTSEARCH_ROW NULL
169
+ #define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT NULL
170
+ #define ZSTD_COMPRESSBLOCK_LAZY2_EXTDICT_ROW NULL
171
+ #endif
172
+
173
+ #ifndef ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR
174
+ size_t ZSTD_compressBlock_btlazy2(
175
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
112
176
  void const* src, size_t srcSize);
113
- size_t ZSTD_compressBlock_lazy2_extDict_row(
114
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
177
+ size_t ZSTD_compressBlock_btlazy2_dictMatchState(
178
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
115
179
  void const* src, size_t srcSize);
116
180
  size_t ZSTD_compressBlock_btlazy2_extDict(
117
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
181
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
118
182
  void const* src, size_t srcSize);
119
-
120
183
 
121
- #if defined (__cplusplus)
122
- }
184
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2 ZSTD_compressBlock_btlazy2
185
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2_DICTMATCHSTATE ZSTD_compressBlock_btlazy2_dictMatchState
186
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2_EXTDICT ZSTD_compressBlock_btlazy2_extDict
187
+ #else
188
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2 NULL
189
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2_DICTMATCHSTATE NULL
190
+ #define ZSTD_COMPRESSBLOCK_BTLAZY2_EXTDICT NULL
123
191
  #endif
124
192
 
125
193
  #endif /* ZSTD_LAZY_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -16,7 +16,7 @@
16
16
  #include "zstd_double_fast.h" /* ZSTD_fillDoubleHashTable() */
17
17
  #include "zstd_ldm_geartab.h"
18
18
 
19
- #define LDM_BUCKET_SIZE_LOG 3
19
+ #define LDM_BUCKET_SIZE_LOG 4
20
20
  #define LDM_MIN_MATCH_LENGTH 64
21
21
  #define LDM_HASH_RLOG 7
22
22
 
@@ -133,21 +133,35 @@ done:
133
133
  }
134
134
 
135
135
  void ZSTD_ldm_adjustParameters(ldmParams_t* params,
136
- ZSTD_compressionParameters const* cParams)
136
+ const ZSTD_compressionParameters* cParams)
137
137
  {
138
138
  params->windowLog = cParams->windowLog;
139
139
  ZSTD_STATIC_ASSERT(LDM_BUCKET_SIZE_LOG <= ZSTD_LDM_BUCKETSIZELOG_MAX);
140
140
  DEBUGLOG(4, "ZSTD_ldm_adjustParameters");
141
- if (!params->bucketSizeLog) params->bucketSizeLog = LDM_BUCKET_SIZE_LOG;
142
- if (!params->minMatchLength) params->minMatchLength = LDM_MIN_MATCH_LENGTH;
141
+ if (params->hashRateLog == 0) {
142
+ if (params->hashLog > 0) {
143
+ /* if params->hashLog is set, derive hashRateLog from it */
144
+ assert(params->hashLog <= ZSTD_HASHLOG_MAX);
145
+ if (params->windowLog > params->hashLog) {
146
+ params->hashRateLog = params->windowLog - params->hashLog;
147
+ }
148
+ } else {
149
+ assert(1 <= (int)cParams->strategy && (int)cParams->strategy <= 9);
150
+ /* mapping from [fast, rate7] to [btultra2, rate4] */
151
+ params->hashRateLog = 7 - (cParams->strategy/3);
152
+ }
153
+ }
143
154
  if (params->hashLog == 0) {
144
- params->hashLog = MAX(ZSTD_HASHLOG_MIN, params->windowLog - LDM_HASH_RLOG);
145
- assert(params->hashLog <= ZSTD_HASHLOG_MAX);
155
+ params->hashLog = BOUNDED(ZSTD_HASHLOG_MIN, params->windowLog - params->hashRateLog, ZSTD_HASHLOG_MAX);
146
156
  }
147
- if (params->hashRateLog == 0) {
148
- params->hashRateLog = params->windowLog < params->hashLog
149
- ? 0
150
- : params->windowLog - params->hashLog;
157
+ if (params->minMatchLength == 0) {
158
+ params->minMatchLength = LDM_MIN_MATCH_LENGTH;
159
+ if (cParams->strategy >= ZSTD_btultra)
160
+ params->minMatchLength /= 2;
161
+ }
162
+ if (params->bucketSizeLog==0) {
163
+ assert(1 <= (int)cParams->strategy && (int)cParams->strategy <= 9);
164
+ params->bucketSizeLog = BOUNDED(LDM_BUCKET_SIZE_LOG, (U32)cParams->strategy, ZSTD_LDM_BUCKETSIZELOG_MAX);
151
165
  }
152
166
  params->bucketSizeLog = MIN(params->bucketSizeLog, params->hashLog);
153
167
  }
@@ -170,22 +184,22 @@ size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize)
170
184
  /** ZSTD_ldm_getBucket() :
171
185
  * Returns a pointer to the start of the bucket associated with hash. */
172
186
  static ldmEntry_t* ZSTD_ldm_getBucket(
173
- ldmState_t* ldmState, size_t hash, ldmParams_t const ldmParams)
187
+ const ldmState_t* ldmState, size_t hash, U32 const bucketSizeLog)
174
188
  {
175
- return ldmState->hashTable + (hash << ldmParams.bucketSizeLog);
189
+ return ldmState->hashTable + (hash << bucketSizeLog);
176
190
  }
177
191
 
178
192
  /** ZSTD_ldm_insertEntry() :
179
193
  * Insert the entry with corresponding hash into the hash table */
180
194
  static void ZSTD_ldm_insertEntry(ldmState_t* ldmState,
181
195
  size_t const hash, const ldmEntry_t entry,
182
- ldmParams_t const ldmParams)
196
+ U32 const bucketSizeLog)
183
197
  {
184
198
  BYTE* const pOffset = ldmState->bucketOffsets + hash;
185
199
  unsigned const offset = *pOffset;
186
200
 
187
- *(ZSTD_ldm_getBucket(ldmState, hash, ldmParams) + offset) = entry;
188
- *pOffset = (BYTE)((offset + 1) & ((1u << ldmParams.bucketSizeLog) - 1));
201
+ *(ZSTD_ldm_getBucket(ldmState, hash, bucketSizeLog) + offset) = entry;
202
+ *pOffset = (BYTE)((offset + 1) & ((1u << bucketSizeLog) - 1));
189
203
 
190
204
  }
191
205
 
@@ -234,7 +248,7 @@ static size_t ZSTD_ldm_countBackwardsMatch_2segments(
234
248
  *
235
249
  * The tables for the other strategies are filled within their
236
250
  * block compressors. */
237
- static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
251
+ static size_t ZSTD_ldm_fillFastTables(ZSTD_MatchState_t* ms,
238
252
  void const* end)
239
253
  {
240
254
  const BYTE* const iend = (const BYTE*)end;
@@ -242,11 +256,15 @@ static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
242
256
  switch(ms->cParams.strategy)
243
257
  {
244
258
  case ZSTD_fast:
245
- ZSTD_fillHashTable(ms, iend, ZSTD_dtlm_fast);
259
+ ZSTD_fillHashTable(ms, iend, ZSTD_dtlm_fast, ZSTD_tfp_forCCtx);
246
260
  break;
247
261
 
248
262
  case ZSTD_dfast:
249
- ZSTD_fillDoubleHashTable(ms, iend, ZSTD_dtlm_fast);
263
+ #ifndef ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
264
+ ZSTD_fillDoubleHashTable(ms, iend, ZSTD_dtlm_fast, ZSTD_tfp_forCCtx);
265
+ #else
266
+ assert(0); /* shouldn't be called: cparams should've been adjusted. */
267
+ #endif
250
268
  break;
251
269
 
252
270
  case ZSTD_greedy:
@@ -269,7 +287,8 @@ void ZSTD_ldm_fillHashTable(
269
287
  const BYTE* iend, ldmParams_t const* params)
270
288
  {
271
289
  U32 const minMatchLength = params->minMatchLength;
272
- U32 const hBits = params->hashLog - params->bucketSizeLog;
290
+ U32 const bucketSizeLog = params->bucketSizeLog;
291
+ U32 const hBits = params->hashLog - bucketSizeLog;
273
292
  BYTE const* const base = ldmState->window.base;
274
293
  BYTE const* const istart = ip;
275
294
  ldmRollingHashState_t hashState;
@@ -284,7 +303,7 @@ void ZSTD_ldm_fillHashTable(
284
303
  unsigned n;
285
304
 
286
305
  numSplits = 0;
287
- hashed = ZSTD_ldm_gear_feed(&hashState, ip, iend - ip, splits, &numSplits);
306
+ hashed = ZSTD_ldm_gear_feed(&hashState, ip, (size_t)(iend - ip), splits, &numSplits);
288
307
 
289
308
  for (n = 0; n < numSplits; n++) {
290
309
  if (ip + splits[n] >= istart + minMatchLength) {
@@ -295,7 +314,7 @@ void ZSTD_ldm_fillHashTable(
295
314
 
296
315
  entry.offset = (U32)(split - base);
297
316
  entry.checksum = (U32)(xxhash >> 32);
298
- ZSTD_ldm_insertEntry(ldmState, hash, entry, *params);
317
+ ZSTD_ldm_insertEntry(ldmState, hash, entry, params->bucketSizeLog);
299
318
  }
300
319
  }
301
320
 
@@ -309,7 +328,7 @@ void ZSTD_ldm_fillHashTable(
309
328
  * Sets cctx->nextToUpdate to a position corresponding closer to anchor
310
329
  * if it is far way
311
330
  * (after a long match, only update tables a limited amount). */
312
- static void ZSTD_ldm_limitTableUpdate(ZSTD_matchState_t* ms, const BYTE* anchor)
331
+ static void ZSTD_ldm_limitTableUpdate(ZSTD_MatchState_t* ms, const BYTE* anchor)
313
332
  {
314
333
  U32 const curr = (U32)(anchor - ms->window.base);
315
334
  if (curr > ms->nextToUpdate + 1024) {
@@ -318,8 +337,10 @@ static void ZSTD_ldm_limitTableUpdate(ZSTD_matchState_t* ms, const BYTE* anchor)
318
337
  }
319
338
  }
320
339
 
321
- static size_t ZSTD_ldm_generateSequences_internal(
322
- ldmState_t* ldmState, rawSeqStore_t* rawSeqStore,
340
+ static
341
+ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
342
+ size_t ZSTD_ldm_generateSequences_internal(
343
+ ldmState_t* ldmState, RawSeqStore_t* rawSeqStore,
323
344
  ldmParams_t const* params, void const* src, size_t srcSize)
324
345
  {
325
346
  /* LDM parameters */
@@ -373,7 +394,7 @@ static size_t ZSTD_ldm_generateSequences_internal(
373
394
  candidates[n].split = split;
374
395
  candidates[n].hash = hash;
375
396
  candidates[n].checksum = (U32)(xxhash >> 32);
376
- candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, *params);
397
+ candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, params->bucketSizeLog);
377
398
  PREFETCH_L1(candidates[n].bucket);
378
399
  }
379
400
 
@@ -396,7 +417,7 @@ static size_t ZSTD_ldm_generateSequences_internal(
396
417
  * the previous one, we merely register it in the hash table and
397
418
  * move on */
398
419
  if (split < anchor) {
399
- ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
420
+ ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
400
421
  continue;
401
422
  }
402
423
 
@@ -443,7 +464,7 @@ static size_t ZSTD_ldm_generateSequences_internal(
443
464
  /* No match found -- insert an entry into the hash table
444
465
  * and process the next candidate match */
445
466
  if (bestEntry == NULL) {
446
- ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
467
+ ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
447
468
  continue;
448
469
  }
449
470
 
@@ -464,7 +485,7 @@ static size_t ZSTD_ldm_generateSequences_internal(
464
485
 
465
486
  /* Insert the current entry into the hash table --- it must be
466
487
  * done after the previous block to avoid clobbering bestEntry */
467
- ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
488
+ ZSTD_ldm_insertEntry(ldmState, hash, newEntry, params->bucketSizeLog);
468
489
 
469
490
  anchor = split + forwardMatchLength;
470
491
 
@@ -503,7 +524,7 @@ static void ZSTD_ldm_reduceTable(ldmEntry_t* const table, U32 const size,
503
524
  }
504
525
 
505
526
  size_t ZSTD_ldm_generateSequences(
506
- ldmState_t* ldmState, rawSeqStore_t* sequences,
527
+ ldmState_t* ldmState, RawSeqStore_t* sequences,
507
528
  ldmParams_t const* params, void const* src, size_t srcSize)
508
529
  {
509
530
  U32 const maxDist = 1U << params->windowLog;
@@ -549,7 +570,7 @@ size_t ZSTD_ldm_generateSequences(
549
570
  * the window through early invalidation.
550
571
  * TODO: * Test the chunk size.
551
572
  * * Try invalidation after the sequence generation and test the
552
- * the offset against maxDist directly.
573
+ * offset against maxDist directly.
553
574
  *
554
575
  * NOTE: Because of dictionaries + sequence splitting we MUST make sure
555
576
  * that any offset used is valid at the END of the sequence, since it may
@@ -580,7 +601,7 @@ size_t ZSTD_ldm_generateSequences(
580
601
  }
581
602
 
582
603
  void
583
- ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize, U32 const minMatch)
604
+ ZSTD_ldm_skipSequences(RawSeqStore_t* rawSeqStore, size_t srcSize, U32 const minMatch)
584
605
  {
585
606
  while (srcSize > 0 && rawSeqStore->pos < rawSeqStore->size) {
586
607
  rawSeq* seq = rawSeqStore->seq + rawSeqStore->pos;
@@ -616,7 +637,7 @@ ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize, U32 const min
616
637
  * Returns the current sequence to handle, or if the rest of the block should
617
638
  * be literals, it returns a sequence with offset == 0.
618
639
  */
619
- static rawSeq maybeSplitSequence(rawSeqStore_t* rawSeqStore,
640
+ static rawSeq maybeSplitSequence(RawSeqStore_t* rawSeqStore,
620
641
  U32 const remaining, U32 const minMatch)
621
642
  {
622
643
  rawSeq sequence = rawSeqStore->seq[rawSeqStore->pos];
@@ -640,7 +661,7 @@ static rawSeq maybeSplitSequence(rawSeqStore_t* rawSeqStore,
640
661
  return sequence;
641
662
  }
642
663
 
643
- void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes) {
664
+ void ZSTD_ldm_skipRawSeqStoreBytes(RawSeqStore_t* rawSeqStore, size_t nbBytes) {
644
665
  U32 currPos = (U32)(rawSeqStore->posInSequence + nbBytes);
645
666
  while (currPos && rawSeqStore->pos < rawSeqStore->size) {
646
667
  rawSeq currSeq = rawSeqStore->seq[rawSeqStore->pos];
@@ -657,14 +678,14 @@ void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes) {
657
678
  }
658
679
  }
659
680
 
660
- size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
661
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
662
- ZSTD_paramSwitch_e useRowMatchFinder,
681
+ size_t ZSTD_ldm_blockCompress(RawSeqStore_t* rawSeqStore,
682
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
683
+ ZSTD_ParamSwitch_e useRowMatchFinder,
663
684
  void const* src, size_t srcSize)
664
685
  {
665
686
  const ZSTD_compressionParameters* const cParams = &ms->cParams;
666
687
  unsigned const minMatch = cParams->minMatch;
667
- ZSTD_blockCompressor const blockCompressor =
688
+ ZSTD_BlockCompressor_f const blockCompressor =
668
689
  ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
669
690
  /* Input bounds */
670
691
  BYTE const* const istart = (BYTE const*)src;
@@ -689,7 +710,6 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
689
710
  /* maybeSplitSequence updates rawSeqStore->pos */
690
711
  rawSeq const sequence = maybeSplitSequence(rawSeqStore,
691
712
  (U32)(iend - ip), minMatch);
692
- int i;
693
713
  /* End signal */
694
714
  if (sequence.offset == 0)
695
715
  break;
@@ -702,6 +722,7 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
702
722
  /* Run the block compressor */
703
723
  DEBUGLOG(5, "pos %u : calling block compressor on segment of size %u", (unsigned)(ip-istart), sequence.litLength);
704
724
  {
725
+ int i;
705
726
  size_t const newLitLength =
706
727
  blockCompressor(ms, seqStore, rep, ip, sequence.litLength);
707
728
  ip += sequence.litLength;
@@ -711,7 +732,7 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
711
732
  rep[0] = sequence.offset;
712
733
  /* Store the sequence */
713
734
  ZSTD_storeSeq(seqStore, newLitLength, ip - newLitLength, iend,
714
- STORE_OFFSET(sequence.offset),
735
+ OFFSET_TO_OFFBASE(sequence.offset),
715
736
  sequence.matchLength);
716
737
  ip += sequence.matchLength;
717
738
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -11,10 +11,6 @@
11
11
  #ifndef ZSTD_LDM_H
12
12
  #define ZSTD_LDM_H
13
13
 
14
- #if defined (__cplusplus)
15
- extern "C" {
16
- #endif
17
-
18
14
  #include "zstd_compress_internal.h" /* ldmParams_t, U32 */
19
15
  #include "../zstd.h" /* ZSTD_CCtx, size_t */
20
16
 
@@ -43,7 +39,7 @@ void ZSTD_ldm_fillHashTable(
43
39
  * sequences.
44
40
  */
45
41
  size_t ZSTD_ldm_generateSequences(
46
- ldmState_t* ldms, rawSeqStore_t* sequences,
42
+ ldmState_t* ldms, RawSeqStore_t* sequences,
47
43
  ldmParams_t const* params, void const* src, size_t srcSize);
48
44
 
49
45
  /**
@@ -64,9 +60,9 @@ size_t ZSTD_ldm_generateSequences(
64
60
  * two. We handle that case correctly, and update `rawSeqStore` appropriately.
65
61
  * NOTE: This function does not return any errors.
66
62
  */
67
- size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
68
- ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
69
- ZSTD_paramSwitch_e useRowMatchFinder,
63
+ size_t ZSTD_ldm_blockCompress(RawSeqStore_t* rawSeqStore,
64
+ ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
65
+ ZSTD_ParamSwitch_e useRowMatchFinder,
70
66
  void const* src, size_t srcSize);
71
67
 
72
68
  /**
@@ -76,7 +72,7 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
76
72
  * Avoids emitting matches less than `minMatch` bytes.
77
73
  * Must be called for data that is not passed to ZSTD_ldm_blockCompress().
78
74
  */
79
- void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
75
+ void ZSTD_ldm_skipSequences(RawSeqStore_t* rawSeqStore, size_t srcSize,
80
76
  U32 const minMatch);
81
77
 
82
78
  /* ZSTD_ldm_skipRawSeqStoreBytes():
@@ -84,7 +80,7 @@ void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
84
80
  * Not to be used in conjunction with ZSTD_ldm_skipSequences().
85
81
  * Must be called for data with is not passed to ZSTD_ldm_blockCompress().
86
82
  */
87
- void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);
83
+ void ZSTD_ldm_skipRawSeqStoreBytes(RawSeqStore_t* rawSeqStore, size_t nbBytes);
88
84
 
89
85
  /** ZSTD_ldm_getTableSize() :
90
86
  * Estimate the space needed for long distance matching tables or 0 if LDM is
@@ -110,8 +106,4 @@ size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
110
106
  void ZSTD_ldm_adjustParameters(ldmParams_t* params,
111
107
  ZSTD_compressionParameters const* cParams);
112
108
 
113
- #if defined (__cplusplus)
114
- }
115
- #endif
116
-
117
109
  #endif /* ZSTD_FAST_H */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the