multi_compress 0.1.0

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 (219) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +13 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +116 -0
  5. data/ext/multi_compress/extconf.rb +171 -0
  6. data/ext/multi_compress/multi_compress.c +1534 -0
  7. data/ext/multi_compress/vendor/brotli/c/common/constants.c +15 -0
  8. data/ext/multi_compress/vendor/brotli/c/common/constants.h +201 -0
  9. data/ext/multi_compress/vendor/brotli/c/common/context.c +156 -0
  10. data/ext/multi_compress/vendor/brotli/c/common/context.h +113 -0
  11. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +5916 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +64 -0
  13. data/ext/multi_compress/vendor/brotli/c/common/platform.c +23 -0
  14. data/ext/multi_compress/vendor/brotli/c/common/platform.h +541 -0
  15. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +521 -0
  16. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
  17. data/ext/multi_compress/vendor/brotli/c/common/transform.c +291 -0
  18. data/ext/multi_compress/vendor/brotli/c/common/transform.h +85 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/version.h +51 -0
  20. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +78 -0
  21. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +423 -0
  22. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +2875 -0
  23. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +342 -0
  24. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +122 -0
  25. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +733 -0
  26. data/ext/multi_compress/vendor/brotli/c/dec/state.c +183 -0
  27. data/ext/multi_compress/vendor/brotli/c/dec/state.h +400 -0
  28. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +207 -0
  29. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +40 -0
  30. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +939 -0
  31. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +96 -0
  32. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_inc.h +189 -0
  33. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +36 -0
  34. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +64 -0
  35. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +127 -0
  36. data/ext/multi_compress/vendor/brotli/c/enc/block_encoder_inc.h +34 -0
  37. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +217 -0
  38. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +52 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +481 -0
  40. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +1336 -0
  41. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +89 -0
  42. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +57 -0
  43. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +49 -0
  44. data/ext/multi_compress/vendor/brotli/c/enc/cluster_inc.h +325 -0
  45. data/ext/multi_compress/vendor/brotli/c/enc/command.c +28 -0
  46. data/ext/multi_compress/vendor/brotli/c/enc/command.h +191 -0
  47. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +207 -0
  48. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +74 -0
  49. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +800 -0
  50. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +86 -0
  51. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +657 -0
  52. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +72 -0
  53. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +1848 -0
  54. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +25 -0
  55. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +1996 -0
  56. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +640 -0
  57. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +157 -0
  58. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +504 -0
  59. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +123 -0
  60. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +542 -0
  61. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +105 -0
  62. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +67 -0
  63. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +72 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +728 -0
  65. data/ext/multi_compress/vendor/brotli/c/enc/hash_composite_inc.h +140 -0
  66. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +295 -0
  67. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +262 -0
  68. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +258 -0
  69. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +266 -0
  70. data/ext/multi_compress/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
  71. data/ext/multi_compress/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +330 -0
  72. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +100 -0
  73. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +64 -0
  74. data/ext/multi_compress/vendor/brotli/c/enc/histogram_inc.h +51 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +180 -0
  76. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +32 -0
  77. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +194 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +131 -0
  79. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +677 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +106 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +185 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/params.h +47 -0
  83. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +54 -0
  84. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +202 -0
  85. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +168 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/state.h +104 -0
  87. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +542 -0
  88. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +41 -0
  89. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +5866 -0
  90. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +85 -0
  91. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +33 -0
  92. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +88 -0
  93. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +409 -0
  94. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +501 -0
  95. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +305 -0
  96. data/ext/multi_compress/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
  97. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +83 -0
  98. data/ext/multi_compress/vendor/lz4/lib/LICENSE +24 -0
  99. data/ext/multi_compress/vendor/lz4/lib/Makefile +244 -0
  100. data/ext/multi_compress/vendor/lz4/lib/README.md +193 -0
  101. data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +63 -0
  102. data/ext/multi_compress/vendor/lz4/lib/dll/example/README.md +69 -0
  103. data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  104. data/ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  105. data/ext/multi_compress/vendor/lz4/lib/liblz4-dll.rc.in +35 -0
  106. data/ext/multi_compress/vendor/lz4/lib/liblz4.pc.in +14 -0
  107. data/ext/multi_compress/vendor/lz4/lib/lz4.c +2829 -0
  108. data/ext/multi_compress/vendor/lz4/lib/lz4.h +884 -0
  109. data/ext/multi_compress/vendor/lz4/lib/lz4file.c +341 -0
  110. data/ext/multi_compress/vendor/lz4/lib/lz4file.h +93 -0
  111. data/ext/multi_compress/vendor/lz4/lib/lz4frame.c +2136 -0
  112. data/ext/multi_compress/vendor/lz4/lib/lz4frame.h +751 -0
  113. data/ext/multi_compress/vendor/lz4/lib/lz4frame_static.h +47 -0
  114. data/ext/multi_compress/vendor/lz4/lib/lz4hc.c +2192 -0
  115. data/ext/multi_compress/vendor/lz4/lib/lz4hc.h +414 -0
  116. data/ext/multi_compress/vendor/lz4/lib/xxhash.c +1030 -0
  117. data/ext/multi_compress/vendor/lz4/lib/xxhash.h +328 -0
  118. data/ext/multi_compress/vendor/zstd/lib/BUCK +232 -0
  119. data/ext/multi_compress/vendor/zstd/lib/Makefile +369 -0
  120. data/ext/multi_compress/vendor/zstd/lib/README.md +237 -0
  121. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  122. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +200 -0
  123. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +457 -0
  124. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +450 -0
  125. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +249 -0
  126. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +30 -0
  127. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +116 -0
  128. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +340 -0
  129. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +63 -0
  130. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +168 -0
  131. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +640 -0
  132. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +313 -0
  133. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +286 -0
  134. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +426 -0
  135. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +371 -0
  136. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +90 -0
  137. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +158 -0
  138. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +182 -0
  139. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +150 -0
  140. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +18 -0
  141. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +7020 -0
  142. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +48 -0
  143. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +111 -0
  144. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +392 -0
  145. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +163 -0
  146. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +134 -0
  147. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +625 -0
  148. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +181 -0
  149. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +75 -0
  150. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +1464 -0
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +7153 -0
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +1534 -0
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +235 -0
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +39 -0
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +442 -0
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +688 -0
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +748 -0
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +770 -0
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +50 -0
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +968 -0
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +38 -0
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +2199 -0
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +202 -0
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +730 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +117 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +1576 -0
  170. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +80 -0
  171. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +1882 -0
  172. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +113 -0
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +1944 -0
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +244 -0
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +44 -0
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +2407 -0
  178. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +2215 -0
  179. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +73 -0
  180. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +240 -0
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +214 -0
  182. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +26 -0
  183. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +167 -0
  184. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +77 -0
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +1261 -0
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +152 -0
  187. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +1913 -0
  188. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +67 -0
  189. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +766 -0
  190. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +1133 -0
  191. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +48 -0
  192. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +63 -0
  193. data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +20 -0
  194. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.sln +25 -0
  195. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +181 -0
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +452 -0
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +2127 -0
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +94 -0
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +3465 -0
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +93 -0
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +3105 -0
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +93 -0
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +3598 -0
  204. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +142 -0
  205. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +4005 -0
  206. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +162 -0
  207. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +4106 -0
  208. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +172 -0
  209. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +4490 -0
  210. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +187 -0
  211. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +237 -0
  212. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +16 -0
  213. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +35 -0
  214. data/ext/multi_compress/vendor/zstd/lib/zdict.h +474 -0
  215. data/ext/multi_compress/vendor/zstd/lib/zstd.h +3089 -0
  216. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +114 -0
  217. data/lib/multi_compress/version.rb +5 -0
  218. data/lib/multi_compress.rb +329 -0
  219. metadata +322 -0
@@ -0,0 +1,64 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Models the histograms of literals, commands and distance codes. */
8
+
9
+ #ifndef BROTLI_ENC_HISTOGRAM_H_
10
+ #define BROTLI_ENC_HISTOGRAM_H_
11
+
12
+ #include <string.h> /* memset */
13
+
14
+ #include <brotli/types.h>
15
+
16
+ #include "../common/constants.h"
17
+ #include "../common/context.h"
18
+ #include "../common/platform.h"
19
+ #include "block_splitter.h"
20
+ #include "command.h"
21
+
22
+ #if defined(__cplusplus) || defined(c_plusplus)
23
+ extern "C" {
24
+ #endif
25
+
26
+ /* The distance symbols effectively used by "Large Window Brotli" (32-bit). */
27
+ #define BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS 544
28
+
29
+ #define FN(X) X ## Literal
30
+ #define DATA_SIZE BROTLI_NUM_LITERAL_SYMBOLS
31
+ #define DataType uint8_t
32
+ #include "histogram_inc.h" /* NOLINT(build/include) */
33
+ #undef DataType
34
+ #undef DATA_SIZE
35
+ #undef FN
36
+
37
+ #define FN(X) X ## Command
38
+ #define DataType uint16_t
39
+ #define DATA_SIZE BROTLI_NUM_COMMAND_SYMBOLS
40
+ #include "histogram_inc.h" /* NOLINT(build/include) */
41
+ #undef DATA_SIZE
42
+ #undef FN
43
+
44
+ #define FN(X) X ## Distance
45
+ #define DATA_SIZE BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS
46
+ #include "histogram_inc.h" /* NOLINT(build/include) */
47
+ #undef DataType
48
+ #undef DATA_SIZE
49
+ #undef FN
50
+
51
+ BROTLI_INTERNAL void BrotliBuildHistogramsWithContext(
52
+ const Command* cmds, const size_t num_commands,
53
+ const BlockSplit* literal_split, const BlockSplit* insert_and_copy_split,
54
+ const BlockSplit* dist_split, const uint8_t* ringbuffer, size_t pos,
55
+ size_t mask, uint8_t prev_byte, uint8_t prev_byte2,
56
+ const ContextType* context_modes, HistogramLiteral* literal_histograms,
57
+ HistogramCommand* insert_and_copy_histograms,
58
+ HistogramDistance* copy_dist_histograms);
59
+
60
+ #if defined(__cplusplus) || defined(c_plusplus)
61
+ } /* extern "C" */
62
+ #endif
63
+
64
+ #endif /* BROTLI_ENC_HISTOGRAM_H_ */
@@ -0,0 +1,51 @@
1
+ /* NOLINT(build/header_guard) */
2
+ /* Copyright 2013 Google Inc. All Rights Reserved.
3
+
4
+ Distributed under MIT license.
5
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
6
+ */
7
+
8
+ /* template parameters: Histogram, DATA_SIZE, DataType */
9
+
10
+ /* A simple container for histograms of data in blocks. */
11
+
12
+ typedef struct FN(Histogram) {
13
+ uint32_t data_[DATA_SIZE];
14
+ size_t total_count_;
15
+ double bit_cost_;
16
+ } FN(Histogram);
17
+
18
+ static BROTLI_INLINE void FN(HistogramClear)(FN(Histogram)* self) {
19
+ memset(self->data_, 0, sizeof(self->data_));
20
+ self->total_count_ = 0;
21
+ self->bit_cost_ = HUGE_VAL;
22
+ }
23
+
24
+ static BROTLI_INLINE void FN(ClearHistograms)(
25
+ FN(Histogram)* array, size_t length) {
26
+ size_t i;
27
+ for (i = 0; i < length; ++i) FN(HistogramClear)(array + i);
28
+ }
29
+
30
+ static BROTLI_INLINE void FN(HistogramAdd)(FN(Histogram)* self, size_t val) {
31
+ ++self->data_[val];
32
+ ++self->total_count_;
33
+ }
34
+
35
+ static BROTLI_INLINE void FN(HistogramAddVector)(FN(Histogram)* self,
36
+ const DataType* p, size_t n) {
37
+ self->total_count_ += n;
38
+ n += 1;
39
+ while (--n) ++self->data_[*p++];
40
+ }
41
+
42
+ static BROTLI_INLINE void FN(HistogramAddHistogram)(FN(Histogram)* self,
43
+ const FN(Histogram)* v) {
44
+ size_t i;
45
+ self->total_count_ += v->total_count_;
46
+ for (i = 0; i < DATA_SIZE; ++i) {
47
+ self->data_[i] += v->data_[i];
48
+ }
49
+ }
50
+
51
+ static BROTLI_INLINE size_t FN(HistogramDataSize)(void) { return DATA_SIZE; }
@@ -0,0 +1,180 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Literal cost model to allow backward reference replacement to be efficient.
8
+ */
9
+
10
+ #include "literal_cost.h"
11
+
12
+ #include <string.h> /* memset */
13
+
14
+ #include <brotli/types.h>
15
+
16
+ #include "../common/platform.h"
17
+ #include "fast_log.h"
18
+ #include "utf8_util.h"
19
+
20
+ #if defined(__cplusplus) || defined(c_plusplus)
21
+ extern "C" {
22
+ #endif
23
+
24
+ static size_t UTF8Position(size_t last, size_t c, size_t clamp) {
25
+ if (c < 128) {
26
+ return 0; /* Next one is the 'Byte 1' again. */
27
+ } else if (c >= 192) { /* Next one is the 'Byte 2' of utf-8 encoding. */
28
+ return BROTLI_MIN(size_t, 1, clamp);
29
+ } else {
30
+ /* Let's decide over the last byte if this ends the sequence. */
31
+ if (last < 0xE0) {
32
+ return 0; /* Completed two or three byte coding. */
33
+ } else { /* Next one is the 'Byte 3' of utf-8 encoding. */
34
+ return BROTLI_MIN(size_t, 2, clamp);
35
+ }
36
+ }
37
+ }
38
+
39
+ static size_t DecideMultiByteStatsLevel(size_t pos, size_t len, size_t mask,
40
+ const uint8_t* data) {
41
+ size_t counts[3] = { 0 };
42
+ size_t max_utf8 = 1; /* should be 2, but 1 compresses better. */
43
+ size_t last_c = 0;
44
+ size_t i;
45
+ for (i = 0; i < len; ++i) {
46
+ size_t c = data[(pos + i) & mask];
47
+ ++counts[UTF8Position(last_c, c, 2)];
48
+ last_c = c;
49
+ }
50
+ if (counts[2] < 500) {
51
+ max_utf8 = 1;
52
+ }
53
+ if (counts[1] + counts[2] < 25) {
54
+ max_utf8 = 0;
55
+ }
56
+ return max_utf8;
57
+ }
58
+
59
+ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
60
+ const uint8_t* data,
61
+ size_t* histogram, float* cost) {
62
+ /* max_utf8 is 0 (normal ASCII single byte modeling),
63
+ 1 (for 2-byte UTF-8 modeling), or 2 (for 3-byte UTF-8 modeling). */
64
+ const size_t max_utf8 = DecideMultiByteStatsLevel(pos, len, mask, data);
65
+ size_t window_half = 495;
66
+ size_t in_window = BROTLI_MIN(size_t, window_half, len);
67
+ size_t in_window_utf8[3] = { 0 };
68
+ size_t i;
69
+ memset(histogram, 0, 3 * 256 * sizeof(histogram[0]));
70
+
71
+ { /* Bootstrap histograms. */
72
+ size_t last_c = 0;
73
+ size_t utf8_pos = 0;
74
+ for (i = 0; i < in_window; ++i) {
75
+ size_t c = data[(pos + i) & mask];
76
+ ++histogram[256 * utf8_pos + c];
77
+ ++in_window_utf8[utf8_pos];
78
+ utf8_pos = UTF8Position(last_c, c, max_utf8);
79
+ last_c = c;
80
+ }
81
+ }
82
+
83
+ /* Compute bit costs with sliding window. */
84
+ for (i = 0; i < len; ++i) {
85
+ if (i >= window_half) {
86
+ /* Remove a byte in the past. */
87
+ size_t c =
88
+ i < window_half + 1 ? 0 : data[(pos + i - window_half - 1) & mask];
89
+ size_t last_c =
90
+ i < window_half + 2 ? 0 : data[(pos + i - window_half - 2) & mask];
91
+ size_t utf8_pos2 = UTF8Position(last_c, c, max_utf8);
92
+ --histogram[256 * utf8_pos2 + data[(pos + i - window_half) & mask]];
93
+ --in_window_utf8[utf8_pos2];
94
+ }
95
+ if (i + window_half < len) {
96
+ /* Add a byte in the future. */
97
+ size_t c = data[(pos + i + window_half - 1) & mask];
98
+ size_t last_c = data[(pos + i + window_half - 2) & mask];
99
+ size_t utf8_pos2 = UTF8Position(last_c, c, max_utf8);
100
+ ++histogram[256 * utf8_pos2 + data[(pos + i + window_half) & mask]];
101
+ ++in_window_utf8[utf8_pos2];
102
+ }
103
+ {
104
+ size_t c = i < 1 ? 0 : data[(pos + i - 1) & mask];
105
+ size_t last_c = i < 2 ? 0 : data[(pos + i - 2) & mask];
106
+ size_t utf8_pos = UTF8Position(last_c, c, max_utf8);
107
+ size_t masked_pos = (pos + i) & mask;
108
+ size_t histo = histogram[256 * utf8_pos + data[masked_pos]];
109
+ double lit_cost;
110
+ if (histo == 0) {
111
+ histo = 1;
112
+ }
113
+ lit_cost = FastLog2(in_window_utf8[utf8_pos]) - FastLog2(histo);
114
+ lit_cost += 0.02905;
115
+ if (lit_cost < 1.0) {
116
+ lit_cost *= 0.5;
117
+ lit_cost += 0.5;
118
+ }
119
+ /* Make the first bytes more expensive -- seems to help, not sure why.
120
+ Perhaps because the entropy source is changing its properties
121
+ rapidly in the beginning of the file, perhaps because the beginning
122
+ of the data is a statistical "anomaly". */
123
+ if (i < 2000) {
124
+ lit_cost += 0.7 - ((double)(2000 - i) / 2000.0 * 0.35);
125
+ }
126
+ cost[i] = (float)lit_cost;
127
+ }
128
+ }
129
+ }
130
+
131
+ void BrotliEstimateBitCostsForLiterals(size_t pos, size_t len, size_t mask,
132
+ const uint8_t* data,
133
+ size_t* histogram, float* cost) {
134
+ if (BrotliIsMostlyUTF8(data, pos, mask, len, kMinUTF8Ratio)) {
135
+ EstimateBitCostsForLiteralsUTF8(pos, len, mask, data, histogram, cost);
136
+ return;
137
+ } else {
138
+ size_t window_half = 2000;
139
+ size_t in_window = BROTLI_MIN(size_t, window_half, len);
140
+ size_t i;
141
+ memset(histogram, 0, 256 * sizeof(histogram[0]));
142
+
143
+ /* Bootstrap histogram. */
144
+ for (i = 0; i < in_window; ++i) {
145
+ ++histogram[data[(pos + i) & mask]];
146
+ }
147
+
148
+ /* Compute bit costs with sliding window. */
149
+ for (i = 0; i < len; ++i) {
150
+ size_t histo;
151
+ if (i >= window_half) {
152
+ /* Remove a byte in the past. */
153
+ --histogram[data[(pos + i - window_half) & mask]];
154
+ --in_window;
155
+ }
156
+ if (i + window_half < len) {
157
+ /* Add a byte in the future. */
158
+ ++histogram[data[(pos + i + window_half) & mask]];
159
+ ++in_window;
160
+ }
161
+ histo = histogram[data[(pos + i) & mask]];
162
+ if (histo == 0) {
163
+ histo = 1;
164
+ }
165
+ {
166
+ double lit_cost = FastLog2(in_window) - FastLog2(histo);
167
+ lit_cost += 0.029;
168
+ if (lit_cost < 1.0) {
169
+ lit_cost *= 0.5;
170
+ lit_cost += 0.5;
171
+ }
172
+ cost[i] = (float)lit_cost;
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ #if defined(__cplusplus) || defined(c_plusplus)
179
+ } /* extern "C" */
180
+ #endif
@@ -0,0 +1,32 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Literal cost model to allow backward reference replacement to be efficient.
8
+ */
9
+
10
+ #ifndef BROTLI_ENC_LITERAL_COST_H_
11
+ #define BROTLI_ENC_LITERAL_COST_H_
12
+
13
+ #include <brotli/types.h>
14
+
15
+ #include "../common/platform.h"
16
+
17
+ #if defined(__cplusplus) || defined(c_plusplus)
18
+ extern "C" {
19
+ #endif
20
+
21
+ /* Estimates how many bits the literals in the interval [pos, pos + len) in the
22
+ ring-buffer (data, mask) will take entropy coded and writes these estimates
23
+ to the cost[0..len) array. */
24
+ BROTLI_INTERNAL void BrotliEstimateBitCostsForLiterals(
25
+ size_t pos, size_t len, size_t mask, const uint8_t* data, size_t* histogram,
26
+ float* cost);
27
+
28
+ #if defined(__cplusplus) || defined(c_plusplus)
29
+ } /* extern "C" */
30
+ #endif
31
+
32
+ #endif /* BROTLI_ENC_LITERAL_COST_H_ */
@@ -0,0 +1,194 @@
1
+ /* Copyright 2015 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Algorithms for distributing the literals and commands of a metablock between
8
+ block types and contexts. */
9
+
10
+ #include "memory.h"
11
+
12
+ #include <stdlib.h> /* exit, free, malloc */
13
+ #include <string.h> /* memcpy */
14
+
15
+ #include <brotli/types.h>
16
+
17
+ #include "../common/platform.h"
18
+
19
+ #if defined(__cplusplus) || defined(c_plusplus)
20
+ extern "C" {
21
+ #endif
22
+
23
+ #define MAX_NEW_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
24
+ #define MAX_NEW_FREED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
25
+ #define MAX_PERM_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 1)
26
+
27
+ #define PERM_ALLOCATED_OFFSET 0
28
+ #define NEW_ALLOCATED_OFFSET MAX_PERM_ALLOCATED
29
+ #define NEW_FREED_OFFSET (MAX_PERM_ALLOCATED + MAX_NEW_ALLOCATED)
30
+
31
+ void BrotliInitMemoryManager(
32
+ MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
33
+ void* opaque) {
34
+ if (!alloc_func) {
35
+ m->alloc_func = BrotliDefaultAllocFunc;
36
+ m->free_func = BrotliDefaultFreeFunc;
37
+ m->opaque = 0;
38
+ } else {
39
+ m->alloc_func = alloc_func;
40
+ m->free_func = free_func;
41
+ m->opaque = opaque;
42
+ }
43
+ #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
44
+ m->is_oom = BROTLI_FALSE;
45
+ m->perm_allocated = 0;
46
+ m->new_allocated = 0;
47
+ m->new_freed = 0;
48
+ #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
49
+ }
50
+
51
+ #if defined(BROTLI_ENCODER_EXIT_ON_OOM)
52
+
53
+ void* BrotliAllocate(MemoryManager* m, size_t n) {
54
+ void* result = m->alloc_func(m->opaque, n);
55
+ if (!result) exit(EXIT_FAILURE);
56
+ return result;
57
+ }
58
+
59
+ void BrotliFree(MemoryManager* m, void* p) {
60
+ m->free_func(m->opaque, p);
61
+ }
62
+
63
+ void BrotliWipeOutMemoryManager(MemoryManager* m) {
64
+ BROTLI_UNUSED(m);
65
+ }
66
+
67
+ #else /* BROTLI_ENCODER_EXIT_ON_OOM */
68
+
69
+ static void SortPointers(void** items, const size_t n) {
70
+ /* Shell sort. */
71
+ /* TODO(eustas): fine-tune for "many slots" case */
72
+ static const size_t gaps[] = {23, 10, 4, 1};
73
+ int g = 0;
74
+ for (; g < 4; ++g) {
75
+ size_t gap = gaps[g];
76
+ size_t i;
77
+ for (i = gap; i < n; ++i) {
78
+ size_t j = i;
79
+ void* tmp = items[i];
80
+ for (; j >= gap && tmp < items[j - gap]; j -= gap) {
81
+ items[j] = items[j - gap];
82
+ }
83
+ items[j] = tmp;
84
+ }
85
+ }
86
+ }
87
+
88
+ static size_t Annihilate(void** a, size_t a_len, void** b, size_t b_len) {
89
+ size_t a_read_index = 0;
90
+ size_t b_read_index = 0;
91
+ size_t a_write_index = 0;
92
+ size_t b_write_index = 0;
93
+ size_t annihilated = 0;
94
+ while (a_read_index < a_len && b_read_index < b_len) {
95
+ if (a[a_read_index] == b[b_read_index]) {
96
+ a_read_index++;
97
+ b_read_index++;
98
+ annihilated++;
99
+ } else if (a[a_read_index] < b[b_read_index]) {
100
+ a[a_write_index++] = a[a_read_index++];
101
+ } else {
102
+ b[b_write_index++] = b[b_read_index++];
103
+ }
104
+ }
105
+ while (a_read_index < a_len) a[a_write_index++] = a[a_read_index++];
106
+ while (b_read_index < b_len) b[b_write_index++] = b[b_read_index++];
107
+ return annihilated;
108
+ }
109
+
110
+ static void CollectGarbagePointers(MemoryManager* m) {
111
+ size_t annihilated;
112
+ SortPointers(m->pointers + NEW_ALLOCATED_OFFSET, m->new_allocated);
113
+ SortPointers(m->pointers + NEW_FREED_OFFSET, m->new_freed);
114
+ annihilated = Annihilate(
115
+ m->pointers + NEW_ALLOCATED_OFFSET, m->new_allocated,
116
+ m->pointers + NEW_FREED_OFFSET, m->new_freed);
117
+ m->new_allocated -= annihilated;
118
+ m->new_freed -= annihilated;
119
+
120
+ if (m->new_freed != 0) {
121
+ annihilated = Annihilate(
122
+ m->pointers + PERM_ALLOCATED_OFFSET, m->perm_allocated,
123
+ m->pointers + NEW_FREED_OFFSET, m->new_freed);
124
+ m->perm_allocated -= annihilated;
125
+ m->new_freed -= annihilated;
126
+ BROTLI_DCHECK(m->new_freed == 0);
127
+ }
128
+
129
+ if (m->new_allocated != 0) {
130
+ BROTLI_DCHECK(m->perm_allocated + m->new_allocated <= MAX_PERM_ALLOCATED);
131
+ memcpy(m->pointers + PERM_ALLOCATED_OFFSET + m->perm_allocated,
132
+ m->pointers + NEW_ALLOCATED_OFFSET,
133
+ sizeof(void*) * m->new_allocated);
134
+ m->perm_allocated += m->new_allocated;
135
+ m->new_allocated = 0;
136
+ SortPointers(m->pointers + PERM_ALLOCATED_OFFSET, m->perm_allocated);
137
+ }
138
+ }
139
+
140
+ void* BrotliAllocate(MemoryManager* m, size_t n) {
141
+ void* result = m->alloc_func(m->opaque, n);
142
+ if (!result) {
143
+ m->is_oom = BROTLI_TRUE;
144
+ return NULL;
145
+ }
146
+ if (m->new_allocated == MAX_NEW_ALLOCATED) CollectGarbagePointers(m);
147
+ m->pointers[NEW_ALLOCATED_OFFSET + (m->new_allocated++)] = result;
148
+ return result;
149
+ }
150
+
151
+ void BrotliFree(MemoryManager* m, void* p) {
152
+ if (!p) return;
153
+ m->free_func(m->opaque, p);
154
+ if (m->new_freed == MAX_NEW_FREED) CollectGarbagePointers(m);
155
+ m->pointers[NEW_FREED_OFFSET + (m->new_freed++)] = p;
156
+ }
157
+
158
+ void BrotliWipeOutMemoryManager(MemoryManager* m) {
159
+ size_t i;
160
+ CollectGarbagePointers(m);
161
+ /* Now all unfreed pointers are in perm-allocated list. */
162
+ for (i = 0; i < m->perm_allocated; ++i) {
163
+ m->free_func(m->opaque, m->pointers[PERM_ALLOCATED_OFFSET + i]);
164
+ }
165
+ m->perm_allocated = 0;
166
+ }
167
+
168
+ #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
169
+
170
+ void* BrotliBootstrapAlloc(size_t size,
171
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
172
+ if (!alloc_func && !free_func) {
173
+ return malloc(size);
174
+ } else if (alloc_func && free_func) {
175
+ return alloc_func(opaque, size);
176
+ }
177
+ return NULL;
178
+ }
179
+
180
+ void BrotliBootstrapFree(void* address, MemoryManager* m) {
181
+ if (!address) {
182
+ /* Should not happen! */
183
+ return;
184
+ } else {
185
+ /* Copy values, as those would be freed. */
186
+ brotli_free_func free_func = m->free_func;
187
+ void* opaque = m->opaque;
188
+ free_func(opaque, address);
189
+ }
190
+ }
191
+
192
+ #if defined(__cplusplus) || defined(c_plusplus)
193
+ } /* extern "C" */
194
+ #endif
@@ -0,0 +1,131 @@
1
+ /* Copyright 2016 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Macros for memory management. */
8
+
9
+ #ifndef BROTLI_ENC_MEMORY_H_
10
+ #define BROTLI_ENC_MEMORY_H_
11
+
12
+ #include <string.h> /* memcpy */
13
+
14
+ #include <brotli/types.h>
15
+
16
+ #include "../common/platform.h"
17
+
18
+ #if defined(__cplusplus) || defined(c_plusplus)
19
+ extern "C" {
20
+ #endif
21
+
22
+ #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
23
+ !defined(BROTLI_ENCODER_EXIT_ON_OOM)
24
+ #define BROTLI_ENCODER_EXIT_ON_OOM
25
+ #endif
26
+
27
+ #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
28
+ #if defined(BROTLI_EXPERIMENTAL)
29
+ #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS (48*1024)
30
+ #else /* BROTLI_EXPERIMENTAL */
31
+ #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
32
+ #endif /* BROTLI_EXPERIMENTAL */
33
+ #else /* BROTLI_ENCODER_EXIT_ON_OOM */
34
+ #define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 0
35
+ #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
36
+
37
+ typedef struct MemoryManager {
38
+ brotli_alloc_func alloc_func;
39
+ brotli_free_func free_func;
40
+ void* opaque;
41
+ #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
42
+ BROTLI_BOOL is_oom;
43
+ size_t perm_allocated;
44
+ size_t new_allocated;
45
+ size_t new_freed;
46
+ void* pointers[BROTLI_ENCODER_MEMORY_MANAGER_SLOTS];
47
+ #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
48
+ } MemoryManager;
49
+
50
+ BROTLI_INTERNAL void BrotliInitMemoryManager(
51
+ MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
52
+ void* opaque);
53
+
54
+ BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);
55
+ #define BROTLI_ALLOC(M, T, N) \
56
+ ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULL)
57
+
58
+ BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
59
+ #define BROTLI_FREE(M, P) { \
60
+ BrotliFree((M), (P)); \
61
+ P = NULL; \
62
+ }
63
+
64
+ #if defined(BROTLI_ENCODER_EXIT_ON_OOM)
65
+ #define BROTLI_IS_OOM(M) (!!0)
66
+ #else /* BROTLI_ENCODER_EXIT_ON_OOM */
67
+ #define BROTLI_IS_OOM(M) (!!(M)->is_oom)
68
+ #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
69
+
70
+ /*
71
+ BROTLI_IS_NULL is a fake check, BROTLI_IS_OOM does the heavy lifting.
72
+ The only purpose of it is to explain static analyzers the state of things.
73
+ NB: use ONLY together with BROTLI_IS_OOM
74
+ AND ONLY for allocations in the current scope.
75
+ */
76
+ #if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
77
+ #define BROTLI_IS_NULL(A) ((A) == nullptr)
78
+ #else /* defined(__clang_analyzer__) */
79
+ #define BROTLI_IS_NULL(A) (!!0)
80
+ #endif /* defined(__clang_analyzer__) */
81
+
82
+ BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
83
+
84
+ /*
85
+ Dynamically grows array capacity to at least the requested size
86
+ M: MemoryManager
87
+ T: data type
88
+ A: array
89
+ C: capacity
90
+ R: requested size
91
+ */
92
+ #define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
93
+ if (C < (R)) { \
94
+ size_t _new_size = (C == 0) ? (R) : C; \
95
+ T* new_array; \
96
+ while (_new_size < (R)) _new_size *= 2; \
97
+ new_array = BROTLI_ALLOC((M), T, _new_size); \
98
+ if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
99
+ memcpy(new_array, A, C * sizeof(T)); \
100
+ BROTLI_FREE((M), A); \
101
+ A = new_array; \
102
+ C = _new_size; \
103
+ } \
104
+ }
105
+
106
+ /*
107
+ Appends value and dynamically grows array capacity when needed
108
+ M: MemoryManager
109
+ T: data type
110
+ A: array
111
+ C: array capacity
112
+ S: array size
113
+ V: value to append
114
+ */
115
+ #define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \
116
+ (S)++; \
117
+ BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \
118
+ A[(S) - 1] = (V); \
119
+ }
120
+
121
+ /* "Bootstrap" allocations are not tracked by memory manager; should be used
122
+ only to allocate MemoryManager itself (or structure containing it). */
123
+ BROTLI_INTERNAL void* BrotliBootstrapAlloc(size_t size,
124
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
125
+ BROTLI_INTERNAL void BrotliBootstrapFree(void* address, MemoryManager* m);
126
+
127
+ #if defined(__cplusplus) || defined(c_plusplus)
128
+ } /* extern "C" */
129
+ #endif
130
+
131
+ #endif /* BROTLI_ENC_MEMORY_H_ */