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,96 @@
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
+ /* Function to find backward reference copies. */
8
+
9
+ #ifndef BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
10
+ #define BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
11
+
12
+ #include <brotli/types.h>
13
+
14
+ #include "../common/constants.h"
15
+ #include "../common/context.h"
16
+ #include "../common/dictionary.h"
17
+ #include "../common/platform.h"
18
+ #include "command.h"
19
+ #include "hash.h"
20
+ #include "memory.h"
21
+ #include "quality.h"
22
+
23
+ #if defined(__cplusplus) || defined(c_plusplus)
24
+ extern "C" {
25
+ #endif
26
+
27
+ BROTLI_INTERNAL void BrotliCreateZopfliBackwardReferences(MemoryManager* m,
28
+ size_t num_bytes,
29
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
30
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
31
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
32
+ Command* commands, size_t* num_commands, size_t* num_literals);
33
+
34
+ BROTLI_INTERNAL void BrotliCreateHqZopfliBackwardReferences(MemoryManager* m,
35
+ size_t num_bytes,
36
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
37
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
38
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
39
+ Command* commands, size_t* num_commands, size_t* num_literals);
40
+
41
+ typedef struct ZopfliNode {
42
+ /* Best length to get up to this byte (not including this byte itself)
43
+ highest 7 bit is used to reconstruct the length code. */
44
+ uint32_t length;
45
+ /* Distance associated with the length. */
46
+ uint32_t distance;
47
+ /* Number of literal inserts before this copy; highest 5 bits contain
48
+ distance short code + 1 (or zero if no short code). */
49
+ uint32_t dcode_insert_length;
50
+
51
+ /* This union holds information used by dynamic-programming. During forward
52
+ pass |cost| it used to store the goal function. When node is processed its
53
+ |cost| is invalidated in favor of |shortcut|. On path back-tracing pass
54
+ |next| is assigned the offset to next node on the path. */
55
+ union {
56
+ /* Smallest cost to get to this byte from the beginning, as found so far. */
57
+ float cost;
58
+ /* Offset to the next node on the path. Equals to command_length() of the
59
+ next node on the path. For last node equals to BROTLI_UINT32_MAX */
60
+ uint32_t next;
61
+ /* Node position that provides next distance for distance cache. */
62
+ uint32_t shortcut;
63
+ } u;
64
+ } ZopfliNode;
65
+
66
+ BROTLI_INTERNAL void BrotliInitZopfliNodes(ZopfliNode* array, size_t length);
67
+
68
+ /* Computes the shortest path of commands from position to at most
69
+ position + num_bytes.
70
+
71
+ On return, path->size() is the number of commands found and path[i] is the
72
+ length of the i-th command (copy length plus insert length).
73
+ Note that the sum of the lengths of all commands can be less than num_bytes.
74
+
75
+ On return, the nodes[0..num_bytes] array will have the following
76
+ "ZopfliNode array invariant":
77
+ For each i in [1..num_bytes], if nodes[i].cost < kInfinity, then
78
+ (1) nodes[i].copy_length() >= 2
79
+ (2) nodes[i].command_length() <= i and
80
+ (3) nodes[i - nodes[i].command_length()].cost < kInfinity */
81
+ BROTLI_INTERNAL size_t BrotliZopfliComputeShortestPath(
82
+ MemoryManager* m, size_t num_bytes,
83
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
84
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
85
+ const int* dist_cache, Hasher* hasher, ZopfliNode* nodes);
86
+
87
+ BROTLI_INTERNAL void BrotliZopfliCreateCommands(
88
+ const size_t num_bytes, const size_t block_start, const ZopfliNode* nodes,
89
+ int* dist_cache, size_t* last_insert_len, const BrotliEncoderParams* params,
90
+ Command* commands, size_t* num_literals);
91
+
92
+ #if defined(__cplusplus) || defined(c_plusplus)
93
+ } /* extern "C" */
94
+ #endif
95
+
96
+ #endif /* BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_ */
@@ -0,0 +1,189 @@
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: EXPORT_FN, FN */
9
+
10
+ static BROTLI_NOINLINE void EXPORT_FN(CreateBackwardReferences)(
11
+ size_t num_bytes, size_t position,
12
+ const uint8_t* ringbuffer, size_t ringbuffer_mask,
13
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
14
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
15
+ Command* commands, size_t* num_commands, size_t* num_literals) {
16
+ HASHER()* privat = &hasher->privat.FN(_);
17
+ /* Set maximum distance, see section 9.1. of the spec. */
18
+ const size_t max_backward_limit = BROTLI_MAX_BACKWARD_LIMIT(params->lgwin);
19
+ const size_t position_offset = params->stream_offset;
20
+
21
+ const Command* const orig_commands = commands;
22
+ size_t insert_length = *last_insert_len;
23
+ const size_t pos_end = position + num_bytes;
24
+ const size_t store_end = num_bytes >= FN(StoreLookahead)() ?
25
+ position + num_bytes - FN(StoreLookahead)() + 1 : position;
26
+
27
+ /* For speed up heuristics for random data. */
28
+ const size_t random_heuristics_window_size =
29
+ LiteralSpreeLengthForSparseSearch(params);
30
+ size_t apply_random_heuristics = position + random_heuristics_window_size;
31
+ const size_t gap = params->dictionary.compound.total_size;
32
+
33
+ /* Minimum score to accept a backward reference. */
34
+ const score_t kMinScore = BROTLI_SCORE_BASE + 100;
35
+
36
+ FN(PrepareDistanceCache)(privat, dist_cache);
37
+
38
+ while (position + FN(HashTypeLength)() < pos_end) {
39
+ size_t max_length = pos_end - position;
40
+ size_t max_distance = BROTLI_MIN(size_t, position, max_backward_limit);
41
+ size_t dictionary_start = BROTLI_MIN(size_t,
42
+ position + position_offset, max_backward_limit);
43
+ HasherSearchResult sr;
44
+ int dict_id = 0;
45
+ uint8_t p1 = 0;
46
+ uint8_t p2 = 0;
47
+ if (params->dictionary.contextual.context_based) {
48
+ p1 = position >= 1 ?
49
+ ringbuffer[(size_t)(position - 1) & ringbuffer_mask] : 0;
50
+ p2 = position >= 2 ?
51
+ ringbuffer[(size_t)(position - 2) & ringbuffer_mask] : 0;
52
+ dict_id = params->dictionary.contextual.context_map[
53
+ BROTLI_CONTEXT(p1, p2, literal_context_lut)];
54
+ }
55
+ sr.len = 0;
56
+ sr.len_code_delta = 0;
57
+ sr.distance = 0;
58
+ sr.score = kMinScore;
59
+ FN(FindLongestMatch)(privat, params->dictionary.contextual.dict[dict_id],
60
+ ringbuffer, ringbuffer_mask, dist_cache, position, max_length,
61
+ max_distance, dictionary_start + gap, params->dist.max_distance, &sr);
62
+ if (ENABLE_COMPOUND_DICTIONARY) {
63
+ LookupCompoundDictionaryMatch(&params->dictionary.compound, ringbuffer,
64
+ ringbuffer_mask, dist_cache, position, max_length,
65
+ dictionary_start, params->dist.max_distance, &sr);
66
+ }
67
+ if (sr.score > kMinScore) {
68
+ /* Found a match. Let's look for something even better ahead. */
69
+ int delayed_backward_references_in_row = 0;
70
+ --max_length;
71
+ for (;; --max_length) {
72
+ const score_t cost_diff_lazy = 175;
73
+ HasherSearchResult sr2;
74
+ sr2.len = params->quality < MIN_QUALITY_FOR_EXTENSIVE_REFERENCE_SEARCH ?
75
+ BROTLI_MIN(size_t, sr.len - 1, max_length) : 0;
76
+ sr2.len_code_delta = 0;
77
+ sr2.distance = 0;
78
+ sr2.score = kMinScore;
79
+ max_distance = BROTLI_MIN(size_t, position + 1, max_backward_limit);
80
+ dictionary_start = BROTLI_MIN(size_t,
81
+ position + 1 + position_offset, max_backward_limit);
82
+ if (params->dictionary.contextual.context_based) {
83
+ p2 = p1;
84
+ p1 = ringbuffer[position & ringbuffer_mask];
85
+ dict_id = params->dictionary.contextual.context_map[
86
+ BROTLI_CONTEXT(p1, p2, literal_context_lut)];
87
+ }
88
+ FN(FindLongestMatch)(privat,
89
+ params->dictionary.contextual.dict[dict_id],
90
+ ringbuffer, ringbuffer_mask, dist_cache, position + 1, max_length,
91
+ max_distance, dictionary_start + gap, params->dist.max_distance,
92
+ &sr2);
93
+ if (ENABLE_COMPOUND_DICTIONARY) {
94
+ LookupCompoundDictionaryMatch(
95
+ &params->dictionary.compound, ringbuffer,
96
+ ringbuffer_mask, dist_cache, position + 1, max_length,
97
+ dictionary_start, params->dist.max_distance, &sr2);
98
+ }
99
+ if (sr2.score >= sr.score + cost_diff_lazy) {
100
+ /* Ok, let's just write one byte for now and start a match from the
101
+ next byte. */
102
+ ++position;
103
+ ++insert_length;
104
+ sr = sr2;
105
+ if (++delayed_backward_references_in_row < 4 &&
106
+ position + FN(HashTypeLength)() < pos_end) {
107
+ continue;
108
+ }
109
+ }
110
+ break;
111
+ }
112
+ apply_random_heuristics =
113
+ position + 2 * sr.len + random_heuristics_window_size;
114
+ dictionary_start = BROTLI_MIN(size_t,
115
+ position + position_offset, max_backward_limit);
116
+ {
117
+ /* The first 16 codes are special short-codes,
118
+ and the minimum offset is 1. */
119
+ size_t distance_code = ComputeDistanceCode(
120
+ sr.distance, dictionary_start + gap, dist_cache);
121
+ if ((sr.distance <= (dictionary_start + gap)) && distance_code > 0) {
122
+ dist_cache[3] = dist_cache[2];
123
+ dist_cache[2] = dist_cache[1];
124
+ dist_cache[1] = dist_cache[0];
125
+ dist_cache[0] = (int)sr.distance;
126
+ FN(PrepareDistanceCache)(privat, dist_cache);
127
+ }
128
+ InitCommand(commands++, &params->dist, insert_length,
129
+ sr.len, sr.len_code_delta, distance_code);
130
+ }
131
+ *num_literals += insert_length;
132
+ insert_length = 0;
133
+ /* Put the hash keys into the table, if there are enough bytes left.
134
+ Depending on the hasher implementation, it can push all positions
135
+ in the given range or only a subset of them.
136
+ Avoid hash poisoning with RLE data. */
137
+ {
138
+ size_t range_start = position + 2;
139
+ size_t range_end = BROTLI_MIN(size_t, position + sr.len, store_end);
140
+ if (sr.distance < (sr.len >> 2)) {
141
+ range_start = BROTLI_MIN(size_t, range_end, BROTLI_MAX(size_t,
142
+ range_start, position + sr.len - (sr.distance << 2)));
143
+ }
144
+ FN(StoreRange)(privat, ringbuffer, ringbuffer_mask, range_start,
145
+ range_end);
146
+ }
147
+ position += sr.len;
148
+ } else {
149
+ ++insert_length;
150
+ ++position;
151
+ /* If we have not seen matches for a long time, we can skip some
152
+ match lookups. Unsuccessful match lookups are very very expensive
153
+ and this kind of a heuristic speeds up compression quite
154
+ a lot. */
155
+ if (position > apply_random_heuristics) {
156
+ /* Going through uncompressible data, jump. */
157
+ if (position >
158
+ apply_random_heuristics + 4 * random_heuristics_window_size) {
159
+ /* It is quite a long time since we saw a copy, so we assume
160
+ that this data is not compressible, and store hashes less
161
+ often. Hashes of non compressible data are less likely to
162
+ turn out to be useful in the future, too, so we store less of
163
+ them to not to flood out the hash table of good compressible
164
+ data. */
165
+ const size_t kMargin =
166
+ BROTLI_MAX(size_t, FN(StoreLookahead)() - 1, 4);
167
+ size_t pos_jump =
168
+ BROTLI_MIN(size_t, position + 16, pos_end - kMargin);
169
+ for (; position < pos_jump; position += 4) {
170
+ FN(Store)(privat, ringbuffer, ringbuffer_mask, position);
171
+ insert_length += 4;
172
+ }
173
+ } else {
174
+ const size_t kMargin =
175
+ BROTLI_MAX(size_t, FN(StoreLookahead)() - 1, 2);
176
+ size_t pos_jump =
177
+ BROTLI_MIN(size_t, position + 8, pos_end - kMargin);
178
+ for (; position < pos_jump; position += 2) {
179
+ FN(Store)(privat, ringbuffer, ringbuffer_mask, position);
180
+ insert_length += 2;
181
+ }
182
+ }
183
+ }
184
+ }
185
+ }
186
+ insert_length += pos_end - position;
187
+ *last_insert_len = insert_length;
188
+ *num_commands += (size_t)(commands - orig_commands);
189
+ }
@@ -0,0 +1,36 @@
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
+ /* Functions to estimate the bit cost of Huffman trees. */
8
+
9
+ #include "bit_cost.h"
10
+
11
+ #include <brotli/types.h>
12
+
13
+ #include "../common/constants.h"
14
+ #include "../common/platform.h"
15
+ #include "fast_log.h"
16
+ #include "histogram.h"
17
+
18
+ #if defined(__cplusplus) || defined(c_plusplus)
19
+ extern "C" {
20
+ #endif
21
+
22
+ #define FN(X) X ## Literal
23
+ #include "bit_cost_inc.h" /* NOLINT(build/include) */
24
+ #undef FN
25
+
26
+ #define FN(X) X ## Command
27
+ #include "bit_cost_inc.h" /* NOLINT(build/include) */
28
+ #undef FN
29
+
30
+ #define FN(X) X ## Distance
31
+ #include "bit_cost_inc.h" /* NOLINT(build/include) */
32
+ #undef FN
33
+
34
+ #if defined(__cplusplus) || defined(c_plusplus)
35
+ } /* extern "C" */
36
+ #endif
@@ -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
+ /* Functions to estimate the bit cost of Huffman trees. */
8
+
9
+ #ifndef BROTLI_ENC_BIT_COST_H_
10
+ #define BROTLI_ENC_BIT_COST_H_
11
+
12
+ #include <brotli/types.h>
13
+
14
+ #include "../common/platform.h"
15
+ #include "fast_log.h"
16
+ #include "histogram.h"
17
+
18
+ #if defined(__cplusplus) || defined(c_plusplus)
19
+ extern "C" {
20
+ #endif
21
+
22
+ static BROTLI_INLINE double ShannonEntropy(
23
+ const uint32_t* population, size_t size, size_t* total) {
24
+ size_t sum = 0;
25
+ double retval = 0;
26
+ const uint32_t* population_end = population + size;
27
+ size_t p;
28
+ if (size & 1) {
29
+ goto odd_number_of_elements_left;
30
+ }
31
+ while (population < population_end) {
32
+ p = *population++;
33
+ sum += p;
34
+ retval -= (double)p * FastLog2(p);
35
+ odd_number_of_elements_left:
36
+ p = *population++;
37
+ sum += p;
38
+ retval -= (double)p * FastLog2(p);
39
+ }
40
+ if (sum) retval += (double)sum * FastLog2(sum);
41
+ *total = sum;
42
+ return retval;
43
+ }
44
+
45
+ static BROTLI_INLINE double BitsEntropy(
46
+ const uint32_t* population, size_t size) {
47
+ size_t sum;
48
+ double retval = ShannonEntropy(population, size, &sum);
49
+ if (retval < (double)sum) {
50
+ /* At least one bit per literal is needed. */
51
+ retval = (double)sum;
52
+ }
53
+ return retval;
54
+ }
55
+
56
+ BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*);
57
+ BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*);
58
+ BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*);
59
+
60
+ #if defined(__cplusplus) || defined(c_plusplus)
61
+ } /* extern "C" */
62
+ #endif
63
+
64
+ #endif /* BROTLI_ENC_BIT_COST_H_ */
@@ -0,0 +1,127 @@
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: FN */
9
+
10
+ #define HistogramType FN(Histogram)
11
+
12
+ double FN(BrotliPopulationCost)(const HistogramType* histogram) {
13
+ static const double kOneSymbolHistogramCost = 12;
14
+ static const double kTwoSymbolHistogramCost = 20;
15
+ static const double kThreeSymbolHistogramCost = 28;
16
+ static const double kFourSymbolHistogramCost = 37;
17
+ const size_t data_size = FN(HistogramDataSize)();
18
+ int count = 0;
19
+ size_t s[5];
20
+ double bits = 0.0;
21
+ size_t i;
22
+ if (histogram->total_count_ == 0) {
23
+ return kOneSymbolHistogramCost;
24
+ }
25
+ for (i = 0; i < data_size; ++i) {
26
+ if (histogram->data_[i] > 0) {
27
+ s[count] = i;
28
+ ++count;
29
+ if (count > 4) break;
30
+ }
31
+ }
32
+ if (count == 1) {
33
+ return kOneSymbolHistogramCost;
34
+ }
35
+ if (count == 2) {
36
+ return (kTwoSymbolHistogramCost + (double)histogram->total_count_);
37
+ }
38
+ if (count == 3) {
39
+ const uint32_t histo0 = histogram->data_[s[0]];
40
+ const uint32_t histo1 = histogram->data_[s[1]];
41
+ const uint32_t histo2 = histogram->data_[s[2]];
42
+ const uint32_t histomax =
43
+ BROTLI_MAX(uint32_t, histo0, BROTLI_MAX(uint32_t, histo1, histo2));
44
+ return (kThreeSymbolHistogramCost +
45
+ 2 * (histo0 + histo1 + histo2) - histomax);
46
+ }
47
+ if (count == 4) {
48
+ uint32_t histo[4];
49
+ uint32_t h23;
50
+ uint32_t histomax;
51
+ for (i = 0; i < 4; ++i) {
52
+ histo[i] = histogram->data_[s[i]];
53
+ }
54
+ /* Sort */
55
+ for (i = 0; i < 4; ++i) {
56
+ size_t j;
57
+ for (j = i + 1; j < 4; ++j) {
58
+ if (histo[j] > histo[i]) {
59
+ BROTLI_SWAP(uint32_t, histo, j, i);
60
+ }
61
+ }
62
+ }
63
+ h23 = histo[2] + histo[3];
64
+ histomax = BROTLI_MAX(uint32_t, h23, histo[0]);
65
+ return (kFourSymbolHistogramCost +
66
+ 3 * h23 + 2 * (histo[0] + histo[1]) - histomax);
67
+ }
68
+
69
+ {
70
+ /* In this loop we compute the entropy of the histogram and simultaneously
71
+ build a simplified histogram of the code length codes where we use the
72
+ zero repeat code 17, but we don't use the non-zero repeat code 16. */
73
+ size_t max_depth = 1;
74
+ uint32_t depth_histo[BROTLI_CODE_LENGTH_CODES] = { 0 };
75
+ const double log2total = FastLog2(histogram->total_count_);
76
+ for (i = 0; i < data_size;) {
77
+ if (histogram->data_[i] > 0) {
78
+ /* Compute -log2(P(symbol)) = -log2(count(symbol)/total_count) =
79
+ = log2(total_count) - log2(count(symbol)) */
80
+ double log2p = log2total - FastLog2(histogram->data_[i]);
81
+ /* Approximate the bit depth by round(-log2(P(symbol))) */
82
+ size_t depth = (size_t)(log2p + 0.5);
83
+ bits += histogram->data_[i] * log2p;
84
+ if (depth > 15) {
85
+ depth = 15;
86
+ }
87
+ if (depth > max_depth) {
88
+ max_depth = depth;
89
+ }
90
+ ++depth_histo[depth];
91
+ ++i;
92
+ } else {
93
+ /* Compute the run length of zeros and add the appropriate number of 0
94
+ and 17 code length codes to the code length code histogram. */
95
+ uint32_t reps = 1;
96
+ size_t k;
97
+ for (k = i + 1; k < data_size && histogram->data_[k] == 0; ++k) {
98
+ ++reps;
99
+ }
100
+ i += reps;
101
+ if (i == data_size) {
102
+ /* Don't add any cost for the last zero run, since these are encoded
103
+ only implicitly. */
104
+ break;
105
+ }
106
+ if (reps < 3) {
107
+ depth_histo[0] += reps;
108
+ } else {
109
+ reps -= 2;
110
+ while (reps > 0) {
111
+ ++depth_histo[BROTLI_REPEAT_ZERO_CODE_LENGTH];
112
+ /* Add the 3 extra bits for the 17 code length code. */
113
+ bits += 3;
114
+ reps >>= 3;
115
+ }
116
+ }
117
+ }
118
+ }
119
+ /* Add the estimated encoding cost of the code length code histogram. */
120
+ bits += (double)(18 + 2 * max_depth);
121
+ /* Add the entropy of the code length code histogram. */
122
+ bits += BitsEntropy(depth_histo, BROTLI_CODE_LENGTH_CODES);
123
+ }
124
+ return bits;
125
+ }
126
+
127
+ #undef HistogramType
@@ -0,0 +1,34 @@
1
+ /* NOLINT(build/header_guard) */
2
+ /* Copyright 2014 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: FN */
9
+
10
+ #define HistogramType FN(Histogram)
11
+
12
+ /* Creates entropy codes for all block types and stores them to the bit
13
+ stream. */
14
+ static void FN(BuildAndStoreEntropyCodes)(MemoryManager* m, BlockEncoder* self,
15
+ const HistogramType* histograms, const size_t histograms_size,
16
+ const size_t alphabet_size, HuffmanTree* tree,
17
+ size_t* storage_ix, uint8_t* storage) {
18
+ const size_t table_size = histograms_size * self->histogram_length_;
19
+ self->depths_ = BROTLI_ALLOC(m, uint8_t, table_size);
20
+ self->bits_ = BROTLI_ALLOC(m, uint16_t, table_size);
21
+ if (BROTLI_IS_OOM(m)) return;
22
+
23
+ {
24
+ size_t i;
25
+ for (i = 0; i < histograms_size; ++i) {
26
+ size_t ix = i * self->histogram_length_;
27
+ BuildAndStoreHuffmanTree(&histograms[i].data_[0], self->histogram_length_,
28
+ alphabet_size, tree, &self->depths_[ix], &self->bits_[ix],
29
+ storage_ix, storage);
30
+ }
31
+ }
32
+ }
33
+
34
+ #undef HistogramType