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
@@ -14,7 +14,6 @@
14
14
  * Dependencies
15
15
  ***************************************/
16
16
  #define ZSTD_DEPS_NEED_MALLOC
17
- #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
18
17
  #include "error_private.h"
19
18
  #include "zstd_internal.h"
20
19
 
@@ -47,37 +46,3 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
47
46
  /*! ZSTD_getErrorString() :
48
47
  * provides error code string from enum */
49
48
  const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
50
-
51
-
52
-
53
- /*=**************************************************************
54
- * Custom allocator
55
- ****************************************************************/
56
- void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
57
- {
58
- if (customMem.customAlloc)
59
- return customMem.customAlloc(customMem.opaque, size);
60
- return ZSTD_malloc(size);
61
- }
62
-
63
- void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
64
- {
65
- if (customMem.customAlloc) {
66
- /* calloc implemented as malloc+memset;
67
- * not as efficient as calloc, but next best guess for custom malloc */
68
- void* const ptr = customMem.customAlloc(customMem.opaque, size);
69
- ZSTD_memset(ptr, 0, size);
70
- return ptr;
71
- }
72
- return ZSTD_calloc(1, size);
73
- }
74
-
75
- void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
76
- {
77
- if (ptr!=NULL) {
78
- if (customMem.customFree)
79
- customMem.customFree(customMem.opaque, ptr);
80
- else
81
- ZSTD_free(ptr);
82
- }
83
- }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 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
@@ -24,6 +24,18 @@
24
24
  #ifndef ZSTD_DEPS_COMMON
25
25
  #define ZSTD_DEPS_COMMON
26
26
 
27
+ /* Even though we use qsort_r only for the dictionary builder, the macro
28
+ * _GNU_SOURCE has to be declared *before* the inclusion of any standard
29
+ * header and the script 'combine.sh' combines the whole zstd source code
30
+ * in a single file.
31
+ */
32
+ #if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \
33
+ defined(__CYGWIN__) || defined(__MSYS__)
34
+ #if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */
35
+ #define _GNU_SOURCE
36
+ #endif
37
+ #endif
38
+
27
39
  #include <limits.h>
28
40
  #include <stddef.h>
29
41
  #include <string.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
@@ -28,7 +28,6 @@
28
28
  #include "../zstd.h"
29
29
  #define FSE_STATIC_LINKING_ONLY
30
30
  #include "fse.h"
31
- #define HUF_STATIC_LINKING_ONLY
32
31
  #include "huf.h"
33
32
  #ifndef XXH_STATIC_LINKING_ONLY
34
33
  # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
@@ -40,10 +39,6 @@
40
39
  # define ZSTD_TRACE 0
41
40
  #endif
42
41
 
43
- #if defined (__cplusplus)
44
- extern "C" {
45
- #endif
46
-
47
42
  /* ---- static assert (debug) --- */
48
43
  #define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
49
44
  #define ZSTD_isError ERR_isError /* for inlining */
@@ -93,16 +88,17 @@ typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
93
88
  #define ZSTD_FRAMECHECKSUMSIZE 4
94
89
 
95
90
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
96
- #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
91
+ #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */) /* for a non-null block */
92
+ #define MIN_LITERALS_FOR_4_STREAMS 6
97
93
 
98
- #define HufLog 12
99
- typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
94
+ typedef enum { set_basic, set_rle, set_compressed, set_repeat } SymbolEncodingType_e;
100
95
 
101
96
  #define LONGNBSEQ 0x7F00
102
97
 
103
98
  #define MINMATCH 3
104
99
 
105
100
  #define Litbits 8
101
+ #define LitHufLog 11
106
102
  #define MaxLit ((1<<Litbits) - 1)
107
103
  #define MaxML 52
108
104
  #define MaxLL 35
@@ -113,6 +109,8 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
113
109
  #define LLFSELog 9
114
110
  #define OffFSELog 8
115
111
  #define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
112
+ #define MaxMLBits 16
113
+ #define MaxLLBits 16
116
114
 
117
115
  #define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
118
116
  /* Each table cannot take more than #symbols * FSELog bits */
@@ -176,7 +174,7 @@ static void ZSTD_copy8(void* dst, const void* src) {
176
174
  ZSTD_memcpy(dst, src, 8);
177
175
  #endif
178
176
  }
179
- #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
177
+ #define COPY8(d,s) do { ZSTD_copy8(d,s); d+=8; s+=8; } while (0)
180
178
 
181
179
  /* Need to use memmove here since the literal buffer can now be located within
182
180
  the dst buffer. In circumstances where the op "catches up" to where the
@@ -196,7 +194,7 @@ static void ZSTD_copy16(void* dst, const void* src) {
196
194
  ZSTD_memcpy(dst, copy16_buf, 16);
197
195
  #endif
198
196
  }
199
- #define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
197
+ #define COPY16(d,s) do { ZSTD_copy16(d,s); d+=16; s+=16; } while (0)
200
198
 
201
199
  #define WILDCOPY_OVERLENGTH 32
202
200
  #define WILDCOPY_VECLEN 16
@@ -225,7 +223,7 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
225
223
  if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
226
224
  /* Handle short offset copies. */
227
225
  do {
228
- COPY8(op, ip)
226
+ COPY8(op, ip);
229
227
  } while (op < oend);
230
228
  } else {
231
229
  assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
@@ -235,12 +233,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
235
233
  * one COPY16() in the first call. Then, do two calls per loop since
236
234
  * at that point it is more likely to have a high trip count.
237
235
  */
238
- #ifdef __aarch64__
239
- do {
240
- COPY16(op, ip);
241
- }
242
- while (op < oend);
243
- #else
244
236
  ZSTD_copy16(op, ip);
245
237
  if (16 >= length) return;
246
238
  op += 16;
@@ -250,7 +242,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
250
242
  COPY16(op, ip);
251
243
  }
252
244
  while (op < oend);
253
- #endif
254
245
  }
255
246
  }
256
247
 
@@ -283,62 +274,6 @@ typedef enum {
283
274
  /*-*******************************************
284
275
  * Private declarations
285
276
  *********************************************/
286
- typedef struct seqDef_s {
287
- U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
288
- U16 litLength;
289
- U16 mlBase; /* mlBase == matchLength - MINMATCH */
290
- } seqDef;
291
-
292
- /* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
293
- typedef enum {
294
- ZSTD_llt_none = 0, /* no longLengthType */
295
- ZSTD_llt_literalLength = 1, /* represents a long literal */
296
- ZSTD_llt_matchLength = 2 /* represents a long match */
297
- } ZSTD_longLengthType_e;
298
-
299
- typedef struct {
300
- seqDef* sequencesStart;
301
- seqDef* sequences; /* ptr to end of sequences */
302
- BYTE* litStart;
303
- BYTE* lit; /* ptr to end of literals */
304
- BYTE* llCode;
305
- BYTE* mlCode;
306
- BYTE* ofCode;
307
- size_t maxNbSeq;
308
- size_t maxNbLit;
309
-
310
- /* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
311
- * in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
312
- * the existing value of the litLength or matchLength by 0x10000.
313
- */
314
- ZSTD_longLengthType_e longLengthType;
315
- U32 longLengthPos; /* Index of the sequence to apply long length modification to */
316
- } seqStore_t;
317
-
318
- typedef struct {
319
- U32 litLength;
320
- U32 matchLength;
321
- } ZSTD_sequenceLength;
322
-
323
- /**
324
- * Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
325
- * indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
326
- */
327
- MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
328
- {
329
- ZSTD_sequenceLength seqLen;
330
- seqLen.litLength = seq->litLength;
331
- seqLen.matchLength = seq->mlBase + MINMATCH;
332
- if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
333
- if (seqStore->longLengthType == ZSTD_llt_literalLength) {
334
- seqLen.litLength += 0xFFFF;
335
- }
336
- if (seqStore->longLengthType == ZSTD_llt_matchLength) {
337
- seqLen.matchLength += 0xFFFF;
338
- }
339
- }
340
- return seqLen;
341
- }
342
277
 
343
278
  /**
344
279
  * Contains the compressed frame size and an upper-bound for the decompressed frame size.
@@ -347,111 +282,11 @@ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore
347
282
  * `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
348
283
  */
349
284
  typedef struct {
285
+ size_t nbBlocks;
350
286
  size_t compressedSize;
351
287
  unsigned long long decompressedBound;
352
288
  } ZSTD_frameSizeInfo; /* decompress & legacy */
353
289
 
354
- const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
355
- void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
356
-
357
- /* custom memory allocation functions */
358
- void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
359
- void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
360
- void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
361
-
362
-
363
- MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
364
- {
365
- assert(val != 0);
366
- {
367
- # if defined(_MSC_VER) /* Visual */
368
- # if STATIC_BMI2 == 1
369
- return _lzcnt_u32(val)^31;
370
- # else
371
- if (val != 0) {
372
- unsigned long r;
373
- _BitScanReverse(&r, val);
374
- return (unsigned)r;
375
- } else {
376
- /* Should not reach this code path */
377
- __assume(0);
378
- }
379
- # endif
380
- # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
381
- return __builtin_clz (val) ^ 31;
382
- # elif defined(__ICCARM__) /* IAR Intrinsic */
383
- return 31 - __CLZ(val);
384
- # else /* Software version */
385
- static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
386
- U32 v = val;
387
- v |= v >> 1;
388
- v |= v >> 2;
389
- v |= v >> 4;
390
- v |= v >> 8;
391
- v |= v >> 16;
392
- return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
393
- # endif
394
- }
395
- }
396
-
397
- /**
398
- * Counts the number of trailing zeros of a `size_t`.
399
- * Most compilers should support CTZ as a builtin. A backup
400
- * implementation is provided if the builtin isn't supported, but
401
- * it may not be terribly efficient.
402
- */
403
- MEM_STATIC unsigned ZSTD_countTrailingZeros(size_t val)
404
- {
405
- if (MEM_64bits()) {
406
- # if defined(_MSC_VER) && defined(_WIN64)
407
- # if STATIC_BMI2
408
- return _tzcnt_u64(val);
409
- # else
410
- if (val != 0) {
411
- unsigned long r;
412
- _BitScanForward64(&r, (U64)val);
413
- return (unsigned)r;
414
- } else {
415
- /* Should not reach this code path */
416
- __assume(0);
417
- }
418
- # endif
419
- # elif defined(__GNUC__) && (__GNUC__ >= 4)
420
- return __builtin_ctzll((U64)val);
421
- # else
422
- static const int DeBruijnBytePos[64] = { 0, 1, 2, 7, 3, 13, 8, 19,
423
- 4, 25, 14, 28, 9, 34, 20, 56,
424
- 5, 17, 26, 54, 15, 41, 29, 43,
425
- 10, 31, 38, 35, 21, 45, 49, 57,
426
- 63, 6, 12, 18, 24, 27, 33, 55,
427
- 16, 53, 40, 42, 30, 37, 44, 48,
428
- 62, 11, 23, 32, 52, 39, 36, 47,
429
- 61, 22, 51, 46, 60, 50, 59, 58 };
430
- return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
431
- # endif
432
- } else { /* 32 bits */
433
- # if defined(_MSC_VER)
434
- if (val != 0) {
435
- unsigned long r;
436
- _BitScanForward(&r, (U32)val);
437
- return (unsigned)r;
438
- } else {
439
- /* Should not reach this code path */
440
- __assume(0);
441
- }
442
- # elif defined(__GNUC__) && (__GNUC__ >= 3)
443
- return __builtin_ctz((U32)val);
444
- # else
445
- static const int DeBruijnBytePos[32] = { 0, 1, 28, 2, 29, 14, 24, 3,
446
- 30, 22, 20, 15, 25, 17, 4, 8,
447
- 31, 27, 13, 23, 21, 19, 16, 7,
448
- 26, 12, 18, 6, 11, 5, 10, 9 };
449
- return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
450
- # endif
451
- }
452
- }
453
-
454
-
455
290
  /* ZSTD_invalidateRepCodes() :
456
291
  * ensures next compression will not use repcodes from previous block.
457
292
  * Note : only works with regular variant;
@@ -467,13 +302,13 @@ typedef struct {
467
302
 
468
303
  /*! ZSTD_getcBlockSize() :
469
304
  * Provides the size of compressed block from block header `src` */
470
- /* Used by: decompress, fullbench (does not get its definition from here) */
305
+ /* Used by: decompress, fullbench */
471
306
  size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
472
307
  blockProperties_t* bpPtr);
473
308
 
474
309
  /*! ZSTD_decodeSeqHeaders() :
475
310
  * decode sequence header from src */
476
- /* Used by: decompress, fullbench (does not get its definition from here) */
311
+ /* Used by: zstd_decompress_block, fullbench */
477
312
  size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
478
313
  const void* src, size_t srcSize);
479
314
 
@@ -486,8 +321,4 @@ MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
486
321
  return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
487
322
  }
488
323
 
489
- #if defined (__cplusplus)
490
- }
491
- #endif
492
-
493
324
  #endif /* ZSTD_CCOMMON_H_MODULE */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 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,23 +11,20 @@
11
11
  #ifndef ZSTD_TRACE_H
12
12
  #define ZSTD_TRACE_H
13
13
 
14
- #if defined (__cplusplus)
15
- extern "C" {
16
- #endif
17
-
18
14
  #include <stddef.h>
19
15
 
20
16
  /* weak symbol support
21
17
  * For now, enable conservatively:
22
18
  * - Only GNUC
23
19
  * - Only ELF
24
- * - Only x86-64 and i386
20
+ * - Only x86-64, i386, aarch64 and risc-v.
25
21
  * Also, explicitly disable on platforms known not to work so they aren't
26
22
  * forgotten in the future.
27
23
  */
28
24
  #if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \
29
25
  defined(__GNUC__) && defined(__ELF__) && \
30
- (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)) && \
26
+ (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
27
+ defined(_M_IX86) || defined(__aarch64__) || defined(__riscv)) && \
31
28
  !defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \
32
29
  !defined(__CYGWIN__) && !defined(_AIX)
33
30
  # define ZSTD_HAVE_WEAK_SYMBOLS 1
@@ -64,7 +61,7 @@ typedef struct {
64
61
  /**
65
62
  * Non-zero if streaming (de)compression is used.
66
63
  */
67
- unsigned streaming;
64
+ int streaming;
68
65
  /**
69
66
  * The dictionary ID.
70
67
  */
@@ -73,7 +70,7 @@ typedef struct {
73
70
  * Is the dictionary cold?
74
71
  * Only set on decompression.
75
72
  */
76
- unsigned dictionaryIsCold;
73
+ int dictionaryIsCold;
77
74
  /**
78
75
  * The dictionary size or zero if no dictionary.
79
76
  */
@@ -156,8 +153,4 @@ ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(
156
153
 
157
154
  #endif /* ZSTD_TRACE */
158
155
 
159
- #if defined (__cplusplus)
160
- }
161
- #endif
162
-
163
156
  #endif /* ZSTD_TRACE_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
@@ -1,6 +1,6 @@
1
1
  /* ******************************************************************
2
2
  * FSE : Finite State Entropy encoder
3
- * Copyright (c) Yann Collet, Facebook, Inc.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * You can contact the author at :
6
6
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -25,7 +25,8 @@
25
25
  #include "../common/error_private.h"
26
26
  #define ZSTD_DEPS_NEED_MALLOC
27
27
  #define ZSTD_DEPS_NEED_MATH64
28
- #include "../common/zstd_deps.h" /* ZSTD_malloc, ZSTD_free, ZSTD_memcpy, ZSTD_memset */
28
+ #include "../common/zstd_deps.h" /* ZSTD_memset */
29
+ #include "../common/bits.h" /* ZSTD_highbit32 */
29
30
 
30
31
 
31
32
  /* **************************************************************
@@ -90,7 +91,7 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
90
91
  assert(tableLog < 16); /* required for threshold strategy to work */
91
92
 
92
93
  /* For explanations on how to distribute symbol values over the table :
93
- * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
94
+ * https://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
94
95
 
95
96
  #ifdef __clang_analyzer__
96
97
  ZSTD_memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
@@ -191,7 +192,7 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
191
192
  break;
192
193
  default :
193
194
  assert(normalizedCounter[s] > 1);
194
- { U32 const maxBitsOut = tableLog - BIT_highbit32 ((U32)normalizedCounter[s]-1);
195
+ { U32 const maxBitsOut = tableLog - ZSTD_highbit32 ((U32)normalizedCounter[s]-1);
195
196
  U32 const minStatePlus = (U32)normalizedCounter[s] << maxBitsOut;
196
197
  symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
197
198
  symbolTT[s].deltaFindState = (int)(total - (unsigned)normalizedCounter[s]);
@@ -224,8 +225,8 @@ size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
224
225
  size_t const maxHeaderSize = (((maxSymbolValue+1) * tableLog
225
226
  + 4 /* bitCount initialized at 4 */
226
227
  + 2 /* first two symbols may use one additional bit each */) / 8)
227
- + 1 /* round up to whole nb bytes */
228
- + 2 /* additional two bytes for bitstream flush */;
228
+ + 1 /* round up to whole nb bytes */
229
+ + 2 /* additional two bytes for bitstream flush */;
229
230
  return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
230
231
  }
231
232
 
@@ -254,7 +255,7 @@ FSE_writeNCount_generic (void* header, size_t headerBufferSize,
254
255
  /* Init */
255
256
  remaining = tableSize+1; /* +1 for extra accuracy */
256
257
  threshold = tableSize;
257
- nbBits = tableLog+1;
258
+ nbBits = (int)tableLog+1;
258
259
 
259
260
  while ((symbol < alphabetSize) && (remaining>1)) { /* stops at 1 */
260
261
  if (previousIs0) {
@@ -273,7 +274,7 @@ FSE_writeNCount_generic (void* header, size_t headerBufferSize,
273
274
  }
274
275
  while (symbol >= start+3) {
275
276
  start+=3;
276
- bitStream += 3 << bitCount;
277
+ bitStream += 3U << bitCount;
277
278
  bitCount += 2;
278
279
  }
279
280
  bitStream += (symbol-start) << bitCount;
@@ -293,7 +294,7 @@ FSE_writeNCount_generic (void* header, size_t headerBufferSize,
293
294
  count++; /* +1 for extra accuracy */
294
295
  if (count>=threshold)
295
296
  count += max; /* [0..max[ [max..threshold[ (...) [threshold+max 2*threshold[ */
296
- bitStream += count << bitCount;
297
+ bitStream += (U32)count << bitCount;
297
298
  bitCount += nbBits;
298
299
  bitCount -= (count<max);
299
300
  previousIs0 = (count==1);
@@ -321,7 +322,8 @@ FSE_writeNCount_generic (void* header, size_t headerBufferSize,
321
322
  out[1] = (BYTE)(bitStream>>8);
322
323
  out+= (bitCount+7) /8;
323
324
 
324
- return (out-ostart);
325
+ assert(out >= ostart);
326
+ return (size_t)(out-ostart);
325
327
  }
326
328
 
327
329
 
@@ -342,21 +344,11 @@ size_t FSE_writeNCount (void* buffer, size_t bufferSize,
342
344
  * FSE Compression Code
343
345
  ****************************************************************/
344
346
 
345
- FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog)
346
- {
347
- size_t size;
348
- if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
349
- size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
350
- return (FSE_CTable*)ZSTD_malloc(size);
351
- }
352
-
353
- void FSE_freeCTable (FSE_CTable* ct) { ZSTD_free(ct); }
354
-
355
347
  /* provides the minimum logSize to safely represent a distribution */
356
348
  static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
357
349
  {
358
- U32 minBitsSrc = BIT_highbit32((U32)(srcSize)) + 1;
359
- U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2;
350
+ U32 minBitsSrc = ZSTD_highbit32((U32)(srcSize)) + 1;
351
+ U32 minBitsSymbols = ZSTD_highbit32(maxSymbolValue) + 2;
360
352
  U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
361
353
  assert(srcSize > 1); /* Not supported, RLE should be used instead */
362
354
  return minBits;
@@ -364,7 +356,7 @@ static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
364
356
 
365
357
  unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
366
358
  {
367
- U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
359
+ U32 maxBitsSrc = ZSTD_highbit32((U32)(srcSize - 1)) - minus;
368
360
  U32 tableLog = maxTableLog;
369
361
  U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
370
362
  assert(srcSize > 1); /* Not supported, RLE should be used instead */
@@ -532,40 +524,6 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
532
524
  return tableLog;
533
525
  }
534
526
 
535
-
536
- /* fake FSE_CTable, for raw (uncompressed) input */
537
- size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits)
538
- {
539
- const unsigned tableSize = 1 << nbBits;
540
- const unsigned tableMask = tableSize - 1;
541
- const unsigned maxSymbolValue = tableMask;
542
- void* const ptr = ct;
543
- U16* const tableU16 = ( (U16*) ptr) + 2;
544
- void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableSize>>1); /* assumption : tableLog >= 1 */
545
- FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
546
- unsigned s;
547
-
548
- /* Sanity checks */
549
- if (nbBits < 1) return ERROR(GENERIC); /* min size */
550
-
551
- /* header */
552
- tableU16[-2] = (U16) nbBits;
553
- tableU16[-1] = (U16) maxSymbolValue;
554
-
555
- /* Build table */
556
- for (s=0; s<tableSize; s++)
557
- tableU16[s] = (U16)(tableSize + s);
558
-
559
- /* Build Symbol Transformation Table */
560
- { const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits);
561
- for (s=0; s<=maxSymbolValue; s++) {
562
- symbolTT[s].deltaNbBits = deltaNbBits;
563
- symbolTT[s].deltaFindState = s-1;
564
- } }
565
-
566
- return 0;
567
- }
568
-
569
527
  /* fake FSE_CTable, for rle input (always same symbol) */
570
528
  size_t FSE_buildCTable_rle (FSE_CTable* ct, BYTE symbolValue)
571
529
  {
@@ -664,78 +622,4 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
664
622
 
665
623
  size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
666
624
 
667
- #ifndef ZSTD_NO_UNUSED_FUNCTIONS
668
- /* FSE_compress_wksp() :
669
- * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
670
- * `wkspSize` size must be `(1<<tableLog)`.
671
- */
672
- size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
673
- {
674
- BYTE* const ostart = (BYTE*) dst;
675
- BYTE* op = ostart;
676
- BYTE* const oend = ostart + dstSize;
677
-
678
- unsigned count[FSE_MAX_SYMBOL_VALUE+1];
679
- S16 norm[FSE_MAX_SYMBOL_VALUE+1];
680
- FSE_CTable* CTable = (FSE_CTable*)workSpace;
681
- size_t const CTableSize = FSE_CTABLE_SIZE_U32(tableLog, maxSymbolValue);
682
- void* scratchBuffer = (void*)(CTable + CTableSize);
683
- size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable));
684
-
685
- /* init conditions */
686
- if (wkspSize < FSE_COMPRESS_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
687
- if (srcSize <= 1) return 0; /* Not compressible */
688
- if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
689
- if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
690
-
691
- /* Scan input and build symbol stats */
692
- { CHECK_V_F(maxCount, HIST_count_wksp(count, &maxSymbolValue, src, srcSize, scratchBuffer, scratchBufferSize) );
693
- if (maxCount == srcSize) return 1; /* only a single symbol in src : rle */
694
- if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */
695
- if (maxCount < (srcSize >> 7)) return 0; /* Heuristic : not compressible enough */
696
- }
697
-
698
- tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
699
- CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue, /* useLowProbCount */ srcSize >= 2048) );
700
-
701
- /* Write table description header */
702
- { CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
703
- op += nc_err;
704
- }
705
-
706
- /* Compress */
707
- CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
708
- { CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) );
709
- if (cSize == 0) return 0; /* not enough space for compressed data */
710
- op += cSize;
711
- }
712
-
713
- /* check compressibility */
714
- if ( (size_t)(op-ostart) >= srcSize-1 ) return 0;
715
-
716
- return op-ostart;
717
- }
718
-
719
- typedef struct {
720
- FSE_CTable CTable_max[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
721
- union {
722
- U32 hist_wksp[HIST_WKSP_SIZE_U32];
723
- BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
724
- } workspace;
725
- } fseWkspMax_t;
726
-
727
- size_t FSE_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
728
- {
729
- fseWkspMax_t scratchBuffer;
730
- DEBUG_STATIC_ASSERT(sizeof(scratchBuffer) >= FSE_COMPRESS_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)); /* compilation failures here means scratchBuffer is not large enough */
731
- if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
732
- return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer));
733
- }
734
-
735
- size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
736
- {
737
- return FSE_compress2(dst, dstCapacity, src, srcSize, FSE_MAX_SYMBOL_VALUE, FSE_DEFAULT_TABLELOG);
738
- }
739
- #endif
740
-
741
625
  #endif /* FSE_COMMONDEFS_ONLY */