hdiffpatch 1.0.0__cp310-cp310-win32.whl

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 (2254) hide show
  1. hdiffpatch/__init__.py +67 -0
  2. hdiffpatch/_base_config.py +56 -0
  3. hdiffpatch/_bzip2_config.py +102 -0
  4. hdiffpatch/_c_extension.cp310-win32.pyd +0 -0
  5. hdiffpatch/_c_extension.pyi +121 -0
  6. hdiffpatch/_c_extension.pyx +1068 -0
  7. hdiffpatch/_c_src/HDiffPatch/.git +1 -0
  8. hdiffpatch/_c_src/HDiffPatch/.github/workflows/ci.yml +134 -0
  9. hdiffpatch/_c_src/HDiffPatch/.gitignore +23 -0
  10. hdiffpatch/_c_src/HDiffPatch/CHANGELOG.md +244 -0
  11. hdiffpatch/_c_src/HDiffPatch/LICENSE +48 -0
  12. hdiffpatch/_c_src/HDiffPatch/Makefile +425 -0
  13. hdiffpatch/_c_src/HDiffPatch/README.md +528 -0
  14. hdiffpatch/_c_src/HDiffPatch/README_cn.md +525 -0
  15. hdiffpatch/_c_src/HDiffPatch/_atosize.h +83 -0
  16. hdiffpatch/_c_src/HDiffPatch/_clock_for_demo.h +55 -0
  17. hdiffpatch/_c_src/HDiffPatch/_dir_ignore.h +191 -0
  18. hdiffpatch/_c_src/HDiffPatch/bsdiff_wrapper/bsdiff_wrapper.cpp +380 -0
  19. hdiffpatch/_c_src/HDiffPatch/bsdiff_wrapper/bsdiff_wrapper.h +73 -0
  20. hdiffpatch/_c_src/HDiffPatch/bsdiff_wrapper/bspatch_wrapper.c +275 -0
  21. hdiffpatch/_c_src/HDiffPatch/bsdiff_wrapper/bspatch_wrapper.h +58 -0
  22. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/Android.mk +135 -0
  23. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/Application.mk +8 -0
  24. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/build_libs.bat +1 -0
  25. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/build_libs.sh +1 -0
  26. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/build_libs_patchers.bat +1 -0
  27. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/build_libs_patchers.sh +1 -0
  28. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/hpatch.c +44 -0
  29. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/hpatch.h +26 -0
  30. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/hpatch_jni.c +38 -0
  31. hdiffpatch/_c_src/HDiffPatch/builds/android_ndk_jni_mk/java/com/github/sisong/HPatch.java +21 -0
  32. hdiffpatch/_c_src/HDiffPatch/builds/codeblocks/HDiffPatch.workspace +8 -0
  33. hdiffpatch/_c_src/HDiffPatch/builds/codeblocks/HDiffZ.cbp +400 -0
  34. hdiffpatch/_c_src/HDiffPatch/builds/codeblocks/HPatchZ.cbp +269 -0
  35. hdiffpatch/_c_src/HDiffPatch/builds/codeblocks/unitTest.cbp +79 -0
  36. hdiffpatch/_c_src/HDiffPatch/builds/vc/HDiffPatch.sln +191 -0
  37. hdiffpatch/_c_src/HDiffPatch/builds/vc/HDiffZ.vcxproj +456 -0
  38. hdiffpatch/_c_src/HDiffPatch/builds/vc/HPatchZ.vcxproj +439 -0
  39. hdiffpatch/_c_src/HDiffPatch/builds/vc/bzip2.vcxproj +302 -0
  40. hdiffpatch/_c_src/HDiffPatch/builds/vc/hpatchz_test.vcxproj +216 -0
  41. hdiffpatch/_c_src/HDiffPatch/builds/vc/libdeflate.vcxproj +332 -0
  42. hdiffpatch/_c_src/HDiffPatch/builds/vc/longPathAware.exe.manifest +7 -0
  43. hdiffpatch/_c_src/HDiffPatch/builds/vc/lzma.vcxproj +350 -0
  44. hdiffpatch/_c_src/HDiffPatch/builds/vc/testHashClash.vcxproj +294 -0
  45. hdiffpatch/_c_src/HDiffPatch/builds/vc/unitTest.vcxproj +369 -0
  46. hdiffpatch/_c_src/HDiffPatch/builds/vc/zlib.vcxproj +315 -0
  47. hdiffpatch/_c_src/HDiffPatch/builds/vc/zstd.vcxproj +357 -0
  48. hdiffpatch/_c_src/HDiffPatch/builds/xcode/HDiffPatch.xcworkspace/contents.xcworkspacedata +39 -0
  49. hdiffpatch/_c_src/HDiffPatch/builds/xcode/HDiffPatch.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  50. hdiffpatch/_c_src/HDiffPatch/builds/xcode/HDiffPatch.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
  51. hdiffpatch/_c_src/HDiffPatch/builds/xcode/bestParams.xcodeproj/project.pbxproj +447 -0
  52. hdiffpatch/_c_src/HDiffPatch/builds/xcode/bestParams.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  53. hdiffpatch/_c_src/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.pbxproj +655 -0
  54. hdiffpatch/_c_src/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  55. hdiffpatch/_c_src/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  56. hdiffpatch/_c_src/HDiffPatch/builds/xcode/hpatchz.xcodeproj/project.pbxproj +410 -0
  57. hdiffpatch/_c_src/HDiffPatch/builds/xcode/hpatchz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  58. hdiffpatch/_c_src/HDiffPatch/builds/xcode/libdeflate.xcodeproj/project.pbxproj +286 -0
  59. hdiffpatch/_c_src/HDiffPatch/builds/xcode/libdeflate.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  60. hdiffpatch/_c_src/HDiffPatch/builds/xcode/lz4.xcodeproj/project.pbxproj +268 -0
  61. hdiffpatch/_c_src/HDiffPatch/builds/xcode/lz4.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  62. hdiffpatch/_c_src/HDiffPatch/builds/xcode/lzma.xcodeproj/project.pbxproj +585 -0
  63. hdiffpatch/_c_src/HDiffPatch/builds/xcode/lzma.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  64. hdiffpatch/_c_src/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.pbxproj +301 -0
  65. hdiffpatch/_c_src/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  66. hdiffpatch/_c_src/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  67. hdiffpatch/_c_src/HDiffPatch/builds/xcode/unitTest.xcodeproj/project.pbxproj +549 -0
  68. hdiffpatch/_c_src/HDiffPatch/builds/xcode/unitTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  69. hdiffpatch/_c_src/HDiffPatch/builds/xcode/zlib.xcodeproj/project.pbxproj +308 -0
  70. hdiffpatch/_c_src/HDiffPatch/builds/xcode/zlib.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  71. hdiffpatch/_c_src/HDiffPatch/builds/xcode/zstd.xcodeproj/project.pbxproj +515 -0
  72. hdiffpatch/_c_src/HDiffPatch/builds/xcode/zstd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  73. hdiffpatch/_c_src/HDiffPatch/builds/xcode_iOS_hpatchz/hpatch_objc/hpatch_objc.h +30 -0
  74. hdiffpatch/_c_src/HDiffPatch/builds/xcode_iOS_hpatchz/hpatch_objc/hpatch_objc.m +32 -0
  75. hdiffpatch/_c_src/HDiffPatch/builds/xcode_iOS_hpatchz/hpatchz.xcodeproj/project.pbxproj +745 -0
  76. hdiffpatch/_c_src/HDiffPatch/builds/xcode_iOS_hpatchz/hpatchz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  77. hdiffpatch/_c_src/HDiffPatch/builds/xcode_iOS_hpatchz/hpatchz.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  78. hdiffpatch/_c_src/HDiffPatch/checksum_plugin_demo.h +716 -0
  79. hdiffpatch/_c_src/HDiffPatch/compress_parallel.cpp +201 -0
  80. hdiffpatch/_c_src/HDiffPatch/compress_parallel.h +59 -0
  81. hdiffpatch/_c_src/HDiffPatch/compress_plugin_demo.h +1519 -0
  82. hdiffpatch/_c_src/HDiffPatch/decompress_plugin_demo.h +1634 -0
  83. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_diff.cpp +867 -0
  84. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_diff.h +79 -0
  85. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_diff_tools.cpp +226 -0
  86. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_diff_tools.h +190 -0
  87. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_manifest.cpp +357 -0
  88. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/dir_manifest.h +87 -0
  89. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_diff/file_for_dirDiff.h +151 -0
  90. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch.c +814 -0
  91. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch.h +241 -0
  92. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch_private.h +47 -0
  93. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch_tools.c +114 -0
  94. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch_tools.h +53 -0
  95. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/dir_patch_types.h +65 -0
  96. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/new_dir_output.c +340 -0
  97. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/new_dir_output.h +144 -0
  98. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/new_stream.c +176 -0
  99. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/new_stream.h +84 -0
  100. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/ref_stream.c +146 -0
  101. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/ref_stream.h +61 -0
  102. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/res_handle_limit.c +152 -0
  103. hdiffpatch/_c_src/HDiffPatch/dirDiffPatch/dir_patch/res_handle_limit.h +76 -0
  104. hdiffpatch/_c_src/HDiffPatch/file_for_patch.c +658 -0
  105. hdiffpatch/_c_src/HDiffPatch/file_for_patch.h +298 -0
  106. hdiffpatch/_c_src/HDiffPatch/hdiffz.cpp +2112 -0
  107. hdiffpatch/_c_src/HDiffPatch/hdiffz_import_patch.c +31 -0
  108. hdiffpatch/_c_src/HDiffPatch/hdiffz_import_patch.h +42 -0
  109. hdiffpatch/_c_src/HDiffPatch/hpatch_dir_listener.h +302 -0
  110. hdiffpatch/_c_src/HDiffPatch/hpatchz.c +1683 -0
  111. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/diff.cpp +1709 -0
  112. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/diff.h +200 -0
  113. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/diff_for_hpatch_lite.h +33 -0
  114. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/diff_types.h +173 -0
  115. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/match_block.cpp +356 -0
  116. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/match_block.h +149 -0
  117. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/bytes_rle.cpp +383 -0
  118. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/bytes_rle.h +73 -0
  119. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/compress_detect.cpp +184 -0
  120. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/compress_detect.h +88 -0
  121. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/config.h +89 -0
  122. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort.c.inc.h +319 -0
  123. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort.cpp +10 -0
  124. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort.h +97 -0
  125. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort64.cpp +14 -0
  126. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort64.h +108 -0
  127. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort_private.h +186 -0
  128. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/sssort.c.inc.h +780 -0
  129. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/trsort.c.inc.h +575 -0
  130. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.c +435 -0
  131. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.h +144 -0
  132. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/bloom_filter.h +167 -0
  133. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/covers.h +138 -0
  134. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/digest_matcher.cpp +763 -0
  135. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/digest_matcher.h +97 -0
  136. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp +921 -0
  137. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.h +319 -0
  138. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/mem_buf.h +72 -0
  139. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/pack_uint.h +132 -0
  140. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/qsort_parallel.h +125 -0
  141. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/suffix_string.cpp +428 -0
  142. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HDiff/private_diff/suffix_string.h +133 -0
  143. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatch/checksum_plugin.h +52 -0
  144. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatch/patch.c +2384 -0
  145. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatch/patch.h +229 -0
  146. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatch/patch_private.h +213 -0
  147. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatch/patch_types.h +342 -0
  148. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite.c +186 -0
  149. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite.h +48 -0
  150. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite_input_cache.h +31 -0
  151. hdiffpatch/_c_src/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite_types.h +100 -0
  152. hdiffpatch/_c_src/HDiffPatch/libParallel/parallel_channel.cpp +170 -0
  153. hdiffpatch/_c_src/HDiffPatch/libParallel/parallel_channel.h +153 -0
  154. hdiffpatch/_c_src/HDiffPatch/libParallel/parallel_import.cpp +367 -0
  155. hdiffpatch/_c_src/HDiffPatch/libParallel/parallel_import.h +92 -0
  156. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/dict_decompress_plugin.h +153 -0
  157. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/dir_sync_client.cpp +437 -0
  158. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/dir_sync_client.h +88 -0
  159. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/match_in_old.cpp +572 -0
  160. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/match_in_old.h +46 -0
  161. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_client.cpp +610 -0
  162. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_client.h +75 -0
  163. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_client_private.h +49 -0
  164. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_client_type.h +156 -0
  165. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_client_type_private.h +204 -0
  166. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_diff_data.cpp +250 -0
  167. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_diff_data.h +67 -0
  168. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_info_client.cpp +674 -0
  169. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_client/sync_info_client.h +121 -0
  170. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/dict_compress_plugin.h +83 -0
  171. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/dir_sync_make.cpp +131 -0
  172. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/dir_sync_make.h +56 -0
  173. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/hsynz_plugin.h +55 -0
  174. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/match_in_new.cpp +147 -0
  175. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/match_in_new.h +38 -0
  176. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/sync_info_make.cpp +328 -0
  177. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/sync_info_make.h +65 -0
  178. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/sync_make.cpp +478 -0
  179. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/sync_make.h +68 -0
  180. hdiffpatch/_c_src/HDiffPatch/libhsync/sync_make/sync_make_hash_clash.h +111 -0
  181. hdiffpatch/_c_src/HDiffPatch/test/_private_searchBestParams.cpp +301 -0
  182. hdiffpatch/_c_src/HDiffPatch/test/hpatchz_test.cpp +291 -0
  183. hdiffpatch/_c_src/HDiffPatch/test/testHashClash.cpp +538 -0
  184. hdiffpatch/_c_src/HDiffPatch/test/unit_test.cpp +861 -0
  185. hdiffpatch/_c_src/HDiffPatch/vcdiff_wrapper/vcdiff_wrapper.cpp +619 -0
  186. hdiffpatch/_c_src/HDiffPatch/vcdiff_wrapper/vcdiff_wrapper.h +95 -0
  187. hdiffpatch/_c_src/HDiffPatch/vcdiff_wrapper/vcpatch_code_table.h +78 -0
  188. hdiffpatch/_c_src/HDiffPatch/vcdiff_wrapper/vcpatch_wrapper.c +950 -0
  189. hdiffpatch/_c_src/HDiffPatch/vcdiff_wrapper/vcpatch_wrapper.h +72 -0
  190. hdiffpatch/_c_src/bzip2/.git +1 -0
  191. hdiffpatch/_c_src/bzip2/.gitattributes +1 -0
  192. hdiffpatch/_c_src/bzip2/.gitignore +9 -0
  193. hdiffpatch/_c_src/bzip2/CHANGES +356 -0
  194. hdiffpatch/_c_src/bzip2/LICENSE +42 -0
  195. hdiffpatch/_c_src/bzip2/Makefile +223 -0
  196. hdiffpatch/_c_src/bzip2/Makefile-libbz2_so +59 -0
  197. hdiffpatch/_c_src/bzip2/README +196 -0
  198. hdiffpatch/_c_src/bzip2/README.COMPILATION.PROBLEMS +58 -0
  199. hdiffpatch/_c_src/bzip2/README.XML.STUFF +45 -0
  200. hdiffpatch/_c_src/bzip2/blocksort.c +1094 -0
  201. hdiffpatch/_c_src/bzip2/bz-common.xsl +39 -0
  202. hdiffpatch/_c_src/bzip2/bz-fo.xsl +276 -0
  203. hdiffpatch/_c_src/bzip2/bz-html.xsl +23 -0
  204. hdiffpatch/_c_src/bzip2/bzdiff +76 -0
  205. hdiffpatch/_c_src/bzip2/bzdiff.1 +52 -0
  206. hdiffpatch/_c_src/bzip2/bzgrep +85 -0
  207. hdiffpatch/_c_src/bzip2/bzgrep.1 +62 -0
  208. hdiffpatch/_c_src/bzip2/bzip.css +74 -0
  209. hdiffpatch/_c_src/bzip2/bzip2.1 +464 -0
  210. hdiffpatch/_c_src/bzip2/bzip2.c +2046 -0
  211. hdiffpatch/_c_src/bzip2/bzip2recover.c +516 -0
  212. hdiffpatch/_c_src/bzip2/bzlib.c +1572 -0
  213. hdiffpatch/_c_src/bzip2/bzlib.h +282 -0
  214. hdiffpatch/_c_src/bzip2/bzlib_private.h +509 -0
  215. hdiffpatch/_c_src/bzip2/bzmore +61 -0
  216. hdiffpatch/_c_src/bzip2/bzmore.1 +156 -0
  217. hdiffpatch/_c_src/bzip2/compress.c +672 -0
  218. hdiffpatch/_c_src/bzip2/crctable.c +104 -0
  219. hdiffpatch/_c_src/bzip2/decompress.c +652 -0
  220. hdiffpatch/_c_src/bzip2/dlltest.c +175 -0
  221. hdiffpatch/_c_src/bzip2/dlltest.dsp +93 -0
  222. hdiffpatch/_c_src/bzip2/entities.xml +10 -0
  223. hdiffpatch/_c_src/bzip2/format.pl +68 -0
  224. hdiffpatch/_c_src/bzip2/huffman.c +205 -0
  225. hdiffpatch/_c_src/bzip2/libbz2.def +27 -0
  226. hdiffpatch/_c_src/bzip2/libbz2.dsp +130 -0
  227. hdiffpatch/_c_src/bzip2/makefile.msc +63 -0
  228. hdiffpatch/_c_src/bzip2/manual.xml +2979 -0
  229. hdiffpatch/_c_src/bzip2/mk251.c +31 -0
  230. hdiffpatch/_c_src/bzip2/prepare-release.sh +82 -0
  231. hdiffpatch/_c_src/bzip2/randtable.c +84 -0
  232. hdiffpatch/_c_src/bzip2/release-update.sh +90 -0
  233. hdiffpatch/_c_src/bzip2/sample1.bz2 +0 -0
  234. hdiffpatch/_c_src/bzip2/sample1.ref +0 -0
  235. hdiffpatch/_c_src/bzip2/sample2.bz2 +0 -0
  236. hdiffpatch/_c_src/bzip2/sample2.ref +0 -0
  237. hdiffpatch/_c_src/bzip2/sample3.bz2 +0 -0
  238. hdiffpatch/_c_src/bzip2/sample3.ref +30007 -0
  239. hdiffpatch/_c_src/bzip2/spewG.c +54 -0
  240. hdiffpatch/_c_src/bzip2/unzcrash.c +141 -0
  241. hdiffpatch/_c_src/bzip2/words0 +9 -0
  242. hdiffpatch/_c_src/bzip2/words1 +4 -0
  243. hdiffpatch/_c_src/bzip2/words2 +5 -0
  244. hdiffpatch/_c_src/bzip2/words3 +30 -0
  245. hdiffpatch/_c_src/bzip2/xmlproc.sh +114 -0
  246. hdiffpatch/_c_src/foo.c +11 -0
  247. hdiffpatch/_c_src/foo.h +24 -0
  248. hdiffpatch/_c_src/libdeflate/.cirrus.yml +12 -0
  249. hdiffpatch/_c_src/libdeflate/.git +1 -0
  250. hdiffpatch/_c_src/libdeflate/.github/workflows/ci.yml +290 -0
  251. hdiffpatch/_c_src/libdeflate/.gitignore +6 -0
  252. hdiffpatch/_c_src/libdeflate/CMakeLists.txt +319 -0
  253. hdiffpatch/_c_src/libdeflate/COPYING +22 -0
  254. hdiffpatch/_c_src/libdeflate/NEWS.md +515 -0
  255. hdiffpatch/_c_src/libdeflate/README.md +341 -0
  256. hdiffpatch/_c_src/libdeflate/common_defs.h +747 -0
  257. hdiffpatch/_c_src/libdeflate/lib/adler32.c +162 -0
  258. hdiffpatch/_c_src/libdeflate/lib/arm/adler32_impl.h +365 -0
  259. hdiffpatch/_c_src/libdeflate/lib/arm/cpu_features.c +230 -0
  260. hdiffpatch/_c_src/libdeflate/lib/arm/cpu_features.h +216 -0
  261. hdiffpatch/_c_src/libdeflate/lib/arm/crc32_impl.h +596 -0
  262. hdiffpatch/_c_src/libdeflate/lib/arm/crc32_pmull_helpers.h +156 -0
  263. hdiffpatch/_c_src/libdeflate/lib/arm/crc32_pmull_wide.h +226 -0
  264. hdiffpatch/_c_src/libdeflate/lib/arm/matchfinder_impl.h +78 -0
  265. hdiffpatch/_c_src/libdeflate/lib/bt_matchfinder.h +342 -0
  266. hdiffpatch/_c_src/libdeflate/lib/cpu_features_common.h +93 -0
  267. hdiffpatch/_c_src/libdeflate/lib/crc32.c +262 -0
  268. hdiffpatch/_c_src/libdeflate/lib/crc32_multipliers.h +375 -0
  269. hdiffpatch/_c_src/libdeflate/lib/crc32_tables.h +587 -0
  270. hdiffpatch/_c_src/libdeflate/lib/decompress_template.h +849 -0
  271. hdiffpatch/_c_src/libdeflate/lib/deflate_compress.c +4394 -0
  272. hdiffpatch/_c_src/libdeflate/lib/deflate_compress.h +15 -0
  273. hdiffpatch/_c_src/libdeflate/lib/deflate_constants.h +56 -0
  274. hdiffpatch/_c_src/libdeflate/lib/deflate_decompress.c +1249 -0
  275. hdiffpatch/_c_src/libdeflate/lib/gzip_compress.c +112 -0
  276. hdiffpatch/_c_src/libdeflate/lib/gzip_constants.h +45 -0
  277. hdiffpatch/_c_src/libdeflate/lib/gzip_decompress.c +184 -0
  278. hdiffpatch/_c_src/libdeflate/lib/gzip_overhead.h +20 -0
  279. hdiffpatch/_c_src/libdeflate/lib/hc_matchfinder.h +401 -0
  280. hdiffpatch/_c_src/libdeflate/lib/ht_matchfinder.h +240 -0
  281. hdiffpatch/_c_src/libdeflate/lib/lib_common.h +108 -0
  282. hdiffpatch/_c_src/libdeflate/lib/matchfinder_common.h +224 -0
  283. hdiffpatch/_c_src/libdeflate/lib/riscv/matchfinder_impl.h +97 -0
  284. hdiffpatch/_c_src/libdeflate/lib/utils.c +141 -0
  285. hdiffpatch/_c_src/libdeflate/lib/x86/adler32_impl.h +136 -0
  286. hdiffpatch/_c_src/libdeflate/lib/x86/adler32_template.h +518 -0
  287. hdiffpatch/_c_src/libdeflate/lib/x86/cpu_features.c +212 -0
  288. hdiffpatch/_c_src/libdeflate/lib/x86/cpu_features.h +179 -0
  289. hdiffpatch/_c_src/libdeflate/lib/x86/crc32_impl.h +160 -0
  290. hdiffpatch/_c_src/libdeflate/lib/x86/crc32_pclmul_template.h +467 -0
  291. hdiffpatch/_c_src/libdeflate/lib/x86/decompress_impl.h +57 -0
  292. hdiffpatch/_c_src/libdeflate/lib/x86/matchfinder_impl.h +122 -0
  293. hdiffpatch/_c_src/libdeflate/lib/zlib_compress.c +82 -0
  294. hdiffpatch/_c_src/libdeflate/lib/zlib_constants.h +21 -0
  295. hdiffpatch/_c_src/libdeflate/lib/zlib_decompress.c +104 -0
  296. hdiffpatch/_c_src/libdeflate/libdeflate-config.cmake.in +3 -0
  297. hdiffpatch/_c_src/libdeflate/libdeflate.h +534 -0
  298. hdiffpatch/_c_src/libdeflate/libdeflate.pc.in +18 -0
  299. hdiffpatch/_c_src/libdeflate/pgzip/Makefile +74 -0
  300. hdiffpatch/_c_src/libdeflate/pgzip/vc/pgzip.sln +37 -0
  301. hdiffpatch/_c_src/libdeflate/pgzip/vc/pgzip.vcxproj +215 -0
  302. hdiffpatch/_c_src/libdeflate/pgzip/vc/pgzip.vcxproj.filters +46 -0
  303. hdiffpatch/_c_src/libdeflate/pgzip/xcode/pgzip.xcodeproj/project.pbxproj +326 -0
  304. hdiffpatch/_c_src/libdeflate/pgzip/xcode/pgzip.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  305. hdiffpatch/_c_src/libdeflate/pgzip/xcode/pgzip.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  306. hdiffpatch/_c_src/libdeflate/pgzip/xcode/pgzip.xcodeproj/xcshareddata/xcschemes/pgzip.xcscheme +78 -0
  307. hdiffpatch/_c_src/libdeflate/programs/CMakeLists.txt +105 -0
  308. hdiffpatch/_c_src/libdeflate/programs/benchmark.c +696 -0
  309. hdiffpatch/_c_src/libdeflate/programs/checksum.c +218 -0
  310. hdiffpatch/_c_src/libdeflate/programs/config.h.in +19 -0
  311. hdiffpatch/_c_src/libdeflate/programs/gzip.c +688 -0
  312. hdiffpatch/_c_src/libdeflate/programs/gzip_compress_by_stream_mt.cpp +336 -0
  313. hdiffpatch/_c_src/libdeflate/programs/gzip_compress_by_stream_mt.h +43 -0
  314. hdiffpatch/_c_src/libdeflate/programs/gzip_decompress_by_stream_mt.cpp +483 -0
  315. hdiffpatch/_c_src/libdeflate/programs/gzip_decompress_by_stream_mt.h +53 -0
  316. hdiffpatch/_c_src/libdeflate/programs/pgzip.c +523 -0
  317. hdiffpatch/_c_src/libdeflate/programs/prog_util.c +541 -0
  318. hdiffpatch/_c_src/libdeflate/programs/prog_util.h +226 -0
  319. hdiffpatch/_c_src/libdeflate/programs/test_checksums.c +200 -0
  320. hdiffpatch/_c_src/libdeflate/programs/test_custom_malloc.c +155 -0
  321. hdiffpatch/_c_src/libdeflate/programs/test_incomplete_codes.c +385 -0
  322. hdiffpatch/_c_src/libdeflate/programs/test_invalid_streams.c +130 -0
  323. hdiffpatch/_c_src/libdeflate/programs/test_litrunlen_overflow.c +72 -0
  324. hdiffpatch/_c_src/libdeflate/programs/test_overread.c +95 -0
  325. hdiffpatch/_c_src/libdeflate/programs/test_slow_decompression.c +472 -0
  326. hdiffpatch/_c_src/libdeflate/programs/test_trailing_bytes.c +151 -0
  327. hdiffpatch/_c_src/libdeflate/programs/test_util.c +237 -0
  328. hdiffpatch/_c_src/libdeflate/programs/test_util.h +61 -0
  329. hdiffpatch/_c_src/libdeflate/programs/tgetopt.c +118 -0
  330. hdiffpatch/_c_src/libdeflate/scripts/android_build.sh +118 -0
  331. hdiffpatch/_c_src/libdeflate/scripts/android_tests.sh +69 -0
  332. hdiffpatch/_c_src/libdeflate/scripts/benchmark.sh +10 -0
  333. hdiffpatch/_c_src/libdeflate/scripts/checksum.sh +10 -0
  334. hdiffpatch/_c_src/libdeflate/scripts/checksum_benchmarks.sh +253 -0
  335. hdiffpatch/_c_src/libdeflate/scripts/cmake-helper.sh +17 -0
  336. hdiffpatch/_c_src/libdeflate/scripts/deflate_benchmarks.sh +119 -0
  337. hdiffpatch/_c_src/libdeflate/scripts/exec_tests.sh +38 -0
  338. hdiffpatch/_c_src/libdeflate/scripts/gen-crc32-consts.py +158 -0
  339. hdiffpatch/_c_src/libdeflate/scripts/gen-release-archives.sh +37 -0
  340. hdiffpatch/_c_src/libdeflate/scripts/gen_bitreverse_tab.py +19 -0
  341. hdiffpatch/_c_src/libdeflate/scripts/gen_default_litlen_costs.py +44 -0
  342. hdiffpatch/_c_src/libdeflate/scripts/gen_offset_slot_map.py +29 -0
  343. hdiffpatch/_c_src/libdeflate/scripts/gzip_tests.sh +523 -0
  344. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/.gitignore +1 -0
  345. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/deflate_compress/corpus/0 +0 -0
  346. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/deflate_compress/fuzz.c +95 -0
  347. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/deflate_decompress/corpus/0 +3 -0
  348. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/deflate_decompress/fuzz.c +62 -0
  349. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/fuzz.sh +108 -0
  350. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/gzip_decompress/corpus/0 +0 -0
  351. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/gzip_decompress/fuzz.c +19 -0
  352. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/zlib_decompress/corpus/0 +3 -0
  353. hdiffpatch/_c_src/libdeflate/scripts/libFuzzer/zlib_decompress/fuzz.c +19 -0
  354. hdiffpatch/_c_src/libdeflate/scripts/run_tests.sh +416 -0
  355. hdiffpatch/_c_src/libdeflate/scripts/toolchain-i686-w64-mingw32.cmake +8 -0
  356. hdiffpatch/_c_src/libdeflate/scripts/toolchain-x86_64-w64-mingw32.cmake +8 -0
  357. hdiffpatch/_c_src/libmd5/.git +1 -0
  358. hdiffpatch/_c_src/libmd5/md5.c +381 -0
  359. hdiffpatch/_c_src/libmd5/md5.h +91 -0
  360. hdiffpatch/_c_src/libmd5/md5main.c +139 -0
  361. hdiffpatch/_c_src/lzma/.git +1 -0
  362. hdiffpatch/_c_src/lzma/Asm/arm/7zCrcOpt.asm +100 -0
  363. hdiffpatch/_c_src/lzma/Asm/arm64/7zAsm.S +181 -0
  364. hdiffpatch/_c_src/lzma/Asm/arm64/LzmaDecOpt.S +1487 -0
  365. hdiffpatch/_c_src/lzma/Asm/x86/7zAsm.asm +341 -0
  366. hdiffpatch/_c_src/lzma/Asm/x86/7zCrcOpt.asm +258 -0
  367. hdiffpatch/_c_src/lzma/Asm/x86/AesOpt.asm +742 -0
  368. hdiffpatch/_c_src/lzma/Asm/x86/LzFindOpt.asm +540 -0
  369. hdiffpatch/_c_src/lzma/Asm/x86/LzmaDecOpt.asm +1339 -0
  370. hdiffpatch/_c_src/lzma/Asm/x86/Sha256Opt.asm +275 -0
  371. hdiffpatch/_c_src/lzma/Asm/x86/XzCrc64Opt.asm +523 -0
  372. hdiffpatch/_c_src/lzma/C/7z.h +204 -0
  373. hdiffpatch/_c_src/lzma/C/7zAlloc.c +89 -0
  374. hdiffpatch/_c_src/lzma/C/7zAlloc.h +19 -0
  375. hdiffpatch/_c_src/lzma/C/7zArcIn.c +1786 -0
  376. hdiffpatch/_c_src/lzma/C/7zBuf.c +36 -0
  377. hdiffpatch/_c_src/lzma/C/7zBuf.h +35 -0
  378. hdiffpatch/_c_src/lzma/C/7zBuf2.c +52 -0
  379. hdiffpatch/_c_src/lzma/C/7zCrc.c +464 -0
  380. hdiffpatch/_c_src/lzma/C/7zCrc.h +28 -0
  381. hdiffpatch/_c_src/lzma/C/7zCrcOpt.c +199 -0
  382. hdiffpatch/_c_src/lzma/C/7zDec.c +673 -0
  383. hdiffpatch/_c_src/lzma/C/7zFile.c +443 -0
  384. hdiffpatch/_c_src/lzma/C/7zFile.h +92 -0
  385. hdiffpatch/_c_src/lzma/C/7zStream.c +199 -0
  386. hdiffpatch/_c_src/lzma/C/7zTypes.h +597 -0
  387. hdiffpatch/_c_src/lzma/C/7zVersion.h +27 -0
  388. hdiffpatch/_c_src/lzma/C/7zVersion.rc +55 -0
  389. hdiffpatch/_c_src/lzma/C/7zWindows.h +101 -0
  390. hdiffpatch/_c_src/lzma/C/7zip_gcc_c.mak +360 -0
  391. hdiffpatch/_c_src/lzma/C/Aes.c +429 -0
  392. hdiffpatch/_c_src/lzma/C/Aes.h +60 -0
  393. hdiffpatch/_c_src/lzma/C/AesOpt.c +1002 -0
  394. hdiffpatch/_c_src/lzma/C/Alloc.c +605 -0
  395. hdiffpatch/_c_src/lzma/C/Alloc.h +76 -0
  396. hdiffpatch/_c_src/lzma/C/Asm_c.mak +12 -0
  397. hdiffpatch/_c_src/lzma/C/Bcj2.c +290 -0
  398. hdiffpatch/_c_src/lzma/C/Bcj2.h +332 -0
  399. hdiffpatch/_c_src/lzma/C/Bcj2Enc.c +506 -0
  400. hdiffpatch/_c_src/lzma/C/Bra.c +709 -0
  401. hdiffpatch/_c_src/lzma/C/Bra.h +105 -0
  402. hdiffpatch/_c_src/lzma/C/Bra86.c +187 -0
  403. hdiffpatch/_c_src/lzma/C/BraIA64.c +14 -0
  404. hdiffpatch/_c_src/lzma/C/Compiler.h +236 -0
  405. hdiffpatch/_c_src/lzma/C/CpuArch.c +970 -0
  406. hdiffpatch/_c_src/lzma/C/CpuArch.h +678 -0
  407. hdiffpatch/_c_src/lzma/C/Delta.c +169 -0
  408. hdiffpatch/_c_src/lzma/C/Delta.h +19 -0
  409. hdiffpatch/_c_src/lzma/C/DllSecur.c +99 -0
  410. hdiffpatch/_c_src/lzma/C/DllSecur.h +20 -0
  411. hdiffpatch/_c_src/lzma/C/LzFind.c +1746 -0
  412. hdiffpatch/_c_src/lzma/C/LzFind.h +160 -0
  413. hdiffpatch/_c_src/lzma/C/LzFindMt.c +1414 -0
  414. hdiffpatch/_c_src/lzma/C/LzFindMt.h +112 -0
  415. hdiffpatch/_c_src/lzma/C/LzFindOpt.c +578 -0
  416. hdiffpatch/_c_src/lzma/C/LzHash.h +34 -0
  417. hdiffpatch/_c_src/lzma/C/Lzma2Dec.c +493 -0
  418. hdiffpatch/_c_src/lzma/C/Lzma2Dec.h +121 -0
  419. hdiffpatch/_c_src/lzma/C/Lzma2DecMt.c +1095 -0
  420. hdiffpatch/_c_src/lzma/C/Lzma2DecMt.h +81 -0
  421. hdiffpatch/_c_src/lzma/C/Lzma2Enc.c +805 -0
  422. hdiffpatch/_c_src/lzma/C/Lzma2Enc.h +57 -0
  423. hdiffpatch/_c_src/lzma/C/Lzma86.h +111 -0
  424. hdiffpatch/_c_src/lzma/C/Lzma86Dec.c +53 -0
  425. hdiffpatch/_c_src/lzma/C/Lzma86Enc.c +103 -0
  426. hdiffpatch/_c_src/lzma/C/LzmaDec.c +1363 -0
  427. hdiffpatch/_c_src/lzma/C/LzmaDec.h +237 -0
  428. hdiffpatch/_c_src/lzma/C/LzmaEnc.c +3144 -0
  429. hdiffpatch/_c_src/lzma/C/LzmaEnc.h +83 -0
  430. hdiffpatch/_c_src/lzma/C/LzmaLib.c +42 -0
  431. hdiffpatch/_c_src/lzma/C/LzmaLib.h +138 -0
  432. hdiffpatch/_c_src/lzma/C/MtCoder.c +571 -0
  433. hdiffpatch/_c_src/lzma/C/MtCoder.h +141 -0
  434. hdiffpatch/_c_src/lzma/C/MtDec.c +1124 -0
  435. hdiffpatch/_c_src/lzma/C/MtDec.h +202 -0
  436. hdiffpatch/_c_src/lzma/C/Ppmd.h +169 -0
  437. hdiffpatch/_c_src/lzma/C/Ppmd7.c +1131 -0
  438. hdiffpatch/_c_src/lzma/C/Ppmd7.h +181 -0
  439. hdiffpatch/_c_src/lzma/C/Ppmd7Dec.c +312 -0
  440. hdiffpatch/_c_src/lzma/C/Ppmd7Enc.c +337 -0
  441. hdiffpatch/_c_src/lzma/C/Precomp.h +127 -0
  442. hdiffpatch/_c_src/lzma/C/RotateDefs.h +50 -0
  443. hdiffpatch/_c_src/lzma/C/Sha256.c +492 -0
  444. hdiffpatch/_c_src/lzma/C/Sha256.h +86 -0
  445. hdiffpatch/_c_src/lzma/C/Sha256Opt.c +451 -0
  446. hdiffpatch/_c_src/lzma/C/Sort.c +141 -0
  447. hdiffpatch/_c_src/lzma/C/Sort.h +18 -0
  448. hdiffpatch/_c_src/lzma/C/SwapBytes.c +835 -0
  449. hdiffpatch/_c_src/lzma/C/SwapBytes.h +17 -0
  450. hdiffpatch/_c_src/lzma/C/Threads.c +581 -0
  451. hdiffpatch/_c_src/lzma/C/Threads.h +250 -0
  452. hdiffpatch/_c_src/lzma/C/Util/7z/7z.dsp +249 -0
  453. hdiffpatch/_c_src/lzma/C/Util/7z/7z.dsw +29 -0
  454. hdiffpatch/_c_src/lzma/C/Util/7z/7zMain.c +889 -0
  455. hdiffpatch/_c_src/lzma/C/Util/7z/Precomp.c +4 -0
  456. hdiffpatch/_c_src/lzma/C/Util/7z/Precomp.h +13 -0
  457. hdiffpatch/_c_src/lzma/C/Util/7z/makefile +44 -0
  458. hdiffpatch/_c_src/lzma/C/Util/7z/makefile.gcc +32 -0
  459. hdiffpatch/_c_src/lzma/C/Util/Lzma/LzmaUtil.c +313 -0
  460. hdiffpatch/_c_src/lzma/C/Util/Lzma/LzmaUtil.dsp +188 -0
  461. hdiffpatch/_c_src/lzma/C/Util/Lzma/LzmaUtil.dsw +29 -0
  462. hdiffpatch/_c_src/lzma/C/Util/Lzma/Precomp.h +13 -0
  463. hdiffpatch/_c_src/lzma/C/Util/Lzma/makefile +30 -0
  464. hdiffpatch/_c_src/lzma/C/Util/Lzma/makefile.gcc +21 -0
  465. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/LzmaLib.def +4 -0
  466. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/LzmaLib.dsp +202 -0
  467. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/LzmaLib.dsw +29 -0
  468. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/LzmaLibExports.c +15 -0
  469. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/Precomp.c +4 -0
  470. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/Precomp.h +13 -0
  471. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/makefile +59 -0
  472. hdiffpatch/_c_src/lzma/C/Util/LzmaLib/resource.rc +3 -0
  473. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/Precomp.c +4 -0
  474. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/Precomp.h +13 -0
  475. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/SfxSetup.c +657 -0
  476. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/SfxSetup.dsp +231 -0
  477. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/SfxSetup.dsw +29 -0
  478. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/makefile +44 -0
  479. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/makefile_con +40 -0
  480. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/resource.rc +5 -0
  481. hdiffpatch/_c_src/lzma/C/Util/SfxSetup/setup.ico +0 -0
  482. hdiffpatch/_c_src/lzma/C/Xz.c +92 -0
  483. hdiffpatch/_c_src/lzma/C/Xz.h +536 -0
  484. hdiffpatch/_c_src/lzma/C/XzCrc64.c +140 -0
  485. hdiffpatch/_c_src/lzma/C/XzCrc64.h +26 -0
  486. hdiffpatch/_c_src/lzma/C/XzCrc64Opt.c +261 -0
  487. hdiffpatch/_c_src/lzma/C/XzDec.c +2877 -0
  488. hdiffpatch/_c_src/lzma/C/XzEnc.c +1378 -0
  489. hdiffpatch/_c_src/lzma/C/XzEnc.h +63 -0
  490. hdiffpatch/_c_src/lzma/C/XzIn.c +340 -0
  491. hdiffpatch/_c_src/lzma/C/var_clang.mak +11 -0
  492. hdiffpatch/_c_src/lzma/C/var_clang_arm64.mak +12 -0
  493. hdiffpatch/_c_src/lzma/C/var_clang_x64.mak +11 -0
  494. hdiffpatch/_c_src/lzma/C/var_clang_x86.mak +11 -0
  495. hdiffpatch/_c_src/lzma/C/var_gcc.mak +12 -0
  496. hdiffpatch/_c_src/lzma/C/var_gcc_arm64.mak +12 -0
  497. hdiffpatch/_c_src/lzma/C/var_gcc_x64.mak +10 -0
  498. hdiffpatch/_c_src/lzma/C/var_gcc_x86.mak +10 -0
  499. hdiffpatch/_c_src/lzma/C/var_mac_arm64.mak +11 -0
  500. hdiffpatch/_c_src/lzma/C/var_mac_x64.mak +11 -0
  501. hdiffpatch/_c_src/lzma/C/warn_clang.mak +1 -0
  502. hdiffpatch/_c_src/lzma/C/warn_clang_mac.mak +1 -0
  503. hdiffpatch/_c_src/lzma/C/warn_gcc.mak +51 -0
  504. hdiffpatch/_c_src/lzma/CPP/7zip/7zip.mak +240 -0
  505. hdiffpatch/_c_src/lzma/CPP/7zip/7zip_gcc.mak +1368 -0
  506. hdiffpatch/_c_src/lzma/CPP/7zip/Aes.mak +10 -0
  507. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp +3 -0
  508. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zCompressionMode.h +90 -0
  509. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zDecode.cpp +599 -0
  510. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zDecode.h +73 -0
  511. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zEncode.cpp +721 -0
  512. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zEncode.h +95 -0
  513. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zExtract.cpp +444 -0
  514. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp +264 -0
  515. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zFolderInStream.h +101 -0
  516. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zHandler.cpp +795 -0
  517. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zHandler.h +178 -0
  518. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp +1158 -0
  519. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zHeader.cpp +19 -0
  520. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zHeader.h +156 -0
  521. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zIn.cpp +1764 -0
  522. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zIn.h +454 -0
  523. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zItem.h +207 -0
  524. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zOut.cpp +1026 -0
  525. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zOut.h +346 -0
  526. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zProperties.cpp +182 -0
  527. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zProperties.h +26 -0
  528. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zRegister.cpp +27 -0
  529. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp +31 -0
  530. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zSpecStream.h +49 -0
  531. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zUpdate.cpp +3088 -0
  532. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/7zUpdate.h +167 -0
  533. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/StdAfx.cpp +3 -0
  534. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/7z/StdAfx.h +11 -0
  535. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Archive.def +14 -0
  536. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Archive2.def +21 -0
  537. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/ArchiveExports.cpp +158 -0
  538. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp +1144 -0
  539. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/CoderMixer2.h +447 -0
  540. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp +17 -0
  541. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/DummyOutStream.h +23 -0
  542. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/HandlerOut.cpp +311 -0
  543. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/HandlerOut.h +154 -0
  544. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp +57 -0
  545. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h +64 -0
  546. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp +135 -0
  547. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/ItemNameUtils.h +30 -0
  548. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/MultiStream.cpp +193 -0
  549. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/MultiStream.h +86 -0
  550. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp +18 -0
  551. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h +35 -0
  552. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/ParseProperties.cpp +3 -0
  553. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/ParseProperties.h +6 -0
  554. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Common/StdAfx.h +11 -0
  555. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/DllExports2.cpp +175 -0
  556. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/IArchive.h +754 -0
  557. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/Icons/7z.ico +0 -0
  558. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/LzmaHandler.cpp +608 -0
  559. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/SplitHandler.cpp +353 -0
  560. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/StdAfx.h +11 -0
  561. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/XzHandler.cpp +1440 -0
  562. hdiffpatch/_c_src/lzma/CPP/7zip/Archive/XzHandler.h +11 -0
  563. hdiffpatch/_c_src/lzma/CPP/7zip/Asm.mak +12 -0
  564. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp +2090 -0
  565. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw +29 -0
  566. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp +3 -0
  567. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h +11 -0
  568. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/makefile +168 -0
  569. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/makefile.gcc +279 -0
  570. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Alone7z/resource.rc +7 -0
  571. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp +3 -0
  572. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h +11 -0
  573. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zExtractR/makefile +98 -0
  574. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc +5 -0
  575. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp +3 -0
  576. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h +11 -0
  577. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zR/makefile +121 -0
  578. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/Format7zR/resource.rc +5 -0
  579. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/LzmaAlone.cpp +817 -0
  580. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/LzmaCon.dsp +540 -0
  581. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/LzmaCon.dsw +29 -0
  582. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/StdAfx.cpp +3 -0
  583. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/StdAfx.h +11 -0
  584. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/makefile +68 -0
  585. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/makefile.gcc +131 -0
  586. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaCon/resource.rc +3 -0
  587. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/LzmaSpec/LzmaSpec.cpp +715 -0
  588. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/7z.ico +0 -0
  589. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/SFXCon.dsp +1017 -0
  590. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/SFXCon.dsw +29 -0
  591. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/SfxCon.cpp +521 -0
  592. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/StdAfx.cpp +3 -0
  593. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/StdAfx.h +11 -0
  594. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/makefile +137 -0
  595. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/makefile.gcc +215 -0
  596. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXCon/resource.rc +9 -0
  597. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/ExtractCallbackSfx.cpp +246 -0
  598. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/ExtractCallbackSfx.h +83 -0
  599. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp +135 -0
  600. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/ExtractEngine.h +11 -0
  601. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp +872 -0
  602. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsw +29 -0
  603. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp +371 -0
  604. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/StdAfx.cpp +3 -0
  605. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/StdAfx.h +6 -0
  606. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/makefile +121 -0
  607. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/resource.h +6 -0
  608. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/resource.rc +16 -0
  609. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXSetup/setup.ico +0 -0
  610. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/7z.ico +0 -0
  611. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/SFXWin.dsp +1074 -0
  612. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/SFXWin.dsw +29 -0
  613. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/SfxWin.cpp +268 -0
  614. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/StdAfx.cpp +3 -0
  615. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/StdAfx.h +6 -0
  616. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/makefile +159 -0
  617. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/resource.h +1 -0
  618. hdiffpatch/_c_src/lzma/CPP/7zip/Bundles/SFXWin/resource.rc +55 -0
  619. hdiffpatch/_c_src/lzma/CPP/7zip/Common/CWrappers.cpp +358 -0
  620. hdiffpatch/_c_src/lzma/CPP/7zip/Common/CWrappers.h +182 -0
  621. hdiffpatch/_c_src/lzma/CPP/7zip/Common/CreateCoder.cpp +548 -0
  622. hdiffpatch/_c_src/lzma/CPP/7zip/Common/CreateCoder.h +200 -0
  623. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FilePathAutoRename.cpp +46 -0
  624. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FilePathAutoRename.h +10 -0
  625. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FileStreams.cpp +923 -0
  626. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FileStreams.h +205 -0
  627. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FilterCoder.cpp +577 -0
  628. hdiffpatch/_c_src/lzma/CPP/7zip/Common/FilterCoder.h +201 -0
  629. hdiffpatch/_c_src/lzma/CPP/7zip/Common/InBuffer.cpp +182 -0
  630. hdiffpatch/_c_src/lzma/CPP/7zip/Common/InBuffer.h +111 -0
  631. hdiffpatch/_c_src/lzma/CPP/7zip/Common/InOutTempBuffer.cpp +237 -0
  632. hdiffpatch/_c_src/lzma/CPP/7zip/Common/InOutTempBuffer.h +45 -0
  633. hdiffpatch/_c_src/lzma/CPP/7zip/Common/LimitedStreams.cpp +393 -0
  634. hdiffpatch/_c_src/lzma/CPP/7zip/Common/LimitedStreams.h +221 -0
  635. hdiffpatch/_c_src/lzma/CPP/7zip/Common/LockedStream.cpp +3 -0
  636. hdiffpatch/_c_src/lzma/CPP/7zip/Common/LockedStream.h +6 -0
  637. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MethodId.cpp +3 -0
  638. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MethodId.h +10 -0
  639. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MethodProps.cpp +739 -0
  640. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MethodProps.h +345 -0
  641. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MultiOutStream.cpp +855 -0
  642. hdiffpatch/_c_src/lzma/CPP/7zip/Common/MultiOutStream.h +160 -0
  643. hdiffpatch/_c_src/lzma/CPP/7zip/Common/OffsetStream.cpp +37 -0
  644. hdiffpatch/_c_src/lzma/CPP/7zip/Common/OffsetStream.h +22 -0
  645. hdiffpatch/_c_src/lzma/CPP/7zip/Common/OutBuffer.cpp +111 -0
  646. hdiffpatch/_c_src/lzma/CPP/7zip/Common/OutBuffer.h +108 -0
  647. hdiffpatch/_c_src/lzma/CPP/7zip/Common/ProgressUtils.cpp +51 -0
  648. hdiffpatch/_c_src/lzma/CPP/7zip/Common/ProgressUtils.h +33 -0
  649. hdiffpatch/_c_src/lzma/CPP/7zip/Common/PropId.cpp +117 -0
  650. hdiffpatch/_c_src/lzma/CPP/7zip/Common/RegisterArc.h +80 -0
  651. hdiffpatch/_c_src/lzma/CPP/7zip/Common/RegisterCodec.h +106 -0
  652. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StdAfx.h +11 -0
  653. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamBinder.cpp +151 -0
  654. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamBinder.h +78 -0
  655. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamObjects.cpp +290 -0
  656. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamObjects.h +146 -0
  657. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamUtils.cpp +101 -0
  658. hdiffpatch/_c_src/lzma/CPP/7zip/Common/StreamUtils.h +31 -0
  659. hdiffpatch/_c_src/lzma/CPP/7zip/Common/UniqBlocks.cpp +57 -0
  660. hdiffpatch/_c_src/lzma/CPP/7zip/Common/UniqBlocks.h +41 -0
  661. hdiffpatch/_c_src/lzma/CPP/7zip/Common/VirtThread.cpp +47 -0
  662. hdiffpatch/_c_src/lzma/CPP/7zip/Common/VirtThread.h +24 -0
  663. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Bcj2Coder.cpp +867 -0
  664. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Bcj2Coder.h +127 -0
  665. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Bcj2Register.cpp +24 -0
  666. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BcjCoder.cpp +24 -0
  667. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BcjCoder.h +37 -0
  668. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BcjRegister.cpp +17 -0
  669. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BranchMisc.cpp +106 -0
  670. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BranchMisc.h +59 -0
  671. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/BranchRegister.cpp +58 -0
  672. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/ByteSwap.cpp +91 -0
  673. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/CodecExports.cpp +378 -0
  674. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/CopyCoder.cpp +153 -0
  675. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/CopyCoder.h +34 -0
  676. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/CopyRegister.cpp +15 -0
  677. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/DeltaFilter.cpp +126 -0
  678. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Lzma2Decoder.cpp +267 -0
  679. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Lzma2Decoder.h +87 -0
  680. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Lzma2Encoder.cpp +126 -0
  681. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Lzma2Encoder.h +30 -0
  682. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/Lzma2Register.cpp +22 -0
  683. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/LzmaDecoder.cpp +350 -0
  684. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/LzmaDecoder.h +113 -0
  685. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/LzmaEncoder.cpp +356 -0
  686. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/LzmaEncoder.h +45 -0
  687. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/LzmaRegister.cpp +22 -0
  688. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/PpmdDecoder.cpp +219 -0
  689. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/PpmdDecoder.h +87 -0
  690. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/PpmdEncoder.cpp +193 -0
  691. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/PpmdEncoder.h +49 -0
  692. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/PpmdRegister.cpp +22 -0
  693. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/StdAfx.h +11 -0
  694. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/XzDecoder.cpp +151 -0
  695. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/XzDecoder.h +86 -0
  696. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/XzEncoder.cpp +243 -0
  697. hdiffpatch/_c_src/lzma/CPP/7zip/Compress/XzEncoder.h +35 -0
  698. hdiffpatch/_c_src/lzma/CPP/7zip/Crc.mak +8 -0
  699. hdiffpatch/_c_src/lzma/CPP/7zip/Crc64.mak +8 -0
  700. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/7zAes.cpp +315 -0
  701. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/7zAes.h +130 -0
  702. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/7zAesRegister.cpp +17 -0
  703. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/MyAes.cpp +258 -0
  704. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/MyAes.h +122 -0
  705. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/MyAesReg.cpp +29 -0
  706. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/RandGen.cpp +241 -0
  707. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/RandGen.h +41 -0
  708. hdiffpatch/_c_src/lzma/CPP/7zip/Crypto/StdAfx.h +11 -0
  709. hdiffpatch/_c_src/lzma/CPP/7zip/GuiCommon.rc +119 -0
  710. hdiffpatch/_c_src/lzma/CPP/7zip/Guid.txt +243 -0
  711. hdiffpatch/_c_src/lzma/CPP/7zip/ICoder.h +477 -0
  712. hdiffpatch/_c_src/lzma/CPP/7zip/IDecl.h +76 -0
  713. hdiffpatch/_c_src/lzma/CPP/7zip/IPassword.h +54 -0
  714. hdiffpatch/_c_src/lzma/CPP/7zip/IProgress.h +20 -0
  715. hdiffpatch/_c_src/lzma/CPP/7zip/IStream.h +210 -0
  716. hdiffpatch/_c_src/lzma/CPP/7zip/LzFindOpt.mak +7 -0
  717. hdiffpatch/_c_src/lzma/CPP/7zip/LzmaDec.mak +7 -0
  718. hdiffpatch/_c_src/lzma/CPP/7zip/LzmaDec_gcc.mak +14 -0
  719. hdiffpatch/_c_src/lzma/CPP/7zip/MyVersion.h +2 -0
  720. hdiffpatch/_c_src/lzma/CPP/7zip/MyVersionInfo.rc +2 -0
  721. hdiffpatch/_c_src/lzma/CPP/7zip/PropID.h +178 -0
  722. hdiffpatch/_c_src/lzma/CPP/7zip/Sha256.mak +13 -0
  723. hdiffpatch/_c_src/lzma/CPP/7zip/SubBuild.mak +3 -0
  724. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/Client7z.cpp +1145 -0
  725. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/Client7z.dsp +331 -0
  726. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/Client7z.dsw +29 -0
  727. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/StdAfx.cpp +3 -0
  728. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/StdAfx.h +11 -0
  729. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/makefile +29 -0
  730. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/makefile.gcc +72 -0
  731. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Client7z/resource.rc +3 -0
  732. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +1769 -0
  733. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h +170 -0
  734. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp +2747 -0
  735. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h +584 -0
  736. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveName.cpp +176 -0
  737. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveName.h +16 -0
  738. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp +398 -0
  739. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h +182 -0
  740. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Bench.cpp +4971 -0
  741. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Bench.h +121 -0
  742. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/DefaultName.cpp +37 -0
  743. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/DefaultName.h +11 -0
  744. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/DirItem.h +407 -0
  745. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp +1654 -0
  746. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/EnumDirItems.h +38 -0
  747. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ExitCode.h +27 -0
  748. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Extract.cpp +575 -0
  749. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Extract.h +107 -0
  750. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ExtractMode.h +44 -0
  751. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp +296 -0
  752. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h +31 -0
  753. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/HashCalc.cpp +2120 -0
  754. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/HashCalc.h +329 -0
  755. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h +112 -0
  756. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp +1337 -0
  757. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/LoadCodecs.h +482 -0
  758. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/OpenArchive.cpp +3702 -0
  759. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/OpenArchive.h +469 -0
  760. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp +745 -0
  761. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/PropIDUtils.h +18 -0
  762. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Property.h +14 -0
  763. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/SetProperties.cpp +88 -0
  764. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/SetProperties.h +10 -0
  765. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/SortUtils.cpp +25 -0
  766. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/SortUtils.h +10 -0
  767. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/StdAfx.h +11 -0
  768. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/TempFiles.cpp +20 -0
  769. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/TempFiles.h +19 -0
  770. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Update.cpp +1931 -0
  771. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/Update.h +219 -0
  772. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateAction.cpp +64 -0
  773. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateAction.h +66 -0
  774. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp +1029 -0
  775. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateCallback.h +197 -0
  776. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdatePair.cpp +302 -0
  777. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdatePair.h +27 -0
  778. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp +74 -0
  779. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/UpdateProduce.h +60 -0
  780. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/WorkDir.cpp +84 -0
  781. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/WorkDir.h +30 -0
  782. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Common/ZipRegistry.h +212 -0
  783. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/BenchCon.cpp +41 -0
  784. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/BenchCon.h +14 -0
  785. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/Console.mak +46 -0
  786. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/Console.manifest +16 -0
  787. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp +98 -0
  788. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/ConsoleClose.h +39 -0
  789. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp +946 -0
  790. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h +211 -0
  791. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/HashCon.cpp +426 -0
  792. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/HashCon.h +58 -0
  793. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/List.cpp +1417 -0
  794. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/List.h +42 -0
  795. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/Main.cpp +1632 -0
  796. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/MainAr.cpp +235 -0
  797. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp +115 -0
  798. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h +73 -0
  799. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/PercentPrinter.cpp +186 -0
  800. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/PercentPrinter.h +66 -0
  801. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/StdAfx.cpp +3 -0
  802. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/StdAfx.h +11 -0
  803. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp +998 -0
  804. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h +148 -0
  805. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp +118 -0
  806. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/UserInputUtils.h +27 -0
  807. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/makefile +68 -0
  808. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/makefile.gcc +187 -0
  809. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Console/resource.rc +7 -0
  810. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Explorer/MyMessages.cpp +43 -0
  811. hdiffpatch/_c_src/lzma/CPP/7zip/UI/Explorer/MyMessages.h +16 -0
  812. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/BrowseDialog.cpp +1132 -0
  813. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/BrowseDialog.h +32 -0
  814. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/BrowseDialogRes.h +9 -0
  815. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ComboDialog.cpp +64 -0
  816. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ComboDialog.h +28 -0
  817. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ComboDialogRes.h +4 -0
  818. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/DialogSize.h +16 -0
  819. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ExtractCallback.cpp +1272 -0
  820. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ExtractCallback.h +347 -0
  821. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/FormatUtils.cpp +28 -0
  822. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/FormatUtils.h +14 -0
  823. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/LangUtils.h +48 -0
  824. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/MemDialog.cpp +218 -0
  825. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/MemDialog.h +48 -0
  826. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/MemDialogRes.h +13 -0
  827. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/MyWindowsNew.h +119 -0
  828. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/OverwriteDialog.cpp +288 -0
  829. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/OverwriteDialog.h +89 -0
  830. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/OverwriteDialog.rc +93 -0
  831. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/OverwriteDialogRes.h +19 -0
  832. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PasswordDialog.cpp +58 -0
  833. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PasswordDialog.h +28 -0
  834. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PasswordDialog.rc +18 -0
  835. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PasswordDialogRes.h +5 -0
  836. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog.cpp +201 -0
  837. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog.h +171 -0
  838. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog.rc +12 -0
  839. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog2.cpp +1483 -0
  840. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog2.h +355 -0
  841. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog2.rc +40 -0
  842. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog2Res.h +49 -0
  843. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialog2a.rc +85 -0
  844. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/ProgressDialogRes.h +3 -0
  845. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PropertyName.cpp +23 -0
  846. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PropertyName.h +10 -0
  847. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/PropertyNameRes.h +104 -0
  848. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/StdAfx.h +67 -0
  849. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/SysIconUtils.cpp +351 -0
  850. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/SysIconUtils.h +65 -0
  851. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/resource.h +199 -0
  852. hdiffpatch/_c_src/lzma/CPP/7zip/UI/FileManager/resourceGui.h +25 -0
  853. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/7zG.exe.manifest +23 -0
  854. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/Extract.rc +59 -0
  855. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractDialog.cpp +421 -0
  856. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractDialog.h +113 -0
  857. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractDialog.rc +98 -0
  858. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractDialogRes.h +24 -0
  859. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractGUI.cpp +297 -0
  860. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractGUI.h +39 -0
  861. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/ExtractRes.h +51 -0
  862. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/HashGUI.h +27 -0
  863. hdiffpatch/_c_src/lzma/CPP/7zip/UI/GUI/resource2.h +2 -0
  864. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_clang.mak +3 -0
  865. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_clang_arm64.mak +3 -0
  866. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_clang_x64.mak +3 -0
  867. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_clang_x86.mak +3 -0
  868. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_gcc.mak +3 -0
  869. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_gcc_arm64.mak +3 -0
  870. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_gcc_x64.mak +3 -0
  871. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_gcc_x86.mak +3 -0
  872. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_mac_arm64.mak +3 -0
  873. hdiffpatch/_c_src/lzma/CPP/7zip/cmpl_mac_x64.mak +3 -0
  874. hdiffpatch/_c_src/lzma/CPP/7zip/var_clang.mak +11 -0
  875. hdiffpatch/_c_src/lzma/CPP/7zip/var_clang_arm64.mak +19 -0
  876. hdiffpatch/_c_src/lzma/CPP/7zip/var_clang_x64.mak +11 -0
  877. hdiffpatch/_c_src/lzma/CPP/7zip/var_clang_x86.mak +11 -0
  878. hdiffpatch/_c_src/lzma/CPP/7zip/var_gcc.mak +12 -0
  879. hdiffpatch/_c_src/lzma/CPP/7zip/var_gcc_arm64.mak +12 -0
  880. hdiffpatch/_c_src/lzma/CPP/7zip/var_gcc_x64.mak +11 -0
  881. hdiffpatch/_c_src/lzma/CPP/7zip/var_gcc_x86.mak +10 -0
  882. hdiffpatch/_c_src/lzma/CPP/7zip/var_mac_arm64.mak +13 -0
  883. hdiffpatch/_c_src/lzma/CPP/7zip/var_mac_x64.mak +11 -0
  884. hdiffpatch/_c_src/lzma/CPP/7zip/warn_clang.mak +3 -0
  885. hdiffpatch/_c_src/lzma/CPP/7zip/warn_clang_mac.mak +9 -0
  886. hdiffpatch/_c_src/lzma/CPP/7zip/warn_gcc.mak +55 -0
  887. hdiffpatch/_c_src/lzma/CPP/Build.mak +246 -0
  888. hdiffpatch/_c_src/lzma/CPP/Common/AutoPtr.h +46 -0
  889. hdiffpatch/_c_src/lzma/CPP/Common/CRC.cpp +7 -0
  890. hdiffpatch/_c_src/lzma/CPP/Common/C_FileIO.cpp +3 -0
  891. hdiffpatch/_c_src/lzma/CPP/Common/C_FileIO.h +6 -0
  892. hdiffpatch/_c_src/lzma/CPP/Common/ComTry.h +21 -0
  893. hdiffpatch/_c_src/lzma/CPP/Common/CommandLineParser.cpp +231 -0
  894. hdiffpatch/_c_src/lzma/CPP/Common/CommandLineParser.h +63 -0
  895. hdiffpatch/_c_src/lzma/CPP/Common/Common.h +28 -0
  896. hdiffpatch/_c_src/lzma/CPP/Common/Common0.h +330 -0
  897. hdiffpatch/_c_src/lzma/CPP/Common/CrcReg.cpp +77 -0
  898. hdiffpatch/_c_src/lzma/CPP/Common/Defs.h +16 -0
  899. hdiffpatch/_c_src/lzma/CPP/Common/DynLimBuf.cpp +93 -0
  900. hdiffpatch/_c_src/lzma/CPP/Common/DynLimBuf.h +41 -0
  901. hdiffpatch/_c_src/lzma/CPP/Common/DynamicBuffer.h +76 -0
  902. hdiffpatch/_c_src/lzma/CPP/Common/IntToString.cpp +215 -0
  903. hdiffpatch/_c_src/lzma/CPP/Common/IntToString.h +54 -0
  904. hdiffpatch/_c_src/lzma/CPP/Common/Lang.h +30 -0
  905. hdiffpatch/_c_src/lzma/CPP/Common/ListFileUtils.cpp +150 -0
  906. hdiffpatch/_c_src/lzma/CPP/Common/ListFileUtils.h +18 -0
  907. hdiffpatch/_c_src/lzma/CPP/Common/LzFindPrepare.cpp +7 -0
  908. hdiffpatch/_c_src/lzma/CPP/Common/MyBuffer.h +297 -0
  909. hdiffpatch/_c_src/lzma/CPP/Common/MyBuffer2.h +185 -0
  910. hdiffpatch/_c_src/lzma/CPP/Common/MyCom.h +693 -0
  911. hdiffpatch/_c_src/lzma/CPP/Common/MyException.h +14 -0
  912. hdiffpatch/_c_src/lzma/CPP/Common/MyGuidDef.h +63 -0
  913. hdiffpatch/_c_src/lzma/CPP/Common/MyInitGuid.h +57 -0
  914. hdiffpatch/_c_src/lzma/CPP/Common/MyLinux.h +75 -0
  915. hdiffpatch/_c_src/lzma/CPP/Common/MyString.cpp +1871 -0
  916. hdiffpatch/_c_src/lzma/CPP/Common/MyString.h +1078 -0
  917. hdiffpatch/_c_src/lzma/CPP/Common/MyTypes.h +38 -0
  918. hdiffpatch/_c_src/lzma/CPP/Common/MyUnknown.h +8 -0
  919. hdiffpatch/_c_src/lzma/CPP/Common/MyVector.cpp +3 -0
  920. hdiffpatch/_c_src/lzma/CPP/Common/MyVector.h +724 -0
  921. hdiffpatch/_c_src/lzma/CPP/Common/MyWindows.cpp +292 -0
  922. hdiffpatch/_c_src/lzma/CPP/Common/MyWindows.h +325 -0
  923. hdiffpatch/_c_src/lzma/CPP/Common/NewHandler.cpp +340 -0
  924. hdiffpatch/_c_src/lzma/CPP/Common/NewHandler.h +121 -0
  925. hdiffpatch/_c_src/lzma/CPP/Common/Sha256Prepare.cpp +7 -0
  926. hdiffpatch/_c_src/lzma/CPP/Common/Sha256Reg.cpp +67 -0
  927. hdiffpatch/_c_src/lzma/CPP/Common/StdAfx.h +8 -0
  928. hdiffpatch/_c_src/lzma/CPP/Common/StdInStream.cpp +98 -0
  929. hdiffpatch/_c_src/lzma/CPP/Common/StdInStream.h +46 -0
  930. hdiffpatch/_c_src/lzma/CPP/Common/StdOutStream.cpp +248 -0
  931. hdiffpatch/_c_src/lzma/CPP/Common/StdOutStream.h +87 -0
  932. hdiffpatch/_c_src/lzma/CPP/Common/StringConvert.cpp +762 -0
  933. hdiffpatch/_c_src/lzma/CPP/Common/StringConvert.h +110 -0
  934. hdiffpatch/_c_src/lzma/CPP/Common/StringToInt.cpp +154 -0
  935. hdiffpatch/_c_src/lzma/CPP/Common/StringToInt.h +38 -0
  936. hdiffpatch/_c_src/lzma/CPP/Common/TextConfig.cpp +123 -0
  937. hdiffpatch/_c_src/lzma/CPP/Common/TextConfig.h +19 -0
  938. hdiffpatch/_c_src/lzma/CPP/Common/UTFConvert.cpp +863 -0
  939. hdiffpatch/_c_src/lzma/CPP/Common/UTFConvert.h +384 -0
  940. hdiffpatch/_c_src/lzma/CPP/Common/Wildcard.cpp +788 -0
  941. hdiffpatch/_c_src/lzma/CPP/Common/Wildcard.h +231 -0
  942. hdiffpatch/_c_src/lzma/CPP/Common/XzCrc64Init.cpp +7 -0
  943. hdiffpatch/_c_src/lzma/CPP/Common/XzCrc64Reg.cpp +39 -0
  944. hdiffpatch/_c_src/lzma/CPP/Windows/COM.h +86 -0
  945. hdiffpatch/_c_src/lzma/CPP/Windows/Clipboard.cpp +130 -0
  946. hdiffpatch/_c_src/lzma/CPP/Windows/Clipboard.h +28 -0
  947. hdiffpatch/_c_src/lzma/CPP/Windows/CommonDialog.cpp +269 -0
  948. hdiffpatch/_c_src/lzma/CPP/Windows/CommonDialog.h +43 -0
  949. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ComboBox.cpp +66 -0
  950. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ComboBox.h +77 -0
  951. hdiffpatch/_c_src/lzma/CPP/Windows/Control/CommandBar.h +52 -0
  952. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Dialog.cpp +446 -0
  953. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Dialog.h +213 -0
  954. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Edit.h +19 -0
  955. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ImageList.cpp +10 -0
  956. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ImageList.h +87 -0
  957. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ListView.cpp +162 -0
  958. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ListView.h +156 -0
  959. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ProgressBar.h +35 -0
  960. hdiffpatch/_c_src/lzma/CPP/Windows/Control/PropertyPage.cpp +165 -0
  961. hdiffpatch/_c_src/lzma/CPP/Windows/Control/PropertyPage.h +50 -0
  962. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ReBar.h +34 -0
  963. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Static.h +28 -0
  964. hdiffpatch/_c_src/lzma/CPP/Windows/Control/StatusBar.h +42 -0
  965. hdiffpatch/_c_src/lzma/CPP/Windows/Control/StdAfx.h +11 -0
  966. hdiffpatch/_c_src/lzma/CPP/Windows/Control/ToolBar.h +43 -0
  967. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Trackbar.h +27 -0
  968. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Window2.cpp +202 -0
  969. hdiffpatch/_c_src/lzma/CPP/Windows/Control/Window2.h +53 -0
  970. hdiffpatch/_c_src/lzma/CPP/Windows/DLL.cpp +178 -0
  971. hdiffpatch/_c_src/lzma/CPP/Windows/DLL.h +103 -0
  972. hdiffpatch/_c_src/lzma/CPP/Windows/Defs.h +17 -0
  973. hdiffpatch/_c_src/lzma/CPP/Windows/ErrorMsg.cpp +133 -0
  974. hdiffpatch/_c_src/lzma/CPP/Windows/ErrorMsg.h +16 -0
  975. hdiffpatch/_c_src/lzma/CPP/Windows/FileDir.cpp +1331 -0
  976. hdiffpatch/_c_src/lzma/CPP/Windows/FileDir.h +156 -0
  977. hdiffpatch/_c_src/lzma/CPP/Windows/FileFind.cpp +1442 -0
  978. hdiffpatch/_c_src/lzma/CPP/Windows/FileFind.h +347 -0
  979. hdiffpatch/_c_src/lzma/CPP/Windows/FileIO.cpp +954 -0
  980. hdiffpatch/_c_src/lzma/CPP/Windows/FileIO.h +448 -0
  981. hdiffpatch/_c_src/lzma/CPP/Windows/FileLink.cpp +621 -0
  982. hdiffpatch/_c_src/lzma/CPP/Windows/FileMapping.cpp +12 -0
  983. hdiffpatch/_c_src/lzma/CPP/Windows/FileMapping.h +66 -0
  984. hdiffpatch/_c_src/lzma/CPP/Windows/FileName.cpp +896 -0
  985. hdiffpatch/_c_src/lzma/CPP/Windows/FileName.h +133 -0
  986. hdiffpatch/_c_src/lzma/CPP/Windows/FileSystem.cpp +187 -0
  987. hdiffpatch/_c_src/lzma/CPP/Windows/FileSystem.h +31 -0
  988. hdiffpatch/_c_src/lzma/CPP/Windows/Handle.h +39 -0
  989. hdiffpatch/_c_src/lzma/CPP/Windows/MemoryGlobal.cpp +36 -0
  990. hdiffpatch/_c_src/lzma/CPP/Windows/MemoryGlobal.h +55 -0
  991. hdiffpatch/_c_src/lzma/CPP/Windows/MemoryLock.cpp +127 -0
  992. hdiffpatch/_c_src/lzma/CPP/Windows/MemoryLock.h +40 -0
  993. hdiffpatch/_c_src/lzma/CPP/Windows/NtCheck.h +58 -0
  994. hdiffpatch/_c_src/lzma/CPP/Windows/PropVariant.cpp +393 -0
  995. hdiffpatch/_c_src/lzma/CPP/Windows/PropVariant.h +173 -0
  996. hdiffpatch/_c_src/lzma/CPP/Windows/PropVariantConv.cpp +274 -0
  997. hdiffpatch/_c_src/lzma/CPP/Windows/PropVariantConv.h +47 -0
  998. hdiffpatch/_c_src/lzma/CPP/Windows/Registry.cpp +474 -0
  999. hdiffpatch/_c_src/lzma/CPP/Windows/Registry.h +96 -0
  1000. hdiffpatch/_c_src/lzma/CPP/Windows/ResourceString.cpp +103 -0
  1001. hdiffpatch/_c_src/lzma/CPP/Windows/ResourceString.h +17 -0
  1002. hdiffpatch/_c_src/lzma/CPP/Windows/SecurityUtils.cpp +186 -0
  1003. hdiffpatch/_c_src/lzma/CPP/Windows/SecurityUtils.h +150 -0
  1004. hdiffpatch/_c_src/lzma/CPP/Windows/Shell.cpp +839 -0
  1005. hdiffpatch/_c_src/lzma/CPP/Windows/Shell.h +129 -0
  1006. hdiffpatch/_c_src/lzma/CPP/Windows/StdAfx.h +11 -0
  1007. hdiffpatch/_c_src/lzma/CPP/Windows/Synchronization.cpp +87 -0
  1008. hdiffpatch/_c_src/lzma/CPP/Windows/Synchronization.h +386 -0
  1009. hdiffpatch/_c_src/lzma/CPP/Windows/System.cpp +327 -0
  1010. hdiffpatch/_c_src/lzma/CPP/Windows/System.h +132 -0
  1011. hdiffpatch/_c_src/lzma/CPP/Windows/SystemInfo.cpp +1251 -0
  1012. hdiffpatch/_c_src/lzma/CPP/Windows/SystemInfo.h +19 -0
  1013. hdiffpatch/_c_src/lzma/CPP/Windows/Thread.h +44 -0
  1014. hdiffpatch/_c_src/lzma/CPP/Windows/TimeUtils.cpp +466 -0
  1015. hdiffpatch/_c_src/lzma/CPP/Windows/TimeUtils.h +146 -0
  1016. hdiffpatch/_c_src/lzma/CPP/Windows/Window.cpp +179 -0
  1017. hdiffpatch/_c_src/lzma/CPP/Windows/Window.h +363 -0
  1018. hdiffpatch/_c_src/lzma/CS/7zip/Common/CRC.cs +55 -0
  1019. hdiffpatch/_c_src/lzma/CS/7zip/Common/CommandLineParser.cs +274 -0
  1020. hdiffpatch/_c_src/lzma/CS/7zip/Common/InBuffer.cs +72 -0
  1021. hdiffpatch/_c_src/lzma/CS/7zip/Common/OutBuffer.cs +47 -0
  1022. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs +24 -0
  1023. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZ/LzBinTree.cs +367 -0
  1024. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZ/LzInWindow.cs +132 -0
  1025. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs +110 -0
  1026. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs +76 -0
  1027. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs +398 -0
  1028. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs +1480 -0
  1029. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs +364 -0
  1030. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln +20 -0
  1031. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs +340 -0
  1032. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs +29 -0
  1033. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs +70 -0
  1034. hdiffpatch/_c_src/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs +42 -0
  1035. hdiffpatch/_c_src/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs +234 -0
  1036. hdiffpatch/_c_src/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs +117 -0
  1037. hdiffpatch/_c_src/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs +157 -0
  1038. hdiffpatch/_c_src/lzma/CS/7zip/ICoder.cs +157 -0
  1039. hdiffpatch/_c_src/lzma/DOC/7zC.txt +187 -0
  1040. hdiffpatch/_c_src/lzma/DOC/7zFormat.txt +469 -0
  1041. hdiffpatch/_c_src/lzma/DOC/Methods.txt +177 -0
  1042. hdiffpatch/_c_src/lzma/DOC/installer.txt +166 -0
  1043. hdiffpatch/_c_src/lzma/DOC/lzma-history.txt +634 -0
  1044. hdiffpatch/_c_src/lzma/DOC/lzma-sdk.txt +409 -0
  1045. hdiffpatch/_c_src/lzma/DOC/lzma-specification.txt +1176 -0
  1046. hdiffpatch/_c_src/lzma/DOC/lzma.txt +345 -0
  1047. hdiffpatch/_c_src/lzma/Java/SevenZip/CRC.java +52 -0
  1048. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZ/BinTree.java +382 -0
  1049. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZ/InWindow.java +131 -0
  1050. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZ/OutWindow.java +85 -0
  1051. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZMA/Base.java +88 -0
  1052. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZMA/Decoder.java +329 -0
  1053. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/LZMA/Encoder.java +1416 -0
  1054. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java +55 -0
  1055. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java +99 -0
  1056. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java +88 -0
  1057. hdiffpatch/_c_src/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java +151 -0
  1058. hdiffpatch/_c_src/lzma/Java/SevenZip/ICodeProgress.java +6 -0
  1059. hdiffpatch/_c_src/lzma/Java/SevenZip/LzmaAlone.java +253 -0
  1060. hdiffpatch/_c_src/lzma/Java/SevenZip/LzmaBench.java +392 -0
  1061. hdiffpatch/_c_src/lzma/bin/7zS2.sfx +0 -0
  1062. hdiffpatch/_c_src/lzma/bin/7zS2con.sfx +0 -0
  1063. hdiffpatch/_c_src/lzma/bin/7zSD.sfx +0 -0
  1064. hdiffpatch/_c_src/lzma/bin/7zdec.exe +0 -0
  1065. hdiffpatch/_c_src/lzma/bin/7zr.exe +0 -0
  1066. hdiffpatch/_c_src/lzma/bin/installer/config.txt +5 -0
  1067. hdiffpatch/_c_src/lzma/bin/installer/cr.bat +5 -0
  1068. hdiffpatch/_c_src/lzma/bin/lzma.exe +0 -0
  1069. hdiffpatch/_c_src/lzma/bin/x64/7zr.exe +0 -0
  1070. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/argparse/__init__.py +226 -0
  1071. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/collections/__init__.py +16 -0
  1072. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/collections/deque.py +58 -0
  1073. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/fnmatch/__init__.py +139 -0
  1074. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/pathlib/__init__.py +207 -0
  1075. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/shutil/__init__.py +48 -0
  1076. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/tempfile/__init__.py +59 -0
  1077. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/unittest/__init__.py +463 -0
  1078. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/unittest/__main__.py +146 -0
  1079. hdiffpatch/_c_src/tamp/.belay/dependencies/dev/uprofiler/__init__.py +108 -0
  1080. hdiffpatch/_c_src/tamp/.bumpversion.cfg +24 -0
  1081. hdiffpatch/_c_src/tamp/.clang-format +5 -0
  1082. hdiffpatch/_c_src/tamp/.codecov.yml +14 -0
  1083. hdiffpatch/_c_src/tamp/.git +1 -0
  1084. hdiffpatch/_c_src/tamp/.github/FUNDING.yml +13 -0
  1085. hdiffpatch/_c_src/tamp/.github/contributing.md +43 -0
  1086. hdiffpatch/_c_src/tamp/.github/dependabot.yml +11 -0
  1087. hdiffpatch/_c_src/tamp/.github/workflows/build_wheels.yaml +291 -0
  1088. hdiffpatch/_c_src/tamp/.github/workflows/esp_upload_component.yml +49 -0
  1089. hdiffpatch/_c_src/tamp/.github/workflows/mpy_native_module.yaml +236 -0
  1090. hdiffpatch/_c_src/tamp/.github/workflows/tests.yaml +134 -0
  1091. hdiffpatch/_c_src/tamp/.gitignore +262 -0
  1092. hdiffpatch/_c_src/tamp/.gitmodules +3 -0
  1093. hdiffpatch/_c_src/tamp/.pre-commit-config.yaml +69 -0
  1094. hdiffpatch/_c_src/tamp/.readthedocs.yaml +32 -0
  1095. hdiffpatch/_c_src/tamp/LICENSE +201 -0
  1096. hdiffpatch/_c_src/tamp/MICROPYTHON_TESTING.rst +7 -0
  1097. hdiffpatch/_c_src/tamp/Makefile +195 -0
  1098. hdiffpatch/_c_src/tamp/README.md +300 -0
  1099. hdiffpatch/_c_src/tamp/assets/favicon-16x16.png +0 -0
  1100. hdiffpatch/_c_src/tamp/assets/favicon-32x32.png +0 -0
  1101. hdiffpatch/_c_src/tamp/assets/icon.png +0 -0
  1102. hdiffpatch/_c_src/tamp/assets/logo.png +0 -0
  1103. hdiffpatch/_c_src/tamp/assets/logo_200w.png +0 -0
  1104. hdiffpatch/_c_src/tamp/assets/logo_300w.png +0 -0
  1105. hdiffpatch/_c_src/tamp/assets/match-size-plot.png +0 -0
  1106. hdiffpatch/_c_src/tamp/assets/social_media.png +0 -0
  1107. hdiffpatch/_c_src/tamp/build.py +104 -0
  1108. hdiffpatch/_c_src/tamp/ctests/Unity/.editorconfig +27 -0
  1109. hdiffpatch/_c_src/tamp/ctests/Unity/.git +1 -0
  1110. hdiffpatch/_c_src/tamp/ctests/Unity/.gitattributes +31 -0
  1111. hdiffpatch/_c_src/tamp/ctests/Unity/.github/workflows/main.yml +32 -0
  1112. hdiffpatch/_c_src/tamp/ctests/Unity/.gitignore +13 -0
  1113. hdiffpatch/_c_src/tamp/ctests/Unity/CMakeLists.txt +159 -0
  1114. hdiffpatch/_c_src/tamp/ctests/Unity/LICENSE.txt +21 -0
  1115. hdiffpatch/_c_src/tamp/ctests/Unity/README.md +200 -0
  1116. hdiffpatch/_c_src/tamp/ctests/Unity/auto/colour_prompt.rb +119 -0
  1117. hdiffpatch/_c_src/tamp/ctests/Unity/auto/colour_reporter.rb +39 -0
  1118. hdiffpatch/_c_src/tamp/ctests/Unity/auto/generate_config.yml +36 -0
  1119. hdiffpatch/_c_src/tamp/ctests/Unity/auto/generate_module.rb +313 -0
  1120. hdiffpatch/_c_src/tamp/ctests/Unity/auto/generate_test_runner.rb +511 -0
  1121. hdiffpatch/_c_src/tamp/ctests/Unity/auto/parse_output.rb +322 -0
  1122. hdiffpatch/_c_src/tamp/ctests/Unity/auto/run_test.erb +37 -0
  1123. hdiffpatch/_c_src/tamp/ctests/Unity/auto/stylize_as_junit.rb +251 -0
  1124. hdiffpatch/_c_src/tamp/ctests/Unity/auto/test_file_filter.rb +25 -0
  1125. hdiffpatch/_c_src/tamp/ctests/Unity/auto/type_sanitizer.rb +6 -0
  1126. hdiffpatch/_c_src/tamp/ctests/Unity/auto/unity_test_summary.py +139 -0
  1127. hdiffpatch/_c_src/tamp/ctests/Unity/auto/unity_test_summary.rb +135 -0
  1128. hdiffpatch/_c_src/tamp/ctests/Unity/auto/unity_to_junit.py +146 -0
  1129. hdiffpatch/_c_src/tamp/ctests/Unity/docs/ThrowTheSwitchCodingStandard.md +206 -0
  1130. hdiffpatch/_c_src/tamp/ctests/Unity/docs/UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf +0 -0
  1131. hdiffpatch/_c_src/tamp/ctests/Unity/docs/UnityAssertionsReference.md +831 -0
  1132. hdiffpatch/_c_src/tamp/ctests/Unity/docs/UnityConfigurationGuide.md +563 -0
  1133. hdiffpatch/_c_src/tamp/ctests/Unity/docs/UnityGettingStartedGuide.md +251 -0
  1134. hdiffpatch/_c_src/tamp/ctests/Unity/docs/UnityHelperScriptsGuide.md +278 -0
  1135. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/makefile +72 -0
  1136. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/readme.txt +5 -0
  1137. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/src/ProductionCode.c +24 -0
  1138. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/src/ProductionCode.h +3 -0
  1139. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/src/ProductionCode2.c +11 -0
  1140. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/src/ProductionCode2.h +2 -0
  1141. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/test/TestProductionCode.c +62 -0
  1142. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/test/TestProductionCode2.c +31 -0
  1143. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
  1144. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
  1145. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/makefile +71 -0
  1146. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/readme.txt +5 -0
  1147. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/src/ProductionCode.c +24 -0
  1148. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/src/ProductionCode.h +3 -0
  1149. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/src/ProductionCode2.c +11 -0
  1150. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/src/ProductionCode2.h +2 -0
  1151. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/test/TestProductionCode.c +64 -0
  1152. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/test/TestProductionCode2.c +33 -0
  1153. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +9 -0
  1154. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +11 -0
  1155. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_2/test/test_runners/all_tests.c +12 -0
  1156. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/helper/UnityHelper.c +10 -0
  1157. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/helper/UnityHelper.h +12 -0
  1158. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/rakefile.rb +38 -0
  1159. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/rakefile_helper.rb +250 -0
  1160. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/readme.txt +13 -0
  1161. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/src/ProductionCode.c +24 -0
  1162. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/src/ProductionCode.h +3 -0
  1163. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/src/ProductionCode2.c +11 -0
  1164. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/src/ProductionCode2.h +2 -0
  1165. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/target_gcc_32.yml +47 -0
  1166. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/test/TestProductionCode.c +62 -0
  1167. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_3/test/TestProductionCode2.c +31 -0
  1168. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/meson.build +12 -0
  1169. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/readme.txt +15 -0
  1170. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/src/ProductionCode.c +24 -0
  1171. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/src/ProductionCode.h +3 -0
  1172. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/src/ProductionCode2.c +11 -0
  1173. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/src/ProductionCode2.h +2 -0
  1174. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/src/meson.build +16 -0
  1175. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/subprojects/unity.wrap +4 -0
  1176. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/TestProductionCode.c +63 -0
  1177. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/TestProductionCode2.c +35 -0
  1178. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/meson.build +7 -0
  1179. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
  1180. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
  1181. hdiffpatch/_c_src/tamp/ctests/Unity/examples/example_4/test/test_runners/meson.build +13 -0
  1182. hdiffpatch/_c_src/tamp/ctests/Unity/examples/unity_config.h +244 -0
  1183. hdiffpatch/_c_src/tamp/ctests/Unity/extras/eclipse/error_parsers.txt +26 -0
  1184. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/readme.md +29 -0
  1185. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/src/unity_fixture.c +310 -0
  1186. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/src/unity_fixture.h +83 -0
  1187. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/src/unity_fixture_internals.h +50 -0
  1188. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/test/Makefile +72 -0
  1189. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/test/main/AllTests.c +20 -0
  1190. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/test/template_fixture_tests.c +39 -0
  1191. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/test/unity_fixture_Test.c +245 -0
  1192. hdiffpatch/_c_src/tamp/ctests/Unity/extras/fixture/test/unity_fixture_TestRunner.c +32 -0
  1193. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/readme.md +49 -0
  1194. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/src/unity_memory.c +202 -0
  1195. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/src/unity_memory.h +60 -0
  1196. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/test/Makefile +78 -0
  1197. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/test/unity_memory_Test.c +325 -0
  1198. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/test/unity_memory_TestRunner.c +49 -0
  1199. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/test/unity_output_Spy.c +56 -0
  1200. hdiffpatch/_c_src/tamp/ctests/Unity/extras/memory/test/unity_output_Spy.h +16 -0
  1201. hdiffpatch/_c_src/tamp/ctests/Unity/meson.build +14 -0
  1202. hdiffpatch/_c_src/tamp/ctests/Unity/src/meson.build +11 -0
  1203. hdiffpatch/_c_src/tamp/ctests/Unity/src/unity.c +2110 -0
  1204. hdiffpatch/_c_src/tamp/ctests/Unity/src/unity.h +661 -0
  1205. hdiffpatch/_c_src/tamp/ctests/Unity/src/unity_internals.h +1039 -0
  1206. hdiffpatch/_c_src/tamp/ctests/Unity/test/.rubocop.yml +76 -0
  1207. hdiffpatch/_c_src/tamp/ctests/Unity/test/Makefile +160 -0
  1208. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_cmd.c +61 -0
  1209. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_def.c +57 -0
  1210. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_head1.c +55 -0
  1211. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_head1.h +15 -0
  1212. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
  1213. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_def.c +76 -0
  1214. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_head1.c +75 -0
  1215. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_head1.h +13 -0
  1216. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_new1.c +89 -0
  1217. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_new2.c +89 -0
  1218. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_param.c +77 -0
  1219. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_run1.c +89 -0
  1220. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_run2.c +89 -0
  1221. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
  1222. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_new1.c +67 -0
  1223. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_new2.c +70 -0
  1224. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_param.c +58 -0
  1225. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_run1.c +67 -0
  1226. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_run2.c +70 -0
  1227. hdiffpatch/_c_src/tamp/ctests/Unity/test/expectdata/testsample_yaml.c +71 -0
  1228. hdiffpatch/_c_src/tamp/ctests/Unity/test/rakefile +163 -0
  1229. hdiffpatch/_c_src/tamp/ctests/Unity/test/rakefile_helper.rb +315 -0
  1230. hdiffpatch/_c_src/tamp/ctests/Unity/test/spec/generate_module_existing_file_spec.rb +158 -0
  1231. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/ansi.yml +44 -0
  1232. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/clang_file.yml +72 -0
  1233. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/clang_strict.yml +71 -0
  1234. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/gcc_32.yml +45 -0
  1235. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/gcc_64.yml +46 -0
  1236. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/gcc_auto_limits.yml +43 -0
  1237. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/gcc_auto_stdint.yml +55 -0
  1238. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/gcc_manual_math.yml +43 -0
  1239. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/hitech_picc18.yml +91 -0
  1240. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_arm_v4.yml +98 -0
  1241. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_arm_v5.yml +92 -0
  1242. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_arm_v5_3.yml +92 -0
  1243. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_armcortex_LM3S9B92_v5_4.yml +90 -0
  1244. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_cortexm3_v5.yml +94 -0
  1245. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_msp430.yml +112 -0
  1246. hdiffpatch/_c_src/tamp/ctests/Unity/test/targets/iar_sh2a_v6.yml +99 -0
  1247. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/CException.h +11 -0
  1248. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/Defs.h +8 -0
  1249. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/cmock.h +14 -0
  1250. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/mockMock.h +13 -0
  1251. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/testRunnerGenerator.c +189 -0
  1252. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/testRunnerGeneratorSmall.c +70 -0
  1253. hdiffpatch/_c_src/tamp/ctests/Unity/test/testdata/testRunnerGeneratorWithMocks.c +197 -0
  1254. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/self_assessment_utils.h +144 -0
  1255. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_generate_test_runner.rb +1260 -0
  1256. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_arrays.c +2874 -0
  1257. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_core.c +371 -0
  1258. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_doubles.c +773 -0
  1259. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_floats.c +884 -0
  1260. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_integers.c +2847 -0
  1261. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_integers_64.c +773 -0
  1262. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_memory.c +81 -0
  1263. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_parameterized.c +171 -0
  1264. hdiffpatch/_c_src/tamp/ctests/Unity/test/tests/test_unity_strings.c +329 -0
  1265. hdiffpatch/_c_src/tamp/ctests/Unity/unityConfig.cmake +1 -0
  1266. hdiffpatch/_c_src/tamp/ctests/test_decompressor.c +81 -0
  1267. hdiffpatch/_c_src/tamp/docs/Makefile +21 -0
  1268. hdiffpatch/_c_src/tamp/docs/make.bat +35 -0
  1269. hdiffpatch/_c_src/tamp/docs/source/Installation.rst +97 -0
  1270. hdiffpatch/_c_src/tamp/docs/source/_static/.gitkeep +0 -0
  1271. hdiffpatch/_c_src/tamp/docs/source/_static/custom.css +13 -0
  1272. hdiffpatch/_c_src/tamp/docs/source/c_library.rst +339 -0
  1273. hdiffpatch/_c_src/tamp/docs/source/conf.py +195 -0
  1274. hdiffpatch/_c_src/tamp/docs/source/index.rst +16 -0
  1275. hdiffpatch/_c_src/tamp/docs/source/python_api.rst +66 -0
  1276. hdiffpatch/_c_src/tamp/docs/source/specification.rst +189 -0
  1277. hdiffpatch/_c_src/tamp/espidf/.gitignore +2 -0
  1278. hdiffpatch/_c_src/tamp/espidf/CMakeLists.txt +25 -0
  1279. hdiffpatch/_c_src/tamp/espidf/Kconfig +18 -0
  1280. hdiffpatch/_c_src/tamp/espidf/Makefile +4 -0
  1281. hdiffpatch/_c_src/tamp/espidf/compressor_esp32.cpp +139 -0
  1282. hdiffpatch/_c_src/tamp/espidf/idf_component.yml +9 -0
  1283. hdiffpatch/_c_src/tamp/espidf/private/copyutil.hpp +143 -0
  1284. hdiffpatch/_c_src/tamp/espidf/private/tamp_arch.hpp +70 -0
  1285. hdiffpatch/_c_src/tamp/espidf/private/tamp_search.hpp +831 -0
  1286. hdiffpatch/_c_src/tamp/mpy_bindings/bindings.c +293 -0
  1287. hdiffpatch/_c_src/tamp/mpy_bindings/bindings_common.py +16 -0
  1288. hdiffpatch/_c_src/tamp/mpy_bindings/bindings_compressor.py +56 -0
  1289. hdiffpatch/_c_src/tamp/mpy_bindings/bindings_decompressor.py +67 -0
  1290. hdiffpatch/_c_src/tamp/package-compressor.json +14 -0
  1291. hdiffpatch/_c_src/tamp/package-decompressor.json +14 -0
  1292. hdiffpatch/_c_src/tamp/package.json +18 -0
  1293. hdiffpatch/_c_src/tamp/poetry.lock +3348 -0
  1294. hdiffpatch/_c_src/tamp/pyproject.toml +249 -0
  1295. hdiffpatch/_c_src/tamp/tamp/__init__.py +87 -0
  1296. hdiffpatch/_c_src/tamp/tamp/__init__.pyi +57 -0
  1297. hdiffpatch/_c_src/tamp/tamp/__main__.py +3 -0
  1298. hdiffpatch/_c_src/tamp/tamp/_c_common.pxd +4 -0
  1299. hdiffpatch/_c_src/tamp/tamp/_c_common.pyx +15 -0
  1300. hdiffpatch/_c_src/tamp/tamp/_c_compressor.pyx +151 -0
  1301. hdiffpatch/_c_src/tamp/tamp/_c_decompressor.pyx +147 -0
  1302. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/common.c +29 -0
  1303. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/common.h +102 -0
  1304. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/compressor.c +299 -0
  1305. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/compressor.h +240 -0
  1306. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/decompressor.c +233 -0
  1307. hdiffpatch/_c_src/tamp/tamp/_c_src/tamp/decompressor.h +106 -0
  1308. hdiffpatch/_c_src/tamp/tamp/cli/__init__.py +0 -0
  1309. hdiffpatch/_c_src/tamp/tamp/cli/main.py +89 -0
  1310. hdiffpatch/_c_src/tamp/tamp/compressor.py +327 -0
  1311. hdiffpatch/_c_src/tamp/tamp/compressor_viper.py +225 -0
  1312. hdiffpatch/_c_src/tamp/tamp/ctamp.pxd +89 -0
  1313. hdiffpatch/_c_src/tamp/tamp/decompressor.py +336 -0
  1314. hdiffpatch/_c_src/tamp/tamp/decompressor_viper.py +220 -0
  1315. hdiffpatch/_c_src/tamp/tamp/py.typed +0 -0
  1316. hdiffpatch/_c_src/tamp/tests/test_bit_writer_reader.py +59 -0
  1317. hdiffpatch/_c_src/tamp/tests/test_cli.py +78 -0
  1318. hdiffpatch/_c_src/tamp/tests/test_compressor.py +304 -0
  1319. hdiffpatch/_c_src/tamp/tests/test_compressor_decompressor.py +128 -0
  1320. hdiffpatch/_c_src/tamp/tests/test_compressor_helpers.py +19 -0
  1321. hdiffpatch/_c_src/tamp/tests/test_decompressor.py +219 -0
  1322. hdiffpatch/_c_src/tamp/tests/test_file_interface.py +84 -0
  1323. hdiffpatch/_c_src/tamp/tests/test_pseudorandom.py +59 -0
  1324. hdiffpatch/_c_src/tamp/tools/analysis.py +116 -0
  1325. hdiffpatch/_c_src/tamp/tools/c-profiler/.gitignore +1 -0
  1326. hdiffpatch/_c_src/tamp/tools/c-profiler/Makefile +55 -0
  1327. hdiffpatch/_c_src/tamp/tools/c-profiler/main.c +128 -0
  1328. hdiffpatch/_c_src/tamp/tools/collect-data.py +74 -0
  1329. hdiffpatch/_c_src/tamp/tools/compute_min_output_flush_size.py +39 -0
  1330. hdiffpatch/_c_src/tamp/tools/find_seed.py +140 -0
  1331. hdiffpatch/_c_src/tamp/tools/huffman.py +52 -0
  1332. hdiffpatch/_c_src/tamp/tools/huffman_jump_table.py +47 -0
  1333. hdiffpatch/_c_src/tamp/tools/micropython-compression-benchmark.py +19 -0
  1334. hdiffpatch/_c_src/tamp/tools/on-device-compression-benchmark.py +27 -0
  1335. hdiffpatch/_c_src/tamp/tools/on-device-decompression-benchmark.py +27 -0
  1336. hdiffpatch/_c_src/tamp/tools/performance-benchmark.sh +13 -0
  1337. hdiffpatch/_c_src/tamp/tools/pi_pico/.gitignore +4 -0
  1338. hdiffpatch/_c_src/tamp/tools/pi_pico/benchmark/CMakeLists.txt +60 -0
  1339. hdiffpatch/_c_src/tamp/tools/pi_pico/benchmark/Makefile +12 -0
  1340. hdiffpatch/_c_src/tamp/tools/pi_pico/benchmark/main.c +67 -0
  1341. hdiffpatch/_c_src/tamp/tools/pi_pico/library-size/.gitignore +3 -0
  1342. hdiffpatch/_c_src/tamp/tools/pi_pico/library-size/CMakeLists.txt +43 -0
  1343. hdiffpatch/_c_src/tamp/tools/pi_pico/library-size/Makefile +45 -0
  1344. hdiffpatch/_c_src/tamp/tools/pi_pico/library-size/README.md +3 -0
  1345. hdiffpatch/_c_src/tamp/tools/profiler.py +15 -0
  1346. hdiffpatch/_c_src/tamp/tools/zlib_compress.py +20 -0
  1347. hdiffpatch/_c_src/tamp/tools/zlib_decompress.py +11 -0
  1348. hdiffpatch/_c_src/tamp_compress_plugin.cpp +328 -0
  1349. hdiffpatch/_c_src/zlib/.git +1 -0
  1350. hdiffpatch/_c_src/zlib/.github/workflows/cmake.yml +89 -0
  1351. hdiffpatch/_c_src/zlib/.github/workflows/configure.yml +136 -0
  1352. hdiffpatch/_c_src/zlib/.github/workflows/fuzz.yml +25 -0
  1353. hdiffpatch/_c_src/zlib/.gitignore +36 -0
  1354. hdiffpatch/_c_src/zlib/CMakeLists.txt +218 -0
  1355. hdiffpatch/_c_src/zlib/ChangeLog +1618 -0
  1356. hdiffpatch/_c_src/zlib/FAQ +367 -0
  1357. hdiffpatch/_c_src/zlib/INDEX +68 -0
  1358. hdiffpatch/_c_src/zlib/LICENSE +22 -0
  1359. hdiffpatch/_c_src/zlib/Makefile +5 -0
  1360. hdiffpatch/_c_src/zlib/Makefile.in +410 -0
  1361. hdiffpatch/_c_src/zlib/README +117 -0
  1362. hdiffpatch/_c_src/zlib/adler32.c +164 -0
  1363. hdiffpatch/_c_src/zlib/amiga/Makefile.pup +69 -0
  1364. hdiffpatch/_c_src/zlib/amiga/Makefile.sas +68 -0
  1365. hdiffpatch/_c_src/zlib/compress.c +75 -0
  1366. hdiffpatch/_c_src/zlib/configure +929 -0
  1367. hdiffpatch/_c_src/zlib/contrib/README.contrib +57 -0
  1368. hdiffpatch/_c_src/zlib/contrib/ada/buffer_demo.adb +106 -0
  1369. hdiffpatch/_c_src/zlib/contrib/ada/mtest.adb +156 -0
  1370. hdiffpatch/_c_src/zlib/contrib/ada/read.adb +156 -0
  1371. hdiffpatch/_c_src/zlib/contrib/ada/readme.txt +65 -0
  1372. hdiffpatch/_c_src/zlib/contrib/ada/test.adb +463 -0
  1373. hdiffpatch/_c_src/zlib/contrib/ada/zlib-streams.adb +225 -0
  1374. hdiffpatch/_c_src/zlib/contrib/ada/zlib-streams.ads +114 -0
  1375. hdiffpatch/_c_src/zlib/contrib/ada/zlib-thin.adb +141 -0
  1376. hdiffpatch/_c_src/zlib/contrib/ada/zlib-thin.ads +450 -0
  1377. hdiffpatch/_c_src/zlib/contrib/ada/zlib.adb +701 -0
  1378. hdiffpatch/_c_src/zlib/contrib/ada/zlib.ads +328 -0
  1379. hdiffpatch/_c_src/zlib/contrib/ada/zlib.gpr +20 -0
  1380. hdiffpatch/_c_src/zlib/contrib/blast/Makefile +8 -0
  1381. hdiffpatch/_c_src/zlib/contrib/blast/README +4 -0
  1382. hdiffpatch/_c_src/zlib/contrib/blast/blast.c +466 -0
  1383. hdiffpatch/_c_src/zlib/contrib/blast/blast.h +83 -0
  1384. hdiffpatch/_c_src/zlib/contrib/blast/test.pk +0 -0
  1385. hdiffpatch/_c_src/zlib/contrib/blast/test.txt +1 -0
  1386. hdiffpatch/_c_src/zlib/contrib/delphi/ZLib.pas +557 -0
  1387. hdiffpatch/_c_src/zlib/contrib/delphi/ZLibConst.pas +11 -0
  1388. hdiffpatch/_c_src/zlib/contrib/delphi/readme.txt +76 -0
  1389. hdiffpatch/_c_src/zlib/contrib/delphi/zlibd32.mak +99 -0
  1390. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
  1391. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
  1392. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
  1393. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
  1394. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
  1395. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
  1396. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
  1397. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
  1398. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
  1399. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
  1400. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib.build +33 -0
  1401. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib.chm +0 -0
  1402. hdiffpatch/_c_src/zlib/contrib/dotzlib/DotZLib.sln +21 -0
  1403. hdiffpatch/_c_src/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
  1404. hdiffpatch/_c_src/zlib/contrib/dotzlib/readme.txt +58 -0
  1405. hdiffpatch/_c_src/zlib/contrib/gcc_gvmat64/gvmat64.S +574 -0
  1406. hdiffpatch/_c_src/zlib/contrib/infback9/README +1 -0
  1407. hdiffpatch/_c_src/zlib/contrib/infback9/infback9.c +603 -0
  1408. hdiffpatch/_c_src/zlib/contrib/infback9/infback9.h +37 -0
  1409. hdiffpatch/_c_src/zlib/contrib/infback9/inffix9.h +107 -0
  1410. hdiffpatch/_c_src/zlib/contrib/infback9/inflate9.h +47 -0
  1411. hdiffpatch/_c_src/zlib/contrib/infback9/inftree9.c +319 -0
  1412. hdiffpatch/_c_src/zlib/contrib/infback9/inftree9.h +61 -0
  1413. hdiffpatch/_c_src/zlib/contrib/iostream/test.cpp +24 -0
  1414. hdiffpatch/_c_src/zlib/contrib/iostream/zfstream.cpp +329 -0
  1415. hdiffpatch/_c_src/zlib/contrib/iostream/zfstream.h +128 -0
  1416. hdiffpatch/_c_src/zlib/contrib/iostream2/zstream.h +307 -0
  1417. hdiffpatch/_c_src/zlib/contrib/iostream2/zstream_test.cpp +25 -0
  1418. hdiffpatch/_c_src/zlib/contrib/iostream3/README +35 -0
  1419. hdiffpatch/_c_src/zlib/contrib/iostream3/TODO +17 -0
  1420. hdiffpatch/_c_src/zlib/contrib/iostream3/test.cc +50 -0
  1421. hdiffpatch/_c_src/zlib/contrib/iostream3/zfstream.cc +479 -0
  1422. hdiffpatch/_c_src/zlib/contrib/iostream3/zfstream.h +466 -0
  1423. hdiffpatch/_c_src/zlib/contrib/minizip/Makefile +29 -0
  1424. hdiffpatch/_c_src/zlib/contrib/minizip/Makefile.am +45 -0
  1425. hdiffpatch/_c_src/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
  1426. hdiffpatch/_c_src/zlib/contrib/minizip/MiniZip64_info.txt +74 -0
  1427. hdiffpatch/_c_src/zlib/contrib/minizip/configure.ac +32 -0
  1428. hdiffpatch/_c_src/zlib/contrib/minizip/crypt.h +128 -0
  1429. hdiffpatch/_c_src/zlib/contrib/minizip/ioapi.c +231 -0
  1430. hdiffpatch/_c_src/zlib/contrib/minizip/ioapi.h +210 -0
  1431. hdiffpatch/_c_src/zlib/contrib/minizip/iowin32.c +440 -0
  1432. hdiffpatch/_c_src/zlib/contrib/minizip/iowin32.h +28 -0
  1433. hdiffpatch/_c_src/zlib/contrib/minizip/make_vms.com +25 -0
  1434. hdiffpatch/_c_src/zlib/contrib/minizip/miniunz.c +647 -0
  1435. hdiffpatch/_c_src/zlib/contrib/minizip/miniunzip.1 +63 -0
  1436. hdiffpatch/_c_src/zlib/contrib/minizip/minizip.1 +46 -0
  1437. hdiffpatch/_c_src/zlib/contrib/minizip/minizip.c +509 -0
  1438. hdiffpatch/_c_src/zlib/contrib/minizip/minizip.pc.in +12 -0
  1439. hdiffpatch/_c_src/zlib/contrib/minizip/mztools.c +285 -0
  1440. hdiffpatch/_c_src/zlib/contrib/minizip/mztools.h +37 -0
  1441. hdiffpatch/_c_src/zlib/contrib/minizip/unzip.c +1985 -0
  1442. hdiffpatch/_c_src/zlib/contrib/minizip/unzip.h +437 -0
  1443. hdiffpatch/_c_src/zlib/contrib/minizip/zip.c +1956 -0
  1444. hdiffpatch/_c_src/zlib/contrib/minizip/zip.h +364 -0
  1445. hdiffpatch/_c_src/zlib/contrib/nuget/nuget.csproj +43 -0
  1446. hdiffpatch/_c_src/zlib/contrib/nuget/nuget.sln +22 -0
  1447. hdiffpatch/_c_src/zlib/contrib/pascal/example.pas +599 -0
  1448. hdiffpatch/_c_src/zlib/contrib/pascal/readme.txt +76 -0
  1449. hdiffpatch/_c_src/zlib/contrib/pascal/zlibd32.mak +99 -0
  1450. hdiffpatch/_c_src/zlib/contrib/pascal/zlibpas.pas +276 -0
  1451. hdiffpatch/_c_src/zlib/contrib/puff/Makefile +42 -0
  1452. hdiffpatch/_c_src/zlib/contrib/puff/README +63 -0
  1453. hdiffpatch/_c_src/zlib/contrib/puff/puff.c +840 -0
  1454. hdiffpatch/_c_src/zlib/contrib/puff/puff.h +35 -0
  1455. hdiffpatch/_c_src/zlib/contrib/puff/pufftest.c +165 -0
  1456. hdiffpatch/_c_src/zlib/contrib/puff/zeros.raw +0 -0
  1457. hdiffpatch/_c_src/zlib/contrib/testzlib/testzlib.c +275 -0
  1458. hdiffpatch/_c_src/zlib/contrib/testzlib/testzlib.txt +10 -0
  1459. hdiffpatch/_c_src/zlib/contrib/untgz/Makefile +14 -0
  1460. hdiffpatch/_c_src/zlib/contrib/untgz/Makefile.msc +17 -0
  1461. hdiffpatch/_c_src/zlib/contrib/untgz/untgz.c +667 -0
  1462. hdiffpatch/_c_src/zlib/contrib/vstudio/readme.txt +81 -0
  1463. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/miniunz.vcxproj +310 -0
  1464. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/miniunz.vcxproj.filters +22 -0
  1465. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/minizip.vcxproj +307 -0
  1466. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/minizip.vcxproj.filters +22 -0
  1467. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/testzlib.vcxproj +412 -0
  1468. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/testzlib.vcxproj.filters +55 -0
  1469. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj +310 -0
  1470. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/testzlibdll.vcxproj.filters +22 -0
  1471. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlib.rc +32 -0
  1472. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibstat.vcxproj +449 -0
  1473. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters +74 -0
  1474. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibvc.def +158 -0
  1475. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibvc.sln +135 -0
  1476. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibvc.vcxproj +633 -0
  1477. hdiffpatch/_c_src/zlib/contrib/vstudio/vc10/zlibvc.vcxproj.filters +115 -0
  1478. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/miniunz.vcxproj +314 -0
  1479. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/minizip.vcxproj +311 -0
  1480. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/testzlib.vcxproj +418 -0
  1481. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/testzlibdll.vcxproj +314 -0
  1482. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/zlib.rc +32 -0
  1483. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/zlibstat.vcxproj +456 -0
  1484. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/zlibvc.def +158 -0
  1485. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/zlibvc.sln +117 -0
  1486. hdiffpatch/_c_src/zlib/contrib/vstudio/vc11/zlibvc.vcxproj +664 -0
  1487. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/miniunz.vcxproj +316 -0
  1488. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/minizip.vcxproj +313 -0
  1489. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/testzlib.vcxproj +422 -0
  1490. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/testzlibdll.vcxproj +316 -0
  1491. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/zlib.rc +32 -0
  1492. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/zlibstat.vcxproj +459 -0
  1493. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/zlibvc.def +158 -0
  1494. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/zlibvc.sln +119 -0
  1495. hdiffpatch/_c_src/zlib/contrib/vstudio/vc12/zlibvc.vcxproj +668 -0
  1496. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/miniunz.vcxproj +316 -0
  1497. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/minizip.vcxproj +313 -0
  1498. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/testzlib.vcxproj +422 -0
  1499. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/testzlibdll.vcxproj +316 -0
  1500. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/zlib.rc +32 -0
  1501. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/zlibstat.vcxproj +459 -0
  1502. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/zlibvc.def +158 -0
  1503. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/zlibvc.sln +119 -0
  1504. hdiffpatch/_c_src/zlib/contrib/vstudio/vc14/zlibvc.vcxproj +668 -0
  1505. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/miniunz.vcxproj +409 -0
  1506. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/minizip.vcxproj +405 -0
  1507. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/testzlib.vcxproj +473 -0
  1508. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/testzlibdll.vcxproj +409 -0
  1509. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/zlib.rc +32 -0
  1510. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/zlibstat.vcxproj +602 -0
  1511. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/zlibvc.def +158 -0
  1512. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/zlibvc.sln +179 -0
  1513. hdiffpatch/_c_src/zlib/contrib/vstudio/vc17/zlibvc.vcxproj +875 -0
  1514. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/miniunz.vcproj +565 -0
  1515. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/minizip.vcproj +562 -0
  1516. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/testzlib.vcproj +796 -0
  1517. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/testzlibdll.vcproj +565 -0
  1518. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/zlib.rc +32 -0
  1519. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/zlibstat.vcproj +781 -0
  1520. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/zlibvc.def +158 -0
  1521. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/zlibvc.sln +144 -0
  1522. hdiffpatch/_c_src/zlib/contrib/vstudio/vc9/zlibvc.vcproj +1100 -0
  1523. hdiffpatch/_c_src/zlib/crc32.c +1049 -0
  1524. hdiffpatch/_c_src/zlib/crc32.h +9446 -0
  1525. hdiffpatch/_c_src/zlib/deflate.c +2159 -0
  1526. hdiffpatch/_c_src/zlib/deflate.h +377 -0
  1527. hdiffpatch/_c_src/zlib/doc/algorithm.txt +209 -0
  1528. hdiffpatch/_c_src/zlib/doc/crc-doc.1.0.pdf +0 -0
  1529. hdiffpatch/_c_src/zlib/doc/rfc1950.txt +619 -0
  1530. hdiffpatch/_c_src/zlib/doc/rfc1951.txt +955 -0
  1531. hdiffpatch/_c_src/zlib/doc/rfc1952.txt +675 -0
  1532. hdiffpatch/_c_src/zlib/doc/txtvsbin.txt +107 -0
  1533. hdiffpatch/_c_src/zlib/examples/README.examples +54 -0
  1534. hdiffpatch/_c_src/zlib/examples/enough.c +597 -0
  1535. hdiffpatch/_c_src/zlib/examples/fitblk.c +233 -0
  1536. hdiffpatch/_c_src/zlib/examples/gun.c +702 -0
  1537. hdiffpatch/_c_src/zlib/examples/gzappend.c +504 -0
  1538. hdiffpatch/_c_src/zlib/examples/gzjoin.c +449 -0
  1539. hdiffpatch/_c_src/zlib/examples/gzlog.c +1061 -0
  1540. hdiffpatch/_c_src/zlib/examples/gzlog.h +91 -0
  1541. hdiffpatch/_c_src/zlib/examples/gznorm.c +470 -0
  1542. hdiffpatch/_c_src/zlib/examples/zlib_how.html +549 -0
  1543. hdiffpatch/_c_src/zlib/examples/zpipe.c +205 -0
  1544. hdiffpatch/_c_src/zlib/examples/zran.c +533 -0
  1545. hdiffpatch/_c_src/zlib/examples/zran.h +51 -0
  1546. hdiffpatch/_c_src/zlib/gzclose.c +23 -0
  1547. hdiffpatch/_c_src/zlib/gzguts.h +214 -0
  1548. hdiffpatch/_c_src/zlib/gzlib.c +582 -0
  1549. hdiffpatch/_c_src/zlib/gzread.c +602 -0
  1550. hdiffpatch/_c_src/zlib/gzwrite.c +631 -0
  1551. hdiffpatch/_c_src/zlib/infback.c +628 -0
  1552. hdiffpatch/_c_src/zlib/inffast.c +320 -0
  1553. hdiffpatch/_c_src/zlib/inffast.h +11 -0
  1554. hdiffpatch/_c_src/zlib/inffixed.h +94 -0
  1555. hdiffpatch/_c_src/zlib/inflate.c +1546 -0
  1556. hdiffpatch/_c_src/zlib/inflate.h +126 -0
  1557. hdiffpatch/_c_src/zlib/inftrees.c +299 -0
  1558. hdiffpatch/_c_src/zlib/inftrees.h +62 -0
  1559. hdiffpatch/_c_src/zlib/make_vms.com +867 -0
  1560. hdiffpatch/_c_src/zlib/msdos/Makefile.bor +115 -0
  1561. hdiffpatch/_c_src/zlib/msdos/Makefile.dj2 +104 -0
  1562. hdiffpatch/_c_src/zlib/msdos/Makefile.emx +69 -0
  1563. hdiffpatch/_c_src/zlib/msdos/Makefile.msc +112 -0
  1564. hdiffpatch/_c_src/zlib/msdos/Makefile.tc +100 -0
  1565. hdiffpatch/_c_src/zlib/nintendods/Makefile +126 -0
  1566. hdiffpatch/_c_src/zlib/nintendods/README +5 -0
  1567. hdiffpatch/_c_src/zlib/old/Makefile.emx +69 -0
  1568. hdiffpatch/_c_src/zlib/old/Makefile.riscos +151 -0
  1569. hdiffpatch/_c_src/zlib/old/README +3 -0
  1570. hdiffpatch/_c_src/zlib/old/descrip.mms +48 -0
  1571. hdiffpatch/_c_src/zlib/old/os2/Makefile.os2 +136 -0
  1572. hdiffpatch/_c_src/zlib/old/os2/zlib.def +51 -0
  1573. hdiffpatch/_c_src/zlib/old/visual-basic.txt +160 -0
  1574. hdiffpatch/_c_src/zlib/os400/README400 +48 -0
  1575. hdiffpatch/_c_src/zlib/os400/bndsrc +127 -0
  1576. hdiffpatch/_c_src/zlib/os400/make.sh +366 -0
  1577. hdiffpatch/_c_src/zlib/os400/zlib.inc +527 -0
  1578. hdiffpatch/_c_src/zlib/qnx/package.qpg +141 -0
  1579. hdiffpatch/_c_src/zlib/test/example.c +546 -0
  1580. hdiffpatch/_c_src/zlib/test/infcover.c +672 -0
  1581. hdiffpatch/_c_src/zlib/test/minigzip.c +579 -0
  1582. hdiffpatch/_c_src/zlib/treebuild.xml +116 -0
  1583. hdiffpatch/_c_src/zlib/trees.c +1117 -0
  1584. hdiffpatch/_c_src/zlib/trees.h +128 -0
  1585. hdiffpatch/_c_src/zlib/uncompr.c +85 -0
  1586. hdiffpatch/_c_src/zlib/watcom/watcom_f.mak +43 -0
  1587. hdiffpatch/_c_src/zlib/watcom/watcom_l.mak +43 -0
  1588. hdiffpatch/_c_src/zlib/win32/DLL_FAQ.txt +381 -0
  1589. hdiffpatch/_c_src/zlib/win32/Makefile.bor +109 -0
  1590. hdiffpatch/_c_src/zlib/win32/Makefile.gcc +177 -0
  1591. hdiffpatch/_c_src/zlib/win32/Makefile.msc +159 -0
  1592. hdiffpatch/_c_src/zlib/win32/README-WIN32.txt +103 -0
  1593. hdiffpatch/_c_src/zlib/win32/VisualC.txt +3 -0
  1594. hdiffpatch/_c_src/zlib/win32/zlib.def +97 -0
  1595. hdiffpatch/_c_src/zlib/win32/zlib1.rc +40 -0
  1596. hdiffpatch/_c_src/zlib/zconf.h +543 -0
  1597. hdiffpatch/_c_src/zlib/zconf.h.cmakein +545 -0
  1598. hdiffpatch/_c_src/zlib/zconf.h.in +543 -0
  1599. hdiffpatch/_c_src/zlib/zlib.3 +149 -0
  1600. hdiffpatch/_c_src/zlib/zlib.3.pdf +0 -0
  1601. hdiffpatch/_c_src/zlib/zlib.h +1945 -0
  1602. hdiffpatch/_c_src/zlib/zlib.map +100 -0
  1603. hdiffpatch/_c_src/zlib/zlib.pc.cmakein +13 -0
  1604. hdiffpatch/_c_src/zlib/zlib.pc.in +13 -0
  1605. hdiffpatch/_c_src/zlib/zutil.c +299 -0
  1606. hdiffpatch/_c_src/zlib/zutil.h +254 -0
  1607. hdiffpatch/_c_src/zstd/.buckconfig +9 -0
  1608. hdiffpatch/_c_src/zstd/.buckversion +1 -0
  1609. hdiffpatch/_c_src/zstd/.cirrus.yml +9 -0
  1610. hdiffpatch/_c_src/zstd/.git +1 -0
  1611. hdiffpatch/_c_src/zstd/.gitattributes +21 -0
  1612. hdiffpatch/_c_src/zstd/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  1613. hdiffpatch/_c_src/zstd/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  1614. hdiffpatch/_c_src/zstd/.github/dependabot.yml +6 -0
  1615. hdiffpatch/_c_src/zstd/.github/workflows/android-ndk-build.yml +39 -0
  1616. hdiffpatch/_c_src/zstd/.github/workflows/commit.yml +104 -0
  1617. hdiffpatch/_c_src/zstd/.github/workflows/dev-long-tests.yml +313 -0
  1618. hdiffpatch/_c_src/zstd/.github/workflows/dev-short-tests.yml +725 -0
  1619. hdiffpatch/_c_src/zstd/.github/workflows/nightly.yml +38 -0
  1620. hdiffpatch/_c_src/zstd/.github/workflows/publish-release-artifacts.yml +73 -0
  1621. hdiffpatch/_c_src/zstd/.github/workflows/scorecards.yml +64 -0
  1622. hdiffpatch/_c_src/zstd/.github/workflows/windows-artifacts.yml +58 -0
  1623. hdiffpatch/_c_src/zstd/.gitignore +63 -0
  1624. hdiffpatch/_c_src/zstd/CHANGELOG +863 -0
  1625. hdiffpatch/_c_src/zstd/CODE_OF_CONDUCT.md +5 -0
  1626. hdiffpatch/_c_src/zstd/CONTRIBUTING.md +489 -0
  1627. hdiffpatch/_c_src/zstd/COPYING +339 -0
  1628. hdiffpatch/_c_src/zstd/LICENSE +30 -0
  1629. hdiffpatch/_c_src/zstd/Makefile +471 -0
  1630. hdiffpatch/_c_src/zstd/Package.swift +36 -0
  1631. hdiffpatch/_c_src/zstd/README.md +237 -0
  1632. hdiffpatch/_c_src/zstd/SECURITY.md +15 -0
  1633. hdiffpatch/_c_src/zstd/TESTING.md +43 -0
  1634. hdiffpatch/_c_src/zstd/build/.gitignore +33 -0
  1635. hdiffpatch/_c_src/zstd/build/LICENSE +0 -0
  1636. hdiffpatch/_c_src/zstd/build/README.md +56 -0
  1637. hdiffpatch/_c_src/zstd/build/VS2008/fullbench/fullbench.vcproj +549 -0
  1638. hdiffpatch/_c_src/zstd/build/VS2008/fuzzer/fuzzer.vcproj +585 -0
  1639. hdiffpatch/_c_src/zstd/build/VS2008/zstd/zstd.vcproj +677 -0
  1640. hdiffpatch/_c_src/zstd/build/VS2008/zstd.sln +56 -0
  1641. hdiffpatch/_c_src/zstd/build/VS2008/zstdlib/zstdlib.vcproj +635 -0
  1642. hdiffpatch/_c_src/zstd/build/VS2010/CompileAsCpp.props +8 -0
  1643. hdiffpatch/_c_src/zstd/build/VS2010/datagen/datagen.vcxproj +170 -0
  1644. hdiffpatch/_c_src/zstd/build/VS2010/fullbench/fullbench.vcxproj +220 -0
  1645. hdiffpatch/_c_src/zstd/build/VS2010/fuzzer/fuzzer.vcxproj +224 -0
  1646. hdiffpatch/_c_src/zstd/build/VS2010/libzstd/libzstd.vcxproj +243 -0
  1647. hdiffpatch/_c_src/zstd/build/VS2010/libzstd-dll/libzstd-dll.rc +51 -0
  1648. hdiffpatch/_c_src/zstd/build/VS2010/libzstd-dll/libzstd-dll.vcxproj +250 -0
  1649. hdiffpatch/_c_src/zstd/build/VS2010/zstd/zstd.rc +51 -0
  1650. hdiffpatch/_c_src/zstd/build/VS2010/zstd/zstd.vcxproj +266 -0
  1651. hdiffpatch/_c_src/zstd/build/VS2010/zstd.sln +84 -0
  1652. hdiffpatch/_c_src/zstd/build/VS_scripts/README.md +64 -0
  1653. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2010.cmd +7 -0
  1654. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2012.cmd +6 -0
  1655. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2013.cmd +7 -0
  1656. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2015.cmd +7 -0
  1657. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2017.cmd +7 -0
  1658. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2017Community.cmd +7 -0
  1659. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2017Enterprise.cmd +7 -0
  1660. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VS2017Professional.cmd +7 -0
  1661. hdiffpatch/_c_src/zstd/build/VS_scripts/build.VSPreview.cmd +7 -0
  1662. hdiffpatch/_c_src/zstd/build/VS_scripts/build.generic.cmd +67 -0
  1663. hdiffpatch/_c_src/zstd/build/cmake/.gitignore +10 -0
  1664. hdiffpatch/_c_src/zstd/build/cmake/CMakeLists.txt +228 -0
  1665. hdiffpatch/_c_src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake +136 -0
  1666. hdiffpatch/_c_src/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake +49 -0
  1667. hdiffpatch/_c_src/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake +10 -0
  1668. hdiffpatch/_c_src/zstd/build/cmake/CMakeModules/JoinPaths.cmake +23 -0
  1669. hdiffpatch/_c_src/zstd/build/cmake/README.md +146 -0
  1670. hdiffpatch/_c_src/zstd/build/cmake/contrib/CMakeLists.txt +13 -0
  1671. hdiffpatch/_c_src/zstd/build/cmake/contrib/gen_html/CMakeLists.txt +30 -0
  1672. hdiffpatch/_c_src/zstd/build/cmake/contrib/pzstd/CMakeLists.txt +39 -0
  1673. hdiffpatch/_c_src/zstd/build/cmake/lib/.gitignore +2 -0
  1674. hdiffpatch/_c_src/zstd/build/cmake/lib/CMakeLists.txt +295 -0
  1675. hdiffpatch/_c_src/zstd/build/cmake/lib/cmake_uninstall.cmake.in +22 -0
  1676. hdiffpatch/_c_src/zstd/build/cmake/programs/.gitignore +5 -0
  1677. hdiffpatch/_c_src/zstd/build/cmake/programs/CMakeLists.txt +144 -0
  1678. hdiffpatch/_c_src/zstd/build/cmake/tests/.gitignore +6 -0
  1679. hdiffpatch/_c_src/zstd/build/cmake/tests/CMakeLists.txt +118 -0
  1680. hdiffpatch/_c_src/zstd/build/cmake/zstdConfig.cmake.in +10 -0
  1681. hdiffpatch/_c_src/zstd/build/meson/GetZstdLibraryVersion.py +39 -0
  1682. hdiffpatch/_c_src/zstd/build/meson/InstallSymlink.py +55 -0
  1683. hdiffpatch/_c_src/zstd/build/meson/README.md +38 -0
  1684. hdiffpatch/_c_src/zstd/build/meson/contrib/gen_html/meson.build +30 -0
  1685. hdiffpatch/_c_src/zstd/build/meson/contrib/meson.build +12 -0
  1686. hdiffpatch/_c_src/zstd/build/meson/contrib/pzstd/meson.build +25 -0
  1687. hdiffpatch/_c_src/zstd/build/meson/lib/meson.build +171 -0
  1688. hdiffpatch/_c_src/zstd/build/meson/meson.build +156 -0
  1689. hdiffpatch/_c_src/zstd/build/meson/meson_options.txt +36 -0
  1690. hdiffpatch/_c_src/zstd/build/meson/programs/meson.build +124 -0
  1691. hdiffpatch/_c_src/zstd/build/meson/tests/meson.build +217 -0
  1692. hdiffpatch/_c_src/zstd/build/meson/tests/valgrindTest.py +90 -0
  1693. hdiffpatch/_c_src/zstd/build/single_file_libs/.gitignore +10 -0
  1694. hdiffpatch/_c_src/zstd/build/single_file_libs/README.md +33 -0
  1695. hdiffpatch/_c_src/zstd/build/single_file_libs/build_decoder_test.sh +91 -0
  1696. hdiffpatch/_c_src/zstd/build/single_file_libs/build_library_test.sh +98 -0
  1697. hdiffpatch/_c_src/zstd/build/single_file_libs/combine.py +234 -0
  1698. hdiffpatch/_c_src/zstd/build/single_file_libs/combine.sh +249 -0
  1699. hdiffpatch/_c_src/zstd/build/single_file_libs/create_single_file_decoder.sh +19 -0
  1700. hdiffpatch/_c_src/zstd/build/single_file_libs/create_single_file_library.sh +19 -0
  1701. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/README.md +11 -0
  1702. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/emscripten.c +340 -0
  1703. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/roundtrip.c +83 -0
  1704. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/shell.html +31 -0
  1705. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/simple.c +75 -0
  1706. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/testcard-dxt1.inl +2731 -0
  1707. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/testcard-zstd.inl +261 -0
  1708. hdiffpatch/_c_src/zstd/build/single_file_libs/examples/testcard.png +0 -0
  1709. hdiffpatch/_c_src/zstd/build/single_file_libs/zstd-in.c +91 -0
  1710. hdiffpatch/_c_src/zstd/build/single_file_libs/zstddeclib-in.c +62 -0
  1711. hdiffpatch/_c_src/zstd/contrib/VS2005/README.md +3 -0
  1712. hdiffpatch/_c_src/zstd/contrib/VS2005/fullbench/fullbench.vcproj +440 -0
  1713. hdiffpatch/_c_src/zstd/contrib/VS2005/fuzzer/fuzzer.vcproj +488 -0
  1714. hdiffpatch/_c_src/zstd/contrib/VS2005/zstd/zstd.vcproj +552 -0
  1715. hdiffpatch/_c_src/zstd/contrib/VS2005/zstd.sln +55 -0
  1716. hdiffpatch/_c_src/zstd/contrib/VS2005/zstdlib/zstdlib.vcproj +546 -0
  1717. hdiffpatch/_c_src/zstd/contrib/cleanTabs +2 -0
  1718. hdiffpatch/_c_src/zstd/contrib/diagnose_corruption/.gitignore +1 -0
  1719. hdiffpatch/_c_src/zstd/contrib/diagnose_corruption/Makefile +35 -0
  1720. hdiffpatch/_c_src/zstd/contrib/diagnose_corruption/check_flipped_bits.c +400 -0
  1721. hdiffpatch/_c_src/zstd/contrib/docker/Dockerfile +20 -0
  1722. hdiffpatch/_c_src/zstd/contrib/docker/README.md +20 -0
  1723. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/.gitignore +2 -0
  1724. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/Makefile +40 -0
  1725. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/README.md +14 -0
  1726. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/main.c +107 -0
  1727. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/sequence_producer.c +80 -0
  1728. hdiffpatch/_c_src/zstd/contrib/externalSequenceProducer/sequence_producer.h +26 -0
  1729. hdiffpatch/_c_src/zstd/contrib/freestanding_lib/freestanding.py +774 -0
  1730. hdiffpatch/_c_src/zstd/contrib/gen_html/.gitignore +3 -0
  1731. hdiffpatch/_c_src/zstd/contrib/gen_html/Makefile +51 -0
  1732. hdiffpatch/_c_src/zstd/contrib/gen_html/README.md +31 -0
  1733. hdiffpatch/_c_src/zstd/contrib/gen_html/gen-zstd-manual.sh +9 -0
  1734. hdiffpatch/_c_src/zstd/contrib/gen_html/gen_html.cpp +225 -0
  1735. hdiffpatch/_c_src/zstd/contrib/largeNbDicts/.gitignore +2 -0
  1736. hdiffpatch/_c_src/zstd/contrib/largeNbDicts/Makefile +58 -0
  1737. hdiffpatch/_c_src/zstd/contrib/largeNbDicts/README.md +33 -0
  1738. hdiffpatch/_c_src/zstd/contrib/largeNbDicts/largeNbDicts.c +1085 -0
  1739. hdiffpatch/_c_src/zstd/contrib/linux-kernel/.gitignore +4 -0
  1740. hdiffpatch/_c_src/zstd/contrib/linux-kernel/Makefile +108 -0
  1741. hdiffpatch/_c_src/zstd/contrib/linux-kernel/README.md +14 -0
  1742. hdiffpatch/_c_src/zstd/contrib/linux-kernel/btrfs-benchmark.sh +104 -0
  1743. hdiffpatch/_c_src/zstd/contrib/linux-kernel/btrfs-extract-benchmark.sh +99 -0
  1744. hdiffpatch/_c_src/zstd/contrib/linux-kernel/decompress_sources.h +34 -0
  1745. hdiffpatch/_c_src/zstd/contrib/linux-kernel/linux.mk +44 -0
  1746. hdiffpatch/_c_src/zstd/contrib/linux-kernel/linux_zstd.h +525 -0
  1747. hdiffpatch/_c_src/zstd/contrib/linux-kernel/mem.h +262 -0
  1748. hdiffpatch/_c_src/zstd/contrib/linux-kernel/squashfs-benchmark.sh +39 -0
  1749. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/Makefile +49 -0
  1750. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/compiler.h +23 -0
  1751. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/errno.h +15 -0
  1752. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/kernel.h +19 -0
  1753. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/limits.h +15 -0
  1754. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/math64.h +15 -0
  1755. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/module.h +20 -0
  1756. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/printk.h +15 -0
  1757. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/stddef.h +15 -0
  1758. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/swab.h +16 -0
  1759. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/types.h +16 -0
  1760. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/unaligned.h +187 -0
  1761. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/include/linux/xxhash.h +745 -0
  1762. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/macro-test.sh +44 -0
  1763. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/static_test.c +52 -0
  1764. hdiffpatch/_c_src/zstd/contrib/linux-kernel/test/test.c +229 -0
  1765. hdiffpatch/_c_src/zstd/contrib/linux-kernel/zstd_common_module.c +29 -0
  1766. hdiffpatch/_c_src/zstd/contrib/linux-kernel/zstd_compress_module.c +237 -0
  1767. hdiffpatch/_c_src/zstd/contrib/linux-kernel/zstd_decompress_module.c +105 -0
  1768. hdiffpatch/_c_src/zstd/contrib/linux-kernel/zstd_deps.h +121 -0
  1769. hdiffpatch/_c_src/zstd/contrib/match_finders/README.md +42 -0
  1770. hdiffpatch/_c_src/zstd/contrib/match_finders/zstd_edist.c +558 -0
  1771. hdiffpatch/_c_src/zstd/contrib/match_finders/zstd_edist.h +70 -0
  1772. hdiffpatch/_c_src/zstd/contrib/premake/premake4.lua +6 -0
  1773. hdiffpatch/_c_src/zstd/contrib/premake/zstd.lua +80 -0
  1774. hdiffpatch/_c_src/zstd/contrib/pzstd/.gitignore +2 -0
  1775. hdiffpatch/_c_src/zstd/contrib/pzstd/BUCK +72 -0
  1776. hdiffpatch/_c_src/zstd/contrib/pzstd/ErrorHolder.h +54 -0
  1777. hdiffpatch/_c_src/zstd/contrib/pzstd/Logging.h +72 -0
  1778. hdiffpatch/_c_src/zstd/contrib/pzstd/Makefile +265 -0
  1779. hdiffpatch/_c_src/zstd/contrib/pzstd/Options.cpp +424 -0
  1780. hdiffpatch/_c_src/zstd/contrib/pzstd/Options.h +71 -0
  1781. hdiffpatch/_c_src/zstd/contrib/pzstd/Pzstd.cpp +626 -0
  1782. hdiffpatch/_c_src/zstd/contrib/pzstd/Pzstd.h +153 -0
  1783. hdiffpatch/_c_src/zstd/contrib/pzstd/README.md +56 -0
  1784. hdiffpatch/_c_src/zstd/contrib/pzstd/SkippableFrame.cpp +30 -0
  1785. hdiffpatch/_c_src/zstd/contrib/pzstd/SkippableFrame.h +64 -0
  1786. hdiffpatch/_c_src/zstd/contrib/pzstd/images/Cspeed.png +0 -0
  1787. hdiffpatch/_c_src/zstd/contrib/pzstd/images/Dspeed.png +0 -0
  1788. hdiffpatch/_c_src/zstd/contrib/pzstd/main.cpp +27 -0
  1789. hdiffpatch/_c_src/zstd/contrib/pzstd/test/BUCK +37 -0
  1790. hdiffpatch/_c_src/zstd/contrib/pzstd/test/OptionsTest.cpp +536 -0
  1791. hdiffpatch/_c_src/zstd/contrib/pzstd/test/PzstdTest.cpp +147 -0
  1792. hdiffpatch/_c_src/zstd/contrib/pzstd/test/RoundTrip.h +86 -0
  1793. hdiffpatch/_c_src/zstd/contrib/pzstd/test/RoundTripTest.cpp +84 -0
  1794. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/BUCK +75 -0
  1795. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/Buffer.h +99 -0
  1796. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/FileSystem.h +96 -0
  1797. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/Likely.h +28 -0
  1798. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/Portability.h +16 -0
  1799. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/Range.h +133 -0
  1800. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/ResourcePool.h +96 -0
  1801. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/ScopeGuard.h +50 -0
  1802. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/ThreadPool.h +58 -0
  1803. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/WorkQueue.h +182 -0
  1804. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/BUCK +35 -0
  1805. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/BufferTest.cpp +89 -0
  1806. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/RangeTest.cpp +82 -0
  1807. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/ResourcePoolTest.cpp +72 -0
  1808. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/ScopeGuardTest.cpp +28 -0
  1809. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/ThreadPoolTest.cpp +71 -0
  1810. hdiffpatch/_c_src/zstd/contrib/pzstd/utils/test/WorkQueueTest.cpp +282 -0
  1811. hdiffpatch/_c_src/zstd/contrib/recovery/Makefile +35 -0
  1812. hdiffpatch/_c_src/zstd/contrib/recovery/recover_directory.c +152 -0
  1813. hdiffpatch/_c_src/zstd/contrib/seekable_format/README.md +42 -0
  1814. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/.gitignore +5 -0
  1815. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/Makefile +53 -0
  1816. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/parallel_compression.c +214 -0
  1817. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/parallel_processing.c +194 -0
  1818. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/seekable_compression.c +136 -0
  1819. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/seekable_decompression.c +141 -0
  1820. hdiffpatch/_c_src/zstd/contrib/seekable_format/examples/seekable_decompression_mem.c +147 -0
  1821. hdiffpatch/_c_src/zstd/contrib/seekable_format/tests/.gitignore +1 -0
  1822. hdiffpatch/_c_src/zstd/contrib/seekable_format/tests/Makefile +38 -0
  1823. hdiffpatch/_c_src/zstd/contrib/seekable_format/tests/seekable_tests.c +363 -0
  1824. hdiffpatch/_c_src/zstd/contrib/seekable_format/zstd_seekable.h +226 -0
  1825. hdiffpatch/_c_src/zstd/contrib/seekable_format/zstd_seekable_compression_format.md +116 -0
  1826. hdiffpatch/_c_src/zstd/contrib/seekable_format/zstdseek_compress.c +365 -0
  1827. hdiffpatch/_c_src/zstd/contrib/seekable_format/zstdseek_decompress.c +600 -0
  1828. hdiffpatch/_c_src/zstd/contrib/seqBench/Makefile +58 -0
  1829. hdiffpatch/_c_src/zstd/contrib/seqBench/seqBench.c +53 -0
  1830. hdiffpatch/_c_src/zstd/contrib/snap/snapcraft.yaml +28 -0
  1831. hdiffpatch/_c_src/zstd/doc/README.md +26 -0
  1832. hdiffpatch/_c_src/zstd/doc/decompressor_errata.md +148 -0
  1833. hdiffpatch/_c_src/zstd/doc/decompressor_permissive.md +80 -0
  1834. hdiffpatch/_c_src/zstd/doc/educational_decoder/.gitignore +2 -0
  1835. hdiffpatch/_c_src/zstd/doc/educational_decoder/Makefile +62 -0
  1836. hdiffpatch/_c_src/zstd/doc/educational_decoder/README.md +36 -0
  1837. hdiffpatch/_c_src/zstd/doc/educational_decoder/harness.c +119 -0
  1838. hdiffpatch/_c_src/zstd/doc/educational_decoder/zstd_decompress.c +2323 -0
  1839. hdiffpatch/_c_src/zstd/doc/educational_decoder/zstd_decompress.h +61 -0
  1840. hdiffpatch/_c_src/zstd/doc/images/CSpeed2.png +0 -0
  1841. hdiffpatch/_c_src/zstd/doc/images/DCspeed5.png +0 -0
  1842. hdiffpatch/_c_src/zstd/doc/images/DSpeed3.png +0 -0
  1843. hdiffpatch/_c_src/zstd/doc/images/cdict_v136.png +0 -0
  1844. hdiffpatch/_c_src/zstd/doc/images/dict-cr.png +0 -0
  1845. hdiffpatch/_c_src/zstd/doc/images/dict-cs.png +0 -0
  1846. hdiffpatch/_c_src/zstd/doc/images/dict-ds.png +0 -0
  1847. hdiffpatch/_c_src/zstd/doc/images/zstd_cdict_v1_3_5.png +0 -0
  1848. hdiffpatch/_c_src/zstd/doc/images/zstd_logo86.png +0 -0
  1849. hdiffpatch/_c_src/zstd/doc/zstd_compression_format.md +1771 -0
  1850. hdiffpatch/_c_src/zstd/doc/zstd_manual.html +2237 -0
  1851. hdiffpatch/_c_src/zstd/examples/.gitignore +15 -0
  1852. hdiffpatch/_c_src/zstd/examples/Makefile +93 -0
  1853. hdiffpatch/_c_src/zstd/examples/README.md +46 -0
  1854. hdiffpatch/_c_src/zstd/examples/common.h +246 -0
  1855. hdiffpatch/_c_src/zstd/examples/dictionary_compression.c +107 -0
  1856. hdiffpatch/_c_src/zstd/examples/dictionary_decompression.c +99 -0
  1857. hdiffpatch/_c_src/zstd/examples/multiple_simple_compression.c +116 -0
  1858. hdiffpatch/_c_src/zstd/examples/multiple_streaming_compression.c +133 -0
  1859. hdiffpatch/_c_src/zstd/examples/simple_compression.c +68 -0
  1860. hdiffpatch/_c_src/zstd/examples/simple_decompression.c +65 -0
  1861. hdiffpatch/_c_src/zstd/examples/streaming_compression.c +146 -0
  1862. hdiffpatch/_c_src/zstd/examples/streaming_compression_thread_pool.c +180 -0
  1863. hdiffpatch/_c_src/zstd/examples/streaming_decompression.c +100 -0
  1864. hdiffpatch/_c_src/zstd/examples/streaming_memory_usage.c +137 -0
  1865. hdiffpatch/_c_src/zstd/lib/.gitignore +3 -0
  1866. hdiffpatch/_c_src/zstd/lib/BUCK +232 -0
  1867. hdiffpatch/_c_src/zstd/lib/Makefile +389 -0
  1868. hdiffpatch/_c_src/zstd/lib/README.md +248 -0
  1869. hdiffpatch/_c_src/zstd/lib/common/allocations.h +55 -0
  1870. hdiffpatch/_c_src/zstd/lib/common/bits.h +205 -0
  1871. hdiffpatch/_c_src/zstd/lib/common/bitstream.h +454 -0
  1872. hdiffpatch/_c_src/zstd/lib/common/compiler.h +464 -0
  1873. hdiffpatch/_c_src/zstd/lib/common/cpu.h +249 -0
  1874. hdiffpatch/_c_src/zstd/lib/common/debug.c +30 -0
  1875. hdiffpatch/_c_src/zstd/lib/common/debug.h +107 -0
  1876. hdiffpatch/_c_src/zstd/lib/common/entropy_common.c +340 -0
  1877. hdiffpatch/_c_src/zstd/lib/common/error_private.c +64 -0
  1878. hdiffpatch/_c_src/zstd/lib/common/error_private.h +158 -0
  1879. hdiffpatch/_c_src/zstd/lib/common/fse.h +625 -0
  1880. hdiffpatch/_c_src/zstd/lib/common/fse_decompress.c +315 -0
  1881. hdiffpatch/_c_src/zstd/lib/common/huf.h +277 -0
  1882. hdiffpatch/_c_src/zstd/lib/common/mem.h +422 -0
  1883. hdiffpatch/_c_src/zstd/lib/common/pool.c +371 -0
  1884. hdiffpatch/_c_src/zstd/lib/common/pool.h +81 -0
  1885. hdiffpatch/_c_src/zstd/lib/common/portability_macros.h +171 -0
  1886. hdiffpatch/_c_src/zstd/lib/common/threading.c +182 -0
  1887. hdiffpatch/_c_src/zstd/lib/common/threading.h +142 -0
  1888. hdiffpatch/_c_src/zstd/lib/common/xxhash.c +18 -0
  1889. hdiffpatch/_c_src/zstd/lib/common/xxhash.h +7094 -0
  1890. hdiffpatch/_c_src/zstd/lib/common/zstd_common.c +48 -0
  1891. hdiffpatch/_c_src/zstd/lib/common/zstd_deps.h +123 -0
  1892. hdiffpatch/_c_src/zstd/lib/common/zstd_internal.h +324 -0
  1893. hdiffpatch/_c_src/zstd/lib/common/zstd_trace.h +156 -0
  1894. hdiffpatch/_c_src/zstd/lib/compress/clevels.h +134 -0
  1895. hdiffpatch/_c_src/zstd/lib/compress/fse_compress.c +625 -0
  1896. hdiffpatch/_c_src/zstd/lib/compress/hist.c +191 -0
  1897. hdiffpatch/_c_src/zstd/lib/compress/hist.h +82 -0
  1898. hdiffpatch/_c_src/zstd/lib/compress/huf_compress.c +1464 -0
  1899. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress.c +7942 -0
  1900. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_internal.h +1640 -0
  1901. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_literals.c +235 -0
  1902. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_literals.h +39 -0
  1903. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_sequences.c +442 -0
  1904. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_sequences.h +55 -0
  1905. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_superblock.c +688 -0
  1906. hdiffpatch/_c_src/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  1907. hdiffpatch/_c_src/zstd/lib/compress/zstd_cwksp.h +765 -0
  1908. hdiffpatch/_c_src/zstd/lib/compress/zstd_double_fast.c +778 -0
  1909. hdiffpatch/_c_src/zstd/lib/compress/zstd_double_fast.h +42 -0
  1910. hdiffpatch/_c_src/zstd/lib/compress/zstd_fast.c +985 -0
  1911. hdiffpatch/_c_src/zstd/lib/compress/zstd_fast.h +30 -0
  1912. hdiffpatch/_c_src/zstd/lib/compress/zstd_lazy.c +2199 -0
  1913. hdiffpatch/_c_src/zstd/lib/compress/zstd_lazy.h +193 -0
  1914. hdiffpatch/_c_src/zstd/lib/compress/zstd_ldm.c +745 -0
  1915. hdiffpatch/_c_src/zstd/lib/compress/zstd_ldm.h +109 -0
  1916. hdiffpatch/_c_src/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  1917. hdiffpatch/_c_src/zstd/lib/compress/zstd_opt.c +1580 -0
  1918. hdiffpatch/_c_src/zstd/lib/compress/zstd_opt.h +72 -0
  1919. hdiffpatch/_c_src/zstd/lib/compress/zstd_preSplit.c +238 -0
  1920. hdiffpatch/_c_src/zstd/lib/compress/zstd_preSplit.h +33 -0
  1921. hdiffpatch/_c_src/zstd/lib/compress/zstdmt_compress.c +1923 -0
  1922. hdiffpatch/_c_src/zstd/lib/compress/zstdmt_compress.h +102 -0
  1923. hdiffpatch/_c_src/zstd/lib/decompress/huf_decompress.c +1944 -0
  1924. hdiffpatch/_c_src/zstd/lib/decompress/huf_decompress_amd64.S +602 -0
  1925. hdiffpatch/_c_src/zstd/lib/decompress/zstd_ddict.c +244 -0
  1926. hdiffpatch/_c_src/zstd/lib/decompress/zstd_ddict.h +44 -0
  1927. hdiffpatch/_c_src/zstd/lib/decompress/zstd_decompress.c +2410 -0
  1928. hdiffpatch/_c_src/zstd/lib/decompress/zstd_decompress_block.c +2209 -0
  1929. hdiffpatch/_c_src/zstd/lib/decompress/zstd_decompress_block.h +73 -0
  1930. hdiffpatch/_c_src/zstd/lib/decompress/zstd_decompress_internal.h +240 -0
  1931. hdiffpatch/_c_src/zstd/lib/deprecated/zbuff.h +214 -0
  1932. hdiffpatch/_c_src/zstd/lib/deprecated/zbuff_common.c +26 -0
  1933. hdiffpatch/_c_src/zstd/lib/deprecated/zbuff_compress.c +167 -0
  1934. hdiffpatch/_c_src/zstd/lib/deprecated/zbuff_decompress.c +77 -0
  1935. hdiffpatch/_c_src/zstd/lib/dictBuilder/cover.c +1302 -0
  1936. hdiffpatch/_c_src/zstd/lib/dictBuilder/cover.h +152 -0
  1937. hdiffpatch/_c_src/zstd/lib/dictBuilder/divsufsort.c +1913 -0
  1938. hdiffpatch/_c_src/zstd/lib/dictBuilder/divsufsort.h +57 -0
  1939. hdiffpatch/_c_src/zstd/lib/dictBuilder/fastcover.c +766 -0
  1940. hdiffpatch/_c_src/zstd/lib/dictBuilder/zdict.c +1133 -0
  1941. hdiffpatch/_c_src/zstd/lib/dll/example/Makefile +48 -0
  1942. hdiffpatch/_c_src/zstd/lib/dll/example/README.md +63 -0
  1943. hdiffpatch/_c_src/zstd/lib/dll/example/build_package.bat +20 -0
  1944. hdiffpatch/_c_src/zstd/lib/dll/example/fullbench-dll.sln +25 -0
  1945. hdiffpatch/_c_src/zstd/lib/dll/example/fullbench-dll.vcxproj +181 -0
  1946. hdiffpatch/_c_src/zstd/lib/legacy/zstd_legacy.h +452 -0
  1947. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v01.c +2127 -0
  1948. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v01.h +94 -0
  1949. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v02.c +3465 -0
  1950. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v02.h +93 -0
  1951. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v03.c +3105 -0
  1952. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v03.h +93 -0
  1953. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v04.c +3598 -0
  1954. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v04.h +142 -0
  1955. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v05.c +4005 -0
  1956. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v05.h +162 -0
  1957. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v06.c +4110 -0
  1958. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v06.h +172 -0
  1959. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v07.c +4490 -0
  1960. hdiffpatch/_c_src/zstd/lib/legacy/zstd_v07.h +187 -0
  1961. hdiffpatch/_c_src/zstd/lib/libzstd.mk +235 -0
  1962. hdiffpatch/_c_src/zstd/lib/libzstd.pc.in +16 -0
  1963. hdiffpatch/_c_src/zstd/lib/module.modulemap +35 -0
  1964. hdiffpatch/_c_src/zstd/lib/zdict.h +481 -0
  1965. hdiffpatch/_c_src/zstd/lib/zstd.h +3206 -0
  1966. hdiffpatch/_c_src/zstd/lib/zstd_errors.h +107 -0
  1967. hdiffpatch/_c_src/zstd/programs/.gitignore +41 -0
  1968. hdiffpatch/_c_src/zstd/programs/BUCK +44 -0
  1969. hdiffpatch/_c_src/zstd/programs/Makefile +445 -0
  1970. hdiffpatch/_c_src/zstd/programs/README.md +344 -0
  1971. hdiffpatch/_c_src/zstd/programs/benchfn.c +256 -0
  1972. hdiffpatch/_c_src/zstd/programs/benchfn.h +173 -0
  1973. hdiffpatch/_c_src/zstd/programs/benchzstd.c +1281 -0
  1974. hdiffpatch/_c_src/zstd/programs/benchzstd.h +191 -0
  1975. hdiffpatch/_c_src/zstd/programs/datagen.c +186 -0
  1976. hdiffpatch/_c_src/zstd/programs/datagen.h +38 -0
  1977. hdiffpatch/_c_src/zstd/programs/dibio.c +440 -0
  1978. hdiffpatch/_c_src/zstd/programs/dibio.h +39 -0
  1979. hdiffpatch/_c_src/zstd/programs/fileio.c +3464 -0
  1980. hdiffpatch/_c_src/zstd/programs/fileio.h +171 -0
  1981. hdiffpatch/_c_src/zstd/programs/fileio_asyncio.c +663 -0
  1982. hdiffpatch/_c_src/zstd/programs/fileio_asyncio.h +195 -0
  1983. hdiffpatch/_c_src/zstd/programs/fileio_common.h +121 -0
  1984. hdiffpatch/_c_src/zstd/programs/fileio_types.h +86 -0
  1985. hdiffpatch/_c_src/zstd/programs/lorem.c +285 -0
  1986. hdiffpatch/_c_src/zstd/programs/lorem.h +32 -0
  1987. hdiffpatch/_c_src/zstd/programs/platform.h +217 -0
  1988. hdiffpatch/_c_src/zstd/programs/timefn.c +168 -0
  1989. hdiffpatch/_c_src/zstd/programs/timefn.h +59 -0
  1990. hdiffpatch/_c_src/zstd/programs/util.c +1643 -0
  1991. hdiffpatch/_c_src/zstd/programs/util.h +362 -0
  1992. hdiffpatch/_c_src/zstd/programs/windres/verrsrc.h +17 -0
  1993. hdiffpatch/_c_src/zstd/programs/windres/zstd.rc +51 -0
  1994. hdiffpatch/_c_src/zstd/programs/windres/zstd32.res +0 -0
  1995. hdiffpatch/_c_src/zstd/programs/windres/zstd64.res +0 -0
  1996. hdiffpatch/_c_src/zstd/programs/zstd.1 +392 -0
  1997. hdiffpatch/_c_src/zstd/programs/zstd.1.md +714 -0
  1998. hdiffpatch/_c_src/zstd/programs/zstdcli.c +1658 -0
  1999. hdiffpatch/_c_src/zstd/programs/zstdcli_trace.c +172 -0
  2000. hdiffpatch/_c_src/zstd/programs/zstdcli_trace.h +24 -0
  2001. hdiffpatch/_c_src/zstd/programs/zstdgrep +134 -0
  2002. hdiffpatch/_c_src/zstd/programs/zstdgrep.1 +26 -0
  2003. hdiffpatch/_c_src/zstd/programs/zstdgrep.1.md +30 -0
  2004. hdiffpatch/_c_src/zstd/programs/zstdless +8 -0
  2005. hdiffpatch/_c_src/zstd/programs/zstdless.1 +14 -0
  2006. hdiffpatch/_c_src/zstd/programs/zstdless.1.md +16 -0
  2007. hdiffpatch/_c_src/zstd/tests/.gitignore +72 -0
  2008. hdiffpatch/_c_src/zstd/tests/DEPRECATED-test-zstd-speed.py +378 -0
  2009. hdiffpatch/_c_src/zstd/tests/Makefile +481 -0
  2010. hdiffpatch/_c_src/zstd/tests/README.md +184 -0
  2011. hdiffpatch/_c_src/zstd/tests/automated_benchmarking.py +326 -0
  2012. hdiffpatch/_c_src/zstd/tests/bigdict.c +133 -0
  2013. hdiffpatch/_c_src/zstd/tests/checkTag.c +65 -0
  2014. hdiffpatch/_c_src/zstd/tests/check_size.py +31 -0
  2015. hdiffpatch/_c_src/zstd/tests/cli-tests/.gitignore +6 -0
  2016. hdiffpatch/_c_src/zstd/tests/cli-tests/README.md +258 -0
  2017. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/args.sh +10 -0
  2018. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/args.sh.exit +1 -0
  2019. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/args.sh.stderr.glob +28 -0
  2020. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/help.sh +10 -0
  2021. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/help.sh.stdout.glob +34 -0
  2022. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/memlimit.sh +40 -0
  2023. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/memlimit.sh.stderr.exact +13 -0
  2024. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/memlimit.sh.stdout.exact +13 -0
  2025. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/output_dir.sh +7 -0
  2026. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/output_dir.sh.stderr.exact +2 -0
  2027. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/output_dir.sh.stdout.exact +2 -0
  2028. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/version.sh +6 -0
  2029. hdiffpatch/_c_src/zstd/tests/cli-tests/basic/version.sh.stdout.glob +2 -0
  2030. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/cmp_size +44 -0
  2031. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/datagen +3 -0
  2032. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/die +4 -0
  2033. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/println +2 -0
  2034. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/zstd +9 -0
  2035. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/zstdgrep +2 -0
  2036. hdiffpatch/_c_src/zstd/tests/cli-tests/bin/zstdless +2 -0
  2037. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/setup +6 -0
  2038. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdgrep.sh +8 -0
  2039. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdgrep.sh.exit +1 -0
  2040. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdgrep.sh.stderr.exact +1 -0
  2041. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdgrep.sh.stdout.glob +4 -0
  2042. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdless.sh +10 -0
  2043. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdless.sh.stderr.exact +2 -0
  2044. hdiffpatch/_c_src/zstd/tests/cli-tests/cltools/zstdless.sh.stdout.glob +5 -0
  2045. hdiffpatch/_c_src/zstd/tests/cli-tests/common/format.sh +19 -0
  2046. hdiffpatch/_c_src/zstd/tests/cli-tests/common/mtime.sh +13 -0
  2047. hdiffpatch/_c_src/zstd/tests/cli-tests/common/permissions.sh +18 -0
  2048. hdiffpatch/_c_src/zstd/tests/cli-tests/common/platform.sh +36 -0
  2049. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/adapt.sh +14 -0
  2050. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/basic.sh +36 -0
  2051. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/compress-literals.sh +10 -0
  2052. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/format.sh +16 -0
  2053. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/golden.sh +16 -0
  2054. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/gzip-compat.sh +17 -0
  2055. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/levels.sh +75 -0
  2056. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/levels.sh.stderr.exact +80 -0
  2057. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/long-distance-matcher.sh +7 -0
  2058. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/multi-threaded.sh +15 -0
  2059. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/multi-threaded.sh.stderr.exact +11 -0
  2060. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/multiple-files.sh +21 -0
  2061. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/multiple-files.sh.stdout.exact +12 -0
  2062. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/row-match-finder.sh +7 -0
  2063. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/setup +7 -0
  2064. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/stream-size.sh +7 -0
  2065. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/verbose-wlog.sh +11 -0
  2066. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/verbose-wlog.sh.stderr.glob +5 -0
  2067. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/verbose-wlog.sh.stdout.glob +5 -0
  2068. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/window-resize.sh +9 -0
  2069. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/window-resize.sh.stderr.ignore +0 -0
  2070. hdiffpatch/_c_src/zstd/tests/cli-tests/compression/window-resize.sh.stdout.glob +3 -0
  2071. hdiffpatch/_c_src/zstd/tests/cli-tests/decompression/detectErrors.sh +11 -0
  2072. hdiffpatch/_c_src/zstd/tests/cli-tests/decompression/golden.sh +7 -0
  2073. hdiffpatch/_c_src/zstd/tests/cli-tests/decompression/pass-through.sh +57 -0
  2074. hdiffpatch/_c_src/zstd/tests/cli-tests/decompression/pass-through.sh.stderr.exact +11 -0
  2075. hdiffpatch/_c_src/zstd/tests/cli-tests/decompression/pass-through.sh.stdout.exact +25 -0
  2076. hdiffpatch/_c_src/zstd/tests/cli-tests/dict-builder/empty-input.sh +9 -0
  2077. hdiffpatch/_c_src/zstd/tests/cli-tests/dict-builder/empty-input.sh.stderr.exact +1 -0
  2078. hdiffpatch/_c_src/zstd/tests/cli-tests/dict-builder/no-inputs.sh +3 -0
  2079. hdiffpatch/_c_src/zstd/tests/cli-tests/dict-builder/no-inputs.sh.exit +1 -0
  2080. hdiffpatch/_c_src/zstd/tests/cli-tests/dict-builder/no-inputs.sh.stderr.exact +5 -0
  2081. hdiffpatch/_c_src/zstd/tests/cli-tests/dictionaries/dictionary-mismatch.sh +29 -0
  2082. hdiffpatch/_c_src/zstd/tests/cli-tests/dictionaries/dictionary-mismatch.sh.stderr.exact +7 -0
  2083. hdiffpatch/_c_src/zstd/tests/cli-tests/dictionaries/golden.sh +9 -0
  2084. hdiffpatch/_c_src/zstd/tests/cli-tests/dictionaries/setup +6 -0
  2085. hdiffpatch/_c_src/zstd/tests/cli-tests/dictionaries/setup_once +24 -0
  2086. hdiffpatch/_c_src/zstd/tests/cli-tests/file-handling/directory-mirror.sh +49 -0
  2087. hdiffpatch/_c_src/zstd/tests/cli-tests/file-handling/directory-mirror.sh.stderr.exact +0 -0
  2088. hdiffpatch/_c_src/zstd/tests/cli-tests/file-handling/directory-mirror.sh.stdout.exact +0 -0
  2089. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-dir-without-write-perm.sh +12 -0
  2090. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-dir-without-write-perm.sh.stderr.exact +26 -0
  2091. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-file.sh +9 -0
  2092. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-file.sh.stderr.exact +42 -0
  2093. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-stdout.sh +8 -0
  2094. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-file-to-stdout.sh.stderr.exact +24 -0
  2095. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-stdin-to-file.sh +8 -0
  2096. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-stdin-to-file.sh.stderr.exact +24 -0
  2097. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-stdin-to-stdout.sh +8 -0
  2098. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/compress-stdin-to-stdout.sh.stderr.exact +18 -0
  2099. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-file-to-file.sh +8 -0
  2100. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-file-to-file.sh.stderr.exact +38 -0
  2101. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-file-to-stdout.sh +7 -0
  2102. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-file-to-stdout.sh.stderr.exact +18 -0
  2103. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-stdin-to-file.sh +7 -0
  2104. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-stdin-to-file.sh.stderr.exact +20 -0
  2105. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-stdin-to-stdout.sh +7 -0
  2106. hdiffpatch/_c_src/zstd/tests/cli-tests/file-stat/decompress-stdin-to-stdout.sh.stderr.exact +14 -0
  2107. hdiffpatch/_c_src/zstd/tests/cli-tests/progress/no-progress.sh +46 -0
  2108. hdiffpatch/_c_src/zstd/tests/cli-tests/progress/no-progress.sh.stderr.glob +96 -0
  2109. hdiffpatch/_c_src/zstd/tests/cli-tests/progress/progress.sh +41 -0
  2110. hdiffpatch/_c_src/zstd/tests/cli-tests/progress/progress.sh.stderr.glob +62 -0
  2111. hdiffpatch/_c_src/zstd/tests/cli-tests/run.py +731 -0
  2112. hdiffpatch/_c_src/zstd/tests/cli-tests/zstd-symlinks/setup +6 -0
  2113. hdiffpatch/_c_src/zstd/tests/cli-tests/zstd-symlinks/zstdcat.sh +12 -0
  2114. hdiffpatch/_c_src/zstd/tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact +8 -0
  2115. hdiffpatch/_c_src/zstd/tests/datagencli.c +149 -0
  2116. hdiffpatch/_c_src/zstd/tests/decodecorpus.c +1998 -0
  2117. hdiffpatch/_c_src/zstd/tests/dict-files/zero-weight-dict +0 -0
  2118. hdiffpatch/_c_src/zstd/tests/external_matchfinder.c +140 -0
  2119. hdiffpatch/_c_src/zstd/tests/external_matchfinder.h +39 -0
  2120. hdiffpatch/_c_src/zstd/tests/fullbench.c +1209 -0
  2121. hdiffpatch/_c_src/zstd/tests/fuzz/.gitignore +31 -0
  2122. hdiffpatch/_c_src/zstd/tests/fuzz/Makefile +278 -0
  2123. hdiffpatch/_c_src/zstd/tests/fuzz/README.md +161 -0
  2124. hdiffpatch/_c_src/zstd/tests/fuzz/block_decompress.c +53 -0
  2125. hdiffpatch/_c_src/zstd/tests/fuzz/block_round_trip.c +103 -0
  2126. hdiffpatch/_c_src/zstd/tests/fuzz/decompress_cross_format.c +130 -0
  2127. hdiffpatch/_c_src/zstd/tests/fuzz/decompress_dstSize_tooSmall.c +74 -0
  2128. hdiffpatch/_c_src/zstd/tests/fuzz/dictionary_decompress.c +77 -0
  2129. hdiffpatch/_c_src/zstd/tests/fuzz/dictionary_loader.c +106 -0
  2130. hdiffpatch/_c_src/zstd/tests/fuzz/dictionary_round_trip.c +155 -0
  2131. hdiffpatch/_c_src/zstd/tests/fuzz/dictionary_stream_round_trip.c +209 -0
  2132. hdiffpatch/_c_src/zstd/tests/fuzz/fse_read_ncount.c +100 -0
  2133. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz.h +57 -0
  2134. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz.py +910 -0
  2135. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz_data_producer.c +95 -0
  2136. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz_data_producer.h +66 -0
  2137. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz_helpers.c +48 -0
  2138. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz_helpers.h +81 -0
  2139. hdiffpatch/_c_src/zstd/tests/fuzz/fuzz_third_party_seq_prod.h +116 -0
  2140. hdiffpatch/_c_src/zstd/tests/fuzz/generate_sequences.c +88 -0
  2141. hdiffpatch/_c_src/zstd/tests/fuzz/huf_decompress.c +68 -0
  2142. hdiffpatch/_c_src/zstd/tests/fuzz/huf_round_trip.c +137 -0
  2143. hdiffpatch/_c_src/zstd/tests/fuzz/raw_dictionary_round_trip.c +119 -0
  2144. hdiffpatch/_c_src/zstd/tests/fuzz/regression_driver.c +90 -0
  2145. hdiffpatch/_c_src/zstd/tests/fuzz/seekable_roundtrip.c +88 -0
  2146. hdiffpatch/_c_src/zstd/tests/fuzz/seq_prod_fuzz_example/Makefile +16 -0
  2147. hdiffpatch/_c_src/zstd/tests/fuzz/seq_prod_fuzz_example/README.md +12 -0
  2148. hdiffpatch/_c_src/zstd/tests/fuzz/seq_prod_fuzz_example/example_seq_prod.c +52 -0
  2149. hdiffpatch/_c_src/zstd/tests/fuzz/sequence_compression_api.c +452 -0
  2150. hdiffpatch/_c_src/zstd/tests/fuzz/simple_compress.c +60 -0
  2151. hdiffpatch/_c_src/zstd/tests/fuzz/simple_decompress.c +59 -0
  2152. hdiffpatch/_c_src/zstd/tests/fuzz/simple_round_trip.c +182 -0
  2153. hdiffpatch/_c_src/zstd/tests/fuzz/stream_decompress.c +119 -0
  2154. hdiffpatch/_c_src/zstd/tests/fuzz/stream_round_trip.c +218 -0
  2155. hdiffpatch/_c_src/zstd/tests/fuzz/zstd_frame_info.c +43 -0
  2156. hdiffpatch/_c_src/zstd/tests/fuzz/zstd_helpers.c +208 -0
  2157. hdiffpatch/_c_src/zstd/tests/fuzz/zstd_helpers.h +56 -0
  2158. hdiffpatch/_c_src/zstd/tests/fuzzer.c +5147 -0
  2159. hdiffpatch/_c_src/zstd/tests/golden-compression/PR-3517-block-splitter-corruption-test +1 -0
  2160. hdiffpatch/_c_src/zstd/tests/golden-compression/http +1 -0
  2161. hdiffpatch/_c_src/zstd/tests/golden-compression/huffman-compressed-larger +0 -0
  2162. hdiffpatch/_c_src/zstd/tests/golden-compression/large-literal-and-match-lengths +0 -0
  2163. hdiffpatch/_c_src/zstd/tests/golden-decompression/block-128k.zst +0 -0
  2164. hdiffpatch/_c_src/zstd/tests/golden-decompression/empty-block.zst +0 -0
  2165. hdiffpatch/_c_src/zstd/tests/golden-decompression/rle-first-block.zst +0 -0
  2166. hdiffpatch/_c_src/zstd/tests/golden-decompression/zeroSeq_2B.zst +0 -0
  2167. hdiffpatch/_c_src/zstd/tests/golden-decompression-errors/.gitignore +1 -0
  2168. hdiffpatch/_c_src/zstd/tests/golden-decompression-errors/off0.bin.zst +0 -0
  2169. hdiffpatch/_c_src/zstd/tests/golden-decompression-errors/truncated_huff_state.zst +0 -0
  2170. hdiffpatch/_c_src/zstd/tests/golden-decompression-errors/zeroSeq_extraneous.zst +0 -0
  2171. hdiffpatch/_c_src/zstd/tests/golden-dictionaries/http-dict-missing-symbols +0 -0
  2172. hdiffpatch/_c_src/zstd/tests/gzip/Makefile +45 -0
  2173. hdiffpatch/_c_src/zstd/tests/gzip/gzip-env.sh +46 -0
  2174. hdiffpatch/_c_src/zstd/tests/gzip/helin-segv.sh +31 -0
  2175. hdiffpatch/_c_src/zstd/tests/gzip/help-version.sh +270 -0
  2176. hdiffpatch/_c_src/zstd/tests/gzip/hufts-segv.gz +0 -0
  2177. hdiffpatch/_c_src/zstd/tests/gzip/hufts.sh +34 -0
  2178. hdiffpatch/_c_src/zstd/tests/gzip/init.cfg +5 -0
  2179. hdiffpatch/_c_src/zstd/tests/gzip/init.sh +616 -0
  2180. hdiffpatch/_c_src/zstd/tests/gzip/keep.sh +51 -0
  2181. hdiffpatch/_c_src/zstd/tests/gzip/list.sh +31 -0
  2182. hdiffpatch/_c_src/zstd/tests/gzip/memcpy-abuse.sh +34 -0
  2183. hdiffpatch/_c_src/zstd/tests/gzip/mixed.sh +68 -0
  2184. hdiffpatch/_c_src/zstd/tests/gzip/null-suffix-clobber.sh +35 -0
  2185. hdiffpatch/_c_src/zstd/tests/gzip/stdin.sh +31 -0
  2186. hdiffpatch/_c_src/zstd/tests/gzip/test-driver.sh +150 -0
  2187. hdiffpatch/_c_src/zstd/tests/gzip/trailing-nul.sh +37 -0
  2188. hdiffpatch/_c_src/zstd/tests/gzip/unpack-invalid.sh +36 -0
  2189. hdiffpatch/_c_src/zstd/tests/gzip/z-suffix.sh +30 -0
  2190. hdiffpatch/_c_src/zstd/tests/gzip/zdiff.sh +48 -0
  2191. hdiffpatch/_c_src/zstd/tests/gzip/zgrep-context.sh +47 -0
  2192. hdiffpatch/_c_src/zstd/tests/gzip/zgrep-f.sh +43 -0
  2193. hdiffpatch/_c_src/zstd/tests/gzip/zgrep-signal.sh +64 -0
  2194. hdiffpatch/_c_src/zstd/tests/gzip/znew-k.sh +40 -0
  2195. hdiffpatch/_c_src/zstd/tests/invalidDictionaries.c +61 -0
  2196. hdiffpatch/_c_src/zstd/tests/largeDictionary.c +128 -0
  2197. hdiffpatch/_c_src/zstd/tests/legacy.c +260 -0
  2198. hdiffpatch/_c_src/zstd/tests/libzstd_builds.sh +104 -0
  2199. hdiffpatch/_c_src/zstd/tests/longmatch.c +102 -0
  2200. hdiffpatch/_c_src/zstd/tests/loremOut.c +50 -0
  2201. hdiffpatch/_c_src/zstd/tests/loremOut.h +15 -0
  2202. hdiffpatch/_c_src/zstd/tests/paramgrill.c +2965 -0
  2203. hdiffpatch/_c_src/zstd/tests/playTests.sh +1925 -0
  2204. hdiffpatch/_c_src/zstd/tests/poolTests.c +271 -0
  2205. hdiffpatch/_c_src/zstd/tests/rateLimiter.py +41 -0
  2206. hdiffpatch/_c_src/zstd/tests/regression/.gitignore +4 -0
  2207. hdiffpatch/_c_src/zstd/tests/regression/Makefile +60 -0
  2208. hdiffpatch/_c_src/zstd/tests/regression/README.md +28 -0
  2209. hdiffpatch/_c_src/zstd/tests/regression/config.c +404 -0
  2210. hdiffpatch/_c_src/zstd/tests/regression/config.h +91 -0
  2211. hdiffpatch/_c_src/zstd/tests/regression/data.c +631 -0
  2212. hdiffpatch/_c_src/zstd/tests/regression/data.h +121 -0
  2213. hdiffpatch/_c_src/zstd/tests/regression/levels.h +59 -0
  2214. hdiffpatch/_c_src/zstd/tests/regression/method.c +701 -0
  2215. hdiffpatch/_c_src/zstd/tests/regression/method.h +65 -0
  2216. hdiffpatch/_c_src/zstd/tests/regression/result.c +30 -0
  2217. hdiffpatch/_c_src/zstd/tests/regression/result.h +103 -0
  2218. hdiffpatch/_c_src/zstd/tests/regression/results.csv +1480 -0
  2219. hdiffpatch/_c_src/zstd/tests/regression/test.c +362 -0
  2220. hdiffpatch/_c_src/zstd/tests/roundTripCrash.c +241 -0
  2221. hdiffpatch/_c_src/zstd/tests/seqgen.c +260 -0
  2222. hdiffpatch/_c_src/zstd/tests/seqgen.h +58 -0
  2223. hdiffpatch/_c_src/zstd/tests/test-license.py +156 -0
  2224. hdiffpatch/_c_src/zstd/tests/test-variants.sh +115 -0
  2225. hdiffpatch/_c_src/zstd/tests/test-zstd-versions.py +308 -0
  2226. hdiffpatch/_c_src/zstd/tests/zstreamtest.c +3467 -0
  2227. hdiffpatch/_c_src/zstd/zlibWrapper/.gitignore +28 -0
  2228. hdiffpatch/_c_src/zstd/zlibWrapper/BUCK +22 -0
  2229. hdiffpatch/_c_src/zstd/zlibWrapper/Makefile +120 -0
  2230. hdiffpatch/_c_src/zstd/zlibWrapper/README.md +163 -0
  2231. hdiffpatch/_c_src/zstd/zlibWrapper/examples/example.c +598 -0
  2232. hdiffpatch/_c_src/zstd/zlibWrapper/examples/example_original.c +599 -0
  2233. hdiffpatch/_c_src/zstd/zlibWrapper/examples/fitblk.c +254 -0
  2234. hdiffpatch/_c_src/zstd/zlibWrapper/examples/fitblk_original.c +233 -0
  2235. hdiffpatch/_c_src/zstd/zlibWrapper/examples/minigzip.c +605 -0
  2236. hdiffpatch/_c_src/zstd/zlibWrapper/examples/zwrapbench.c +1018 -0
  2237. hdiffpatch/_c_src/zstd/zlibWrapper/gzclose.c +26 -0
  2238. hdiffpatch/_c_src/zstd/zlibWrapper/gzcompatibility.h +68 -0
  2239. hdiffpatch/_c_src/zstd/zlibWrapper/gzguts.h +229 -0
  2240. hdiffpatch/_c_src/zstd/zlibWrapper/gzlib.c +587 -0
  2241. hdiffpatch/_c_src/zstd/zlibWrapper/gzread.c +637 -0
  2242. hdiffpatch/_c_src/zstd/zlibWrapper/gzwrite.c +632 -0
  2243. hdiffpatch/_c_src/zstd/zlibWrapper/zstd_zlibwrapper.c +1200 -0
  2244. hdiffpatch/_c_src/zstd/zlibWrapper/zstd_zlibwrapper.h +91 -0
  2245. hdiffpatch/_lzma_config.py +215 -0
  2246. hdiffpatch/_tamp_config.py +85 -0
  2247. hdiffpatch/_zlib_config.py +177 -0
  2248. hdiffpatch/_zstd_config.py +113 -0
  2249. hdiffpatch/py.typed +0 -0
  2250. hdiffpatch-1.0.0.dist-info/LICENSE +201 -0
  2251. hdiffpatch-1.0.0.dist-info/METADATA +376 -0
  2252. hdiffpatch-1.0.0.dist-info/RECORD +2254 -0
  2253. hdiffpatch-1.0.0.dist-info/WHEEL +4 -0
  2254. hdiffpatch-1.0.0.dist-info/entry_points.txt +0 -0
@@ -0,0 +1,4394 @@
1
+ /*
2
+ * deflate_compress.c - a compressor for DEFLATE
3
+ *
4
+ * Copyright 2016 Eric Biggers
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use,
10
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following
13
+ * conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ * OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+ #include "deflate_compress.h"
29
+ #include "deflate_constants.h"
30
+
31
+ /******************************************************************************/
32
+
33
+ /*
34
+ * The following parameters can be changed at build time to customize the
35
+ * compression algorithms slightly:
36
+ *
37
+ * (Note, not all customizable parameters are here. Some others can be found in
38
+ * libdeflate_alloc_compressor() and in *_matchfinder.h.)
39
+ */
40
+
41
+ /*
42
+ * If this parameter is defined to 1, then the near-optimal parsing algorithm
43
+ * will be included, and compression levels 10-12 will use it. This algorithm
44
+ * usually produces a compression ratio significantly better than the other
45
+ * algorithms. However, it is slow. If this parameter is defined to 0, then
46
+ * levels 10-12 will be the same as level 9 and will use the lazy2 algorithm.
47
+ */
48
+ #define SUPPORT_NEAR_OPTIMAL_PARSING 1
49
+
50
+ /*
51
+ * This is the minimum block length that the compressor will use, in
52
+ * uncompressed bytes. This should be a value below which using shorter blocks
53
+ * is unlikely to be worthwhile, due to the per-block overhead. This value does
54
+ * not apply to the final block, which may be shorter than this (if the input is
55
+ * shorter, it will have to be), or to the final uncompressed block in a series
56
+ * of uncompressed blocks that cover more than UINT16_MAX bytes.
57
+ *
58
+ * This value is also approximately the amount by which what would otherwise be
59
+ * the second-to-last block is allowed to grow past the soft maximum length in
60
+ * order to avoid having to use a very short final block.
61
+ *
62
+ * Defining a fixed minimum block length is needed in order to guarantee a
63
+ * reasonable upper bound on the compressed size. It's also needed because our
64
+ * block splitting algorithm doesn't work well on very short blocks.
65
+ */
66
+ #define MIN_BLOCK_LENGTH 5000
67
+
68
+ /*
69
+ * For the greedy, lazy, lazy2, and near-optimal compressors: This is the soft
70
+ * maximum block length, in uncompressed bytes. The compressor will try to end
71
+ * blocks at this length, but it may go slightly past it if there is a match
72
+ * that straddles this limit or if the input data ends soon after this limit.
73
+ * This parameter doesn't apply to uncompressed blocks, which the DEFLATE format
74
+ * limits to 65535 bytes.
75
+ *
76
+ * This should be a value above which it is very likely that splitting the block
77
+ * would produce a better compression ratio. For the near-optimal compressor,
78
+ * increasing/decreasing this parameter will increase/decrease per-compressor
79
+ * memory usage linearly.
80
+ */
81
+ #define SOFT_MAX_BLOCK_LENGTH 300000
82
+
83
+ /*
84
+ * For the greedy, lazy, and lazy2 compressors: this is the length of the
85
+ * sequence store, which is an array where the compressor temporarily stores
86
+ * matches that it's going to use in the current block. This value is the
87
+ * maximum number of matches that can be used in a block. If the sequence store
88
+ * fills up, then the compressor will be forced to end the block early. This
89
+ * value should be large enough so that this rarely happens, due to the block
90
+ * being ended normally before then. Increasing/decreasing this value will
91
+ * increase/decrease per-compressor memory usage linearly.
92
+ */
93
+ #define SEQ_STORE_LENGTH 50000
94
+
95
+ /*
96
+ * For deflate_compress_fastest(): This is the soft maximum block length.
97
+ * deflate_compress_fastest() doesn't use the regular block splitting algorithm;
98
+ * it only ends blocks when they reach FAST_SOFT_MAX_BLOCK_LENGTH bytes or
99
+ * FAST_SEQ_STORE_LENGTH matches. Therefore, this value should be lower than
100
+ * the regular SOFT_MAX_BLOCK_LENGTH.
101
+ */
102
+ #define FAST_SOFT_MAX_BLOCK_LENGTH 65535
103
+
104
+ /*
105
+ * For deflate_compress_fastest(): this is the length of the sequence store.
106
+ * This is like SEQ_STORE_LENGTH, but this should be a lower value.
107
+ */
108
+ #define FAST_SEQ_STORE_LENGTH 8192
109
+
110
+ /*
111
+ * These are the maximum codeword lengths, in bits, the compressor will use for
112
+ * each Huffman code. The DEFLATE format defines limits for these. However,
113
+ * further limiting litlen codewords to 14 bits is beneficial, since it has
114
+ * negligible effect on compression ratio but allows some optimizations when
115
+ * outputting bits. (It allows 4 literals to be written at once rather than 3.)
116
+ */
117
+ #define MAX_LITLEN_CODEWORD_LEN 14
118
+ #define MAX_OFFSET_CODEWORD_LEN DEFLATE_MAX_OFFSET_CODEWORD_LEN
119
+ #define MAX_PRE_CODEWORD_LEN DEFLATE_MAX_PRE_CODEWORD_LEN
120
+
121
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
122
+
123
+ /* Parameters specific to the near-optimal parsing algorithm */
124
+
125
+ /*
126
+ * BIT_COST is a scaling factor that allows the near-optimal compressor to
127
+ * consider fractional bit costs when deciding which literal/match sequence to
128
+ * use. This is useful when the true symbol costs are unknown. For example, if
129
+ * the compressor thinks that a symbol has 6.5 bits of entropy, it can set its
130
+ * cost to 6.5 bits rather than have to use 6 or 7 bits. Although in the end
131
+ * each symbol will use a whole number of bits due to the Huffman coding,
132
+ * considering fractional bits can be helpful due to the limited information.
133
+ *
134
+ * BIT_COST should be a power of 2. A value of 8 or 16 works well. A higher
135
+ * value isn't very useful since the calculations are approximate anyway.
136
+ *
137
+ * BIT_COST doesn't apply to deflate_flush_block() and
138
+ * deflate_compute_true_cost(), which consider whole bits.
139
+ */
140
+ #define BIT_COST 16
141
+
142
+ /*
143
+ * The NOSTAT_BITS value for a given alphabet is the number of bits assumed to
144
+ * be needed to output a symbol that was unused in the previous optimization
145
+ * pass. Assigning a default cost allows the symbol to be used in the next
146
+ * optimization pass. However, the cost should be relatively high because the
147
+ * symbol probably won't be used very many times (if at all).
148
+ */
149
+ #define LITERAL_NOSTAT_BITS 13
150
+ #define LENGTH_NOSTAT_BITS 13
151
+ #define OFFSET_NOSTAT_BITS 10
152
+
153
+ /*
154
+ * This is (slightly less than) the maximum number of matches that the
155
+ * near-optimal compressor will cache per block. This behaves similarly to
156
+ * SEQ_STORE_LENGTH for the other compressors.
157
+ */
158
+ #define MATCH_CACHE_LENGTH (SOFT_MAX_BLOCK_LENGTH * 5)
159
+
160
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
161
+
162
+ /******************************************************************************/
163
+
164
+ /* Include the needed matchfinders. */
165
+ #define MATCHFINDER_WINDOW_ORDER DEFLATE_WINDOW_ORDER
166
+ #include "hc_matchfinder.h"
167
+ #include "ht_matchfinder.h"
168
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
169
+ # include "bt_matchfinder.h"
170
+ /*
171
+ * This is the maximum number of matches the binary trees matchfinder can find
172
+ * at a single position. Since the matchfinder never finds more than one match
173
+ * for the same length, presuming one of each possible length is sufficient for
174
+ * an upper bound. (This says nothing about whether it is worthwhile to
175
+ * consider so many matches; this is just defining the worst case.)
176
+ */
177
+ #define MAX_MATCHES_PER_POS \
178
+ (DEFLATE_MAX_MATCH_LEN - DEFLATE_MIN_MATCH_LEN + 1)
179
+ #endif
180
+
181
+ /*
182
+ * The largest block length we will ever use is when the final block is of
183
+ * length SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH - 1, or when any block is of
184
+ * length SOFT_MAX_BLOCK_LENGTH + 1 + DEFLATE_MAX_MATCH_LEN. The latter case
185
+ * occurs when the lazy2 compressor chooses two literals and a maximum-length
186
+ * match, starting at SOFT_MAX_BLOCK_LENGTH - 1.
187
+ */
188
+ #define MAX_BLOCK_LENGTH \
189
+ MAX(SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH - 1, \
190
+ SOFT_MAX_BLOCK_LENGTH + 1 + DEFLATE_MAX_MATCH_LEN)
191
+
192
+ static forceinline void
193
+ check_buildtime_parameters(void)
194
+ {
195
+ /*
196
+ * Verify that MIN_BLOCK_LENGTH is being honored, as
197
+ * libdeflate_deflate_compress_bound() depends on it.
198
+ */
199
+ STATIC_ASSERT(SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH);
200
+ STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH);
201
+ STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN >=
202
+ MIN_BLOCK_LENGTH);
203
+ STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN >=
204
+ MIN_BLOCK_LENGTH);
205
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
206
+ STATIC_ASSERT(MIN_BLOCK_LENGTH * MAX_MATCHES_PER_POS <=
207
+ MATCH_CACHE_LENGTH);
208
+ #endif
209
+
210
+ /* The definition of MAX_BLOCK_LENGTH assumes this. */
211
+ STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH <= SOFT_MAX_BLOCK_LENGTH);
212
+
213
+ /* Verify that the sequence stores aren't uselessly large. */
214
+ STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN <=
215
+ SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH);
216
+ STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN <=
217
+ FAST_SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH);
218
+
219
+ /* Verify that the maximum codeword lengths are valid. */
220
+ STATIC_ASSERT(
221
+ MAX_LITLEN_CODEWORD_LEN <= DEFLATE_MAX_LITLEN_CODEWORD_LEN);
222
+ STATIC_ASSERT(
223
+ MAX_OFFSET_CODEWORD_LEN <= DEFLATE_MAX_OFFSET_CODEWORD_LEN);
224
+ STATIC_ASSERT(
225
+ MAX_PRE_CODEWORD_LEN <= DEFLATE_MAX_PRE_CODEWORD_LEN);
226
+ STATIC_ASSERT(
227
+ (1U << MAX_LITLEN_CODEWORD_LEN) >= DEFLATE_NUM_LITLEN_SYMS);
228
+ STATIC_ASSERT(
229
+ (1U << MAX_OFFSET_CODEWORD_LEN) >= DEFLATE_NUM_OFFSET_SYMS);
230
+ STATIC_ASSERT(
231
+ (1U << MAX_PRE_CODEWORD_LEN) >= DEFLATE_NUM_PRECODE_SYMS);
232
+ }
233
+
234
+ /******************************************************************************/
235
+
236
+ /* Table: length slot => length slot base value */
237
+ static const unsigned deflate_length_slot_base[] = {
238
+ 3, 4, 5, 6, 7, 8, 9, 10,
239
+ 11, 13, 15, 17, 19, 23, 27, 31,
240
+ 35, 43, 51, 59, 67, 83, 99, 115,
241
+ 131, 163, 195, 227, 258,
242
+ };
243
+
244
+ /* Table: length slot => number of extra length bits */
245
+ static const u8 deflate_extra_length_bits[] = {
246
+ 0, 0, 0, 0, 0, 0, 0, 0,
247
+ 1, 1, 1, 1, 2, 2, 2, 2,
248
+ 3, 3, 3, 3, 4, 4, 4, 4,
249
+ 5, 5, 5, 5, 0,
250
+ };
251
+
252
+ /* Table: offset slot => offset slot base value */
253
+ static const unsigned deflate_offset_slot_base[] = {
254
+ 1, 2, 3, 4, 5, 7, 9, 13,
255
+ 17, 25, 33, 49, 65, 97, 129, 193,
256
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073,
257
+ 4097, 6145, 8193, 12289, 16385, 24577,
258
+ };
259
+
260
+ /* Table: offset slot => number of extra offset bits */
261
+ static const u8 deflate_extra_offset_bits[] = {
262
+ 0, 0, 0, 0, 1, 1, 2, 2,
263
+ 3, 3, 4, 4, 5, 5, 6, 6,
264
+ 7, 7, 8, 8, 9, 9, 10, 10,
265
+ 11, 11, 12, 12, 13, 13,
266
+ };
267
+
268
+ /* Table: length => length slot */
269
+ static const u8 deflate_length_slot[DEFLATE_MAX_MATCH_LEN + 1] = {
270
+ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12,
271
+ 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16,
272
+ 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18,
273
+ 18, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20,
274
+ 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
275
+ 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
276
+ 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
277
+ 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
278
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25,
279
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
280
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26,
281
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
282
+ 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
283
+ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
284
+ 27, 27, 28,
285
+ };
286
+
287
+ /*
288
+ * Table: 'offset - 1 => offset_slot' for offset <= 256.
289
+ * This was generated by scripts/gen_offset_slot_map.py.
290
+ */
291
+ static const u8 deflate_offset_slot[256] = {
292
+ 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
293
+ 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
294
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
295
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
296
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
297
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
298
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
299
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
300
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
301
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
302
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
303
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
304
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
305
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
306
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
307
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
308
+ };
309
+
310
+ /* The order in which precode codeword lengths are stored */
311
+ static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = {
312
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
313
+ };
314
+
315
+ /* Table: precode symbol => number of extra bits */
316
+ static const u8 deflate_extra_precode_bits[DEFLATE_NUM_PRECODE_SYMS] = {
317
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7
318
+ };
319
+
320
+ /* Codewords for the DEFLATE Huffman codes */
321
+ struct deflate_codewords {
322
+ u32 litlen[DEFLATE_NUM_LITLEN_SYMS];
323
+ u32 offset[DEFLATE_NUM_OFFSET_SYMS];
324
+ };
325
+
326
+ /*
327
+ * Codeword lengths (in bits) for the DEFLATE Huffman codes.
328
+ * A zero length means the corresponding symbol had zero frequency.
329
+ */
330
+ struct deflate_lens {
331
+ u8 litlen[DEFLATE_NUM_LITLEN_SYMS];
332
+ u8 offset[DEFLATE_NUM_OFFSET_SYMS];
333
+ };
334
+
335
+ /* Codewords and lengths for the DEFLATE Huffman codes */
336
+ struct deflate_codes {
337
+ struct deflate_codewords codewords;
338
+ struct deflate_lens lens;
339
+ };
340
+
341
+ /* Symbol frequency counters for the DEFLATE Huffman codes */
342
+ struct deflate_freqs {
343
+ u32 litlen[DEFLATE_NUM_LITLEN_SYMS];
344
+ u32 offset[DEFLATE_NUM_OFFSET_SYMS];
345
+ };
346
+
347
+ /*
348
+ * Represents a run of literals followed by a match or end-of-block. This
349
+ * struct is needed to temporarily store items chosen by the parser, since items
350
+ * cannot be written until all items for the block have been chosen and the
351
+ * block's Huffman codes have been computed.
352
+ */
353
+ struct deflate_sequence {
354
+
355
+ /*
356
+ * Bits 0..22: the number of literals in this run. This may be 0 and
357
+ * can be at most MAX_BLOCK_LENGTH. The literals are not stored
358
+ * explicitly in this structure; instead, they are read directly from
359
+ * the uncompressed data.
360
+ *
361
+ * Bits 23..31: the length of the match which follows the literals, or 0
362
+ * if this literal run was the last in the block, so there is no match
363
+ * which follows it.
364
+ */
365
+ #define SEQ_LENGTH_SHIFT 23
366
+ #define SEQ_LITRUNLEN_MASK (((u32)1 << SEQ_LENGTH_SHIFT) - 1)
367
+ u32 litrunlen_and_length;
368
+
369
+ /*
370
+ * If 'length' doesn't indicate end-of-block, then this is the offset of
371
+ * the match which follows the literals.
372
+ */
373
+ u16 offset;
374
+
375
+ /*
376
+ * If 'length' doesn't indicate end-of-block, then this is the offset
377
+ * slot of the match which follows the literals.
378
+ */
379
+ u16 offset_slot;
380
+ };
381
+
382
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
383
+
384
+ /* Costs for the near-optimal parsing algorithm */
385
+ struct deflate_costs {
386
+
387
+ /* The cost to output each possible literal */
388
+ u32 literal[DEFLATE_NUM_LITERALS];
389
+
390
+ /* The cost to output each possible match length */
391
+ u32 length[DEFLATE_MAX_MATCH_LEN + 1];
392
+
393
+ /* The cost to output a match offset of each possible offset slot */
394
+ u32 offset_slot[DEFLATE_NUM_OFFSET_SYMS];
395
+ };
396
+
397
+ /*
398
+ * This structure represents a byte position in the input data and a node in the
399
+ * graph of possible match/literal choices for the current block.
400
+ *
401
+ * Logically, each incoming edge to this node is labeled with a literal or a
402
+ * match that can be taken to reach this position from an earlier position; and
403
+ * each outgoing edge from this node is labeled with a literal or a match that
404
+ * can be taken to advance from this position to a later position.
405
+ *
406
+ * But these "edges" are actually stored elsewhere (in 'match_cache'). Here we
407
+ * associate with each node just two pieces of information:
408
+ *
409
+ * 'cost_to_end' is the minimum cost to reach the end of the block from
410
+ * this position.
411
+ *
412
+ * 'item' represents the literal or match that must be chosen from here to
413
+ * reach the end of the block with the minimum cost. Equivalently, this
414
+ * can be interpreted as the label of the outgoing edge on the minimum-cost
415
+ * path to the "end of block" node from this node.
416
+ */
417
+ struct deflate_optimum_node {
418
+
419
+ u32 cost_to_end;
420
+
421
+ /*
422
+ * Notes on the match/literal representation used here:
423
+ *
424
+ * The low bits of 'item' are the length: 1 if this is a literal,
425
+ * or the match length if this is a match.
426
+ *
427
+ * The high bits of 'item' are the actual literal byte if this is a
428
+ * literal, or the match offset if this is a match.
429
+ */
430
+ #define OPTIMUM_OFFSET_SHIFT 9
431
+ #define OPTIMUM_LEN_MASK (((u32)1 << OPTIMUM_OFFSET_SHIFT) - 1)
432
+ u32 item;
433
+
434
+ };
435
+
436
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
437
+
438
+ /* Block split statistics. See "Block splitting algorithm" below. */
439
+ #define NUM_LITERAL_OBSERVATION_TYPES 8
440
+ #define NUM_MATCH_OBSERVATION_TYPES 2
441
+ #define NUM_OBSERVATION_TYPES (NUM_LITERAL_OBSERVATION_TYPES + \
442
+ NUM_MATCH_OBSERVATION_TYPES)
443
+ #define NUM_OBSERVATIONS_PER_BLOCK_CHECK 512
444
+ struct block_split_stats {
445
+ u32 new_observations[NUM_OBSERVATION_TYPES];
446
+ u32 observations[NUM_OBSERVATION_TYPES];
447
+ u32 num_new_observations;
448
+ u32 num_observations;
449
+ };
450
+
451
+ struct deflate_output_bitstream;
452
+
453
+ /*
454
+ * The type for the bitbuffer variable, which temporarily holds bits that are
455
+ * being packed into bytes and written to the output buffer. For best
456
+ * performance, this should have size equal to a machine word.
457
+ */
458
+ typedef machine_word_t bitbuf_t;
459
+
460
+ /* The main DEFLATE compressor structure */
461
+ struct libdeflate_compressor {
462
+
463
+ /* Pointer to the compress() implementation chosen at allocation time */
464
+ void (*impl)(struct libdeflate_compressor *restrict c,const u8* in_block_with_dict,size_t dict_nbytes,
465
+ size_t in_nbytes,size_t in_border_nbytes,struct deflate_output_bitstream *os);
466
+
467
+ /* The free() function for this struct, chosen at allocation time */
468
+ free_func_t free_func;
469
+
470
+ /* The compression level with which this compressor was created */
471
+ unsigned compression_level;
472
+ bool in_is_final_block;
473
+ bool lazy2;
474
+ unsigned bitcount_back_for_block;
475
+ bitbuf_t bitbuf_back_for_block;
476
+ size_t dict_pos_for_blocks_continue;
477
+ size_t slide_pos_for_blocks_continue;
478
+ u32 next_hashes_for_blocks_continue0;
479
+ u32 next_hashes_for_blocks_continue1;
480
+
481
+ /* Anything of this size or less we won't bother trying to compress. */
482
+ size_t max_passthrough_size;
483
+
484
+ /*
485
+ * The maximum search depth: consider at most this many potential
486
+ * matches at each position
487
+ */
488
+ unsigned max_search_depth;
489
+
490
+ /*
491
+ * The "nice" match length: if a match of this length is found, choose
492
+ * it immediately without further consideration
493
+ */
494
+ unsigned nice_match_length;
495
+
496
+ /* Frequency counters for the current block */
497
+ struct deflate_freqs freqs;
498
+
499
+ /* Block split statistics for the current block */
500
+ struct block_split_stats split_stats;
501
+
502
+ /* Dynamic Huffman codes for the current block */
503
+ struct deflate_codes codes;
504
+
505
+ /* The static Huffman codes defined by the DEFLATE format */
506
+ struct deflate_codes static_codes;
507
+
508
+ /* Temporary space for block flushing */
509
+ union {
510
+ /* Information about the precode */
511
+ struct {
512
+ u32 freqs[DEFLATE_NUM_PRECODE_SYMS];
513
+ u32 codewords[DEFLATE_NUM_PRECODE_SYMS];
514
+ u8 lens[DEFLATE_NUM_PRECODE_SYMS];
515
+ unsigned items[DEFLATE_NUM_LITLEN_SYMS +
516
+ DEFLATE_NUM_OFFSET_SYMS];
517
+ unsigned num_litlen_syms;
518
+ unsigned num_offset_syms;
519
+ unsigned num_explicit_lens;
520
+ unsigned num_items;
521
+ } precode;
522
+ /*
523
+ * The "full" length codewords. Used only after the information
524
+ * in 'precode' is no longer needed.
525
+ */
526
+ struct {
527
+ u32 codewords[DEFLATE_MAX_MATCH_LEN + 1];
528
+ u8 lens[DEFLATE_MAX_MATCH_LEN + 1];
529
+ } length;
530
+ } o;
531
+
532
+ union {
533
+ /* Data for greedy or lazy parsing */
534
+ struct {
535
+ /* Hash chains matchfinder */
536
+ struct hc_matchfinder hc_mf;
537
+
538
+ /* Matches and literals chosen for the current block */
539
+ struct deflate_sequence sequences[SEQ_STORE_LENGTH + 1];
540
+
541
+ } g; /* (g)reedy */
542
+
543
+ /* Data for fastest parsing */
544
+ struct {
545
+ /* Hash table matchfinder */
546
+ struct ht_matchfinder ht_mf;
547
+
548
+ /* Matches and literals chosen for the current block */
549
+ struct deflate_sequence sequences[
550
+ FAST_SEQ_STORE_LENGTH + 1];
551
+
552
+ } f; /* (f)astest */
553
+
554
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
555
+ /* Data for near-optimal parsing */
556
+ struct {
557
+
558
+ /* Binary tree matchfinder */
559
+ struct bt_matchfinder bt_mf;
560
+
561
+ /*
562
+ * Cached matches for the current block. This array
563
+ * contains the matches that were found at each position
564
+ * in the block. Specifically, for each position, there
565
+ * is a list of matches found at that position, if any,
566
+ * sorted by strictly increasing length. In addition,
567
+ * following the matches for each position, there is a
568
+ * special 'struct lz_match' whose 'length' member
569
+ * contains the number of matches found at that
570
+ * position, and whose 'offset' member contains the
571
+ * literal at that position.
572
+ *
573
+ * Note: in rare cases, there will be a very high number
574
+ * of matches in the block and this array will overflow.
575
+ * If this happens, we force the end of the current
576
+ * block. MATCH_CACHE_LENGTH is the length at which we
577
+ * actually check for overflow. The extra slots beyond
578
+ * this are enough to absorb the worst case overflow,
579
+ * which occurs if starting at
580
+ * &match_cache[MATCH_CACHE_LENGTH - 1], we write
581
+ * MAX_MATCHES_PER_POS matches and a match count header,
582
+ * then skip searching for matches at
583
+ * 'DEFLATE_MAX_MATCH_LEN - 1' positions and write the
584
+ * match count header for each.
585
+ */
586
+ struct lz_match match_cache[MATCH_CACHE_LENGTH +
587
+ MAX_MATCHES_PER_POS +
588
+ DEFLATE_MAX_MATCH_LEN - 1];
589
+
590
+ /*
591
+ * Array of nodes, one per position, for running the
592
+ * minimum-cost path algorithm.
593
+ *
594
+ * This array must be large enough to accommodate the
595
+ * worst-case number of nodes, which is MAX_BLOCK_LENGTH
596
+ * plus 1 for the end-of-block node.
597
+ */
598
+ struct deflate_optimum_node optimum_nodes[
599
+ MAX_BLOCK_LENGTH + 1];
600
+
601
+ /* The current cost model being used */
602
+ struct deflate_costs costs;
603
+
604
+ /* Saved cost model */
605
+ struct deflate_costs costs_saved;
606
+
607
+ /*
608
+ * A table that maps match offset to offset slot. This
609
+ * differs from deflate_offset_slot[] in that this is a
610
+ * full map, not a condensed one. The full map is more
611
+ * appropriate for the near-optimal parser, since the
612
+ * near-optimal parser does more offset => offset_slot
613
+ * translations, it doesn't intersperse them with
614
+ * matchfinding (so cache evictions are less of a
615
+ * concern), and it uses more memory anyway.
616
+ */
617
+ u8 offset_slot_full[DEFLATE_MAX_MATCH_OFFSET + 1];
618
+
619
+ /* Literal/match statistics saved from previous block */
620
+ u32 prev_observations[NUM_OBSERVATION_TYPES];
621
+ u32 prev_num_observations;
622
+
623
+ /*
624
+ * Approximate match length frequencies based on a
625
+ * greedy parse, gathered during matchfinding. This is
626
+ * used for setting the initial symbol costs.
627
+ */
628
+ u32 new_match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1];
629
+ u32 match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1];
630
+
631
+ /*
632
+ * The maximum number of optimization passes
633
+ * (min-cost path searches) per block.
634
+ * Larger values = more compression.
635
+ */
636
+ unsigned max_optim_passes;
637
+
638
+ /*
639
+ * If an optimization pass improves the cost by fewer
640
+ * than this number of bits, then optimization will stop
641
+ * early, before max_optim_passes has been reached.
642
+ * Smaller values = more compression.
643
+ */
644
+ unsigned min_improvement_to_continue;
645
+
646
+ /*
647
+ * The minimum number of bits that would need to be
648
+ * saved for it to be considered worth the time to
649
+ * regenerate and use the min-cost path from a previous
650
+ * optimization pass, in the case where the final
651
+ * optimization pass actually increased the cost.
652
+ * Smaller values = more compression.
653
+ */
654
+ unsigned min_bits_to_use_nonfinal_path;
655
+
656
+ /*
657
+ * The maximum block length, in uncompressed bytes, at
658
+ * which to find and consider the optimal match/literal
659
+ * list for the static Huffman codes. This strategy
660
+ * improves the compression ratio produced by static
661
+ * Huffman blocks and can discover more cases in which
662
+ * static blocks are worthwhile. This helps mostly with
663
+ * small blocks, hence why this parameter is a max_len.
664
+ *
665
+ * Above this block length, static Huffman blocks are
666
+ * only used opportunistically. I.e. a static Huffman
667
+ * block is only used if a static block using the same
668
+ * match/literal list as the optimized dynamic block
669
+ * happens to be cheaper than the dynamic block itself.
670
+ */
671
+ unsigned max_len_to_optimize_static_block;
672
+
673
+ } n; /* (n)ear-optimal */
674
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
675
+
676
+ } p; /* (p)arser */
677
+ };
678
+
679
+ static forceinline void _compress_block_reset(struct libdeflate_compressor* c){
680
+ c->bitbuf_back_for_block=0;
681
+ c->bitcount_back_for_block=0;
682
+ c->dict_pos_for_blocks_continue=~(size_t)0;
683
+ c->slide_pos_for_blocks_continue=0;
684
+ }
685
+
686
+ /*
687
+ * The capacity of the bitbuffer, in bits. This is 1 less than the real size,
688
+ * in order to avoid undefined behavior when doing bitbuf >>= bitcount & ~7.
689
+ */
690
+ #define BITBUF_NBITS (8 * sizeof(bitbuf_t) - 1)
691
+
692
+ /*
693
+ * Can the specified number of bits always be added to 'bitbuf' after any
694
+ * pending bytes have been flushed? There can be up to 7 bits remaining after a
695
+ * flush, so the count must not exceed BITBUF_NBITS after adding 'n' more bits.
696
+ */
697
+ #define CAN_BUFFER(n) (7 + (n) <= BITBUF_NBITS)
698
+
699
+ /*
700
+ * Structure to keep track of the current state of sending bits to the
701
+ * compressed output buffer
702
+ */
703
+ struct deflate_output_bitstream {
704
+
705
+ /* Bits that haven't yet been written to the output buffer */
706
+ bitbuf_t bitbuf;
707
+
708
+ /*
709
+ * Number of bits currently held in @bitbuf. This can be between 0 and
710
+ * BITBUF_NBITS in general, or between 0 and 7 after a flush.
711
+ */
712
+ unsigned bitcount;
713
+
714
+ /*
715
+ * Pointer to the position in the output buffer at which the next byte
716
+ * should be written
717
+ */
718
+ u8 *next;
719
+
720
+ /* Pointer to the end of the output buffer */
721
+ u8 *end;
722
+
723
+ /* true if the output buffer ran out of space */
724
+ bool overflow;
725
+ };
726
+
727
+ /*
728
+ * Add some bits to the bitbuffer variable of the output bitstream. The caller
729
+ * must ensure that 'bitcount + n <= BITBUF_NBITS', by calling FLUSH_BITS()
730
+ * frequently enough.
731
+ */
732
+ #define ADD_BITS(bits, n) \
733
+ do { \
734
+ bitbuf |= (bitbuf_t)(bits) << bitcount; \
735
+ bitcount += (n); \
736
+ ASSERT(bitcount <= BITBUF_NBITS); \
737
+ } while (0)
738
+
739
+ /*
740
+ * Flush bits from the bitbuffer variable to the output buffer. After this, the
741
+ * bitbuffer will contain at most 7 bits (a partial byte).
742
+ *
743
+ * Since deflate_flush_block() verified ahead of time that there is enough space
744
+ * remaining before actually writing the block, it's guaranteed that out_next
745
+ * won't exceed os->end. However, there might not be enough space remaining to
746
+ * flush a whole word, even though that's fastest. Therefore, flush a whole
747
+ * word if there is space for it, otherwise flush a byte at a time.
748
+ */
749
+ #define FLUSH_BITS() \
750
+ do { \
751
+ if (UNALIGNED_ACCESS_IS_FAST && likely(out_next < out_fast_end)) { \
752
+ /* Flush a whole word (branchlessly). */ \
753
+ put_unaligned_leword(bitbuf, out_next); \
754
+ bitbuf >>= bitcount & ~7; \
755
+ out_next += bitcount >> 3; \
756
+ bitcount &= 7; \
757
+ } else { \
758
+ /* Flush a byte at a time. */ \
759
+ while (bitcount >= 8) { \
760
+ ASSERT(out_next < os->end); \
761
+ *out_next++ = bitbuf; \
762
+ bitcount -= 8; \
763
+ bitbuf >>= 8; \
764
+ } \
765
+ } \
766
+ } while (0)
767
+
768
+ /*
769
+ * Given the binary tree node A[subtree_idx] whose children already satisfy the
770
+ * maxheap property, swap the node with its greater child until it is greater
771
+ * than or equal to both of its children, so that the maxheap property is
772
+ * satisfied in the subtree rooted at A[subtree_idx]. 'A' uses 1-based indices.
773
+ */
774
+ static void
775
+ heapify_subtree(u32 A[], unsigned length, unsigned subtree_idx)
776
+ {
777
+ unsigned parent_idx;
778
+ unsigned child_idx;
779
+ u32 v;
780
+
781
+ v = A[subtree_idx];
782
+ parent_idx = subtree_idx;
783
+ while ((child_idx = parent_idx * 2) <= length) {
784
+ if (child_idx < length && A[child_idx + 1] > A[child_idx])
785
+ child_idx++;
786
+ if (v >= A[child_idx])
787
+ break;
788
+ A[parent_idx] = A[child_idx];
789
+ parent_idx = child_idx;
790
+ }
791
+ A[parent_idx] = v;
792
+ }
793
+
794
+ /*
795
+ * Rearrange the array 'A' so that it satisfies the maxheap property.
796
+ * 'A' uses 1-based indices, so the children of A[i] are A[i*2] and A[i*2 + 1].
797
+ */
798
+ static void
799
+ heapify_array(u32 A[], unsigned length)
800
+ {
801
+ unsigned subtree_idx;
802
+
803
+ for (subtree_idx = length / 2; subtree_idx >= 1; subtree_idx--)
804
+ heapify_subtree(A, length, subtree_idx);
805
+ }
806
+
807
+ /*
808
+ * Sort the array 'A', which contains 'length' unsigned 32-bit integers.
809
+ *
810
+ * Note: name this function heap_sort() instead of heapsort() to avoid colliding
811
+ * with heapsort() from stdlib.h on BSD-derived systems.
812
+ */
813
+ static void
814
+ heap_sort(u32 A[], unsigned length)
815
+ {
816
+ A--; /* Use 1-based indices */
817
+
818
+ heapify_array(A, length);
819
+
820
+ while (length >= 2) {
821
+ u32 tmp = A[length];
822
+
823
+ A[length] = A[1];
824
+ A[1] = tmp;
825
+ length--;
826
+ heapify_subtree(A, length, 1);
827
+ }
828
+ }
829
+
830
+ #define NUM_SYMBOL_BITS 10
831
+ #define NUM_FREQ_BITS (32 - NUM_SYMBOL_BITS)
832
+ #define SYMBOL_MASK ((1 << NUM_SYMBOL_BITS) - 1)
833
+ #define FREQ_MASK (~SYMBOL_MASK)
834
+
835
+ #define GET_NUM_COUNTERS(num_syms) (num_syms)
836
+
837
+ /*
838
+ * Sort the symbols primarily by frequency and secondarily by symbol value.
839
+ * Discard symbols with zero frequency and fill in an array with the remaining
840
+ * symbols, along with their frequencies. The low NUM_SYMBOL_BITS bits of each
841
+ * array entry will contain the symbol value, and the remaining bits will
842
+ * contain the frequency.
843
+ *
844
+ * @num_syms
845
+ * Number of symbols in the alphabet, at most 1 << NUM_SYMBOL_BITS.
846
+ *
847
+ * @freqs[num_syms]
848
+ * Frequency of each symbol, summing to at most (1 << NUM_FREQ_BITS) - 1.
849
+ *
850
+ * @lens[num_syms]
851
+ * An array that eventually will hold the length of each codeword. This
852
+ * function only fills in the codeword lengths for symbols that have zero
853
+ * frequency, which are not well defined per se but will be set to 0.
854
+ *
855
+ * @symout[num_syms]
856
+ * The output array, described above.
857
+ *
858
+ * Returns the number of entries in 'symout' that were filled. This is the
859
+ * number of symbols that have nonzero frequency.
860
+ */
861
+ static unsigned
862
+ sort_symbols(unsigned num_syms, const u32 freqs[], u8 lens[], u32 symout[])
863
+ {
864
+ unsigned sym;
865
+ unsigned i;
866
+ unsigned num_used_syms;
867
+ unsigned num_counters;
868
+ unsigned counters[GET_NUM_COUNTERS(DEFLATE_MAX_NUM_SYMS)];
869
+
870
+ /*
871
+ * We use heapsort, but with an added optimization. Since often most
872
+ * symbol frequencies are low, we first do a count sort using a limited
873
+ * number of counters. High frequencies are counted in the last
874
+ * counter, and only they will be sorted with heapsort.
875
+ *
876
+ * Note: with more symbols, it is generally beneficial to have more
877
+ * counters. About 1 counter per symbol seems fastest.
878
+ */
879
+
880
+ num_counters = GET_NUM_COUNTERS(num_syms);
881
+
882
+ memset(counters, 0, num_counters * sizeof(counters[0]));
883
+
884
+ /* Count the frequencies. */
885
+ for (sym = 0; sym < num_syms; sym++)
886
+ counters[MIN(freqs[sym], num_counters - 1)]++;
887
+
888
+ /*
889
+ * Make the counters cumulative, ignoring the zero-th, which counted
890
+ * symbols with zero frequency. As a side effect, this calculates the
891
+ * number of symbols with nonzero frequency.
892
+ */
893
+ num_used_syms = 0;
894
+ for (i = 1; i < num_counters; i++) {
895
+ unsigned count = counters[i];
896
+
897
+ counters[i] = num_used_syms;
898
+ num_used_syms += count;
899
+ }
900
+
901
+ /*
902
+ * Sort nonzero-frequency symbols using the counters. At the same time,
903
+ * set the codeword lengths of zero-frequency symbols to 0.
904
+ */
905
+ for (sym = 0; sym < num_syms; sym++) {
906
+ u32 freq = freqs[sym];
907
+
908
+ if (freq != 0) {
909
+ symout[counters[MIN(freq, num_counters - 1)]++] =
910
+ sym | (freq << NUM_SYMBOL_BITS);
911
+ } else {
912
+ lens[sym] = 0;
913
+ }
914
+ }
915
+
916
+ /* Sort the symbols counted in the last counter. */
917
+ heap_sort(symout + counters[num_counters - 2],
918
+ counters[num_counters - 1] - counters[num_counters - 2]);
919
+
920
+ return num_used_syms;
921
+ }
922
+
923
+ /*
924
+ * Build a Huffman tree.
925
+ *
926
+ * This is an optimized implementation that
927
+ * (a) takes advantage of the frequencies being already sorted;
928
+ * (b) only generates non-leaf nodes, since the non-leaf nodes of a Huffman
929
+ * tree are sufficient to generate a canonical code;
930
+ * (c) Only stores parent pointers, not child pointers;
931
+ * (d) Produces the nodes in the same memory used for input frequency
932
+ * information.
933
+ *
934
+ * Array 'A', which contains 'sym_count' entries, is used for both input and
935
+ * output. For this function, 'sym_count' must be at least 2.
936
+ *
937
+ * For input, the array must contain the frequencies of the symbols, sorted in
938
+ * increasing order. Specifically, each entry must contain a frequency left
939
+ * shifted by NUM_SYMBOL_BITS bits. Any data in the low NUM_SYMBOL_BITS bits of
940
+ * the entries will be ignored by this function. Although these bits will, in
941
+ * fact, contain the symbols that correspond to the frequencies, this function
942
+ * is concerned with frequencies only and keeps the symbols as-is.
943
+ *
944
+ * For output, this function will produce the non-leaf nodes of the Huffman
945
+ * tree. These nodes will be stored in the first (sym_count - 1) entries of the
946
+ * array. Entry A[sym_count - 2] will represent the root node. Each other node
947
+ * will contain the zero-based index of its parent node in 'A', left shifted by
948
+ * NUM_SYMBOL_BITS bits. The low NUM_SYMBOL_BITS bits of each entry in A will
949
+ * be kept as-is. Again, note that although these low bits will, in fact,
950
+ * contain a symbol value, this symbol will have *no relationship* with the
951
+ * Huffman tree node that happens to occupy the same slot. This is because this
952
+ * implementation only generates the non-leaf nodes of the tree.
953
+ */
954
+ static void
955
+ build_tree(u32 A[], unsigned sym_count)
956
+ {
957
+ const unsigned last_idx = sym_count - 1;
958
+
959
+ /* Index of the next lowest frequency leaf that still needs a parent */
960
+ unsigned i = 0;
961
+
962
+ /*
963
+ * Index of the next lowest frequency non-leaf that still needs a
964
+ * parent, or 'e' if there is currently no such node
965
+ */
966
+ unsigned b = 0;
967
+
968
+ /* Index of the next spot for a non-leaf (will overwrite a leaf) */
969
+ unsigned e = 0;
970
+
971
+ do {
972
+ u32 new_freq;
973
+
974
+ /*
975
+ * Select the next two lowest frequency nodes among the leaves
976
+ * A[i] and non-leaves A[b], and create a new node A[e] to be
977
+ * their parent. Set the new node's frequency to the sum of the
978
+ * frequencies of its two children.
979
+ *
980
+ * Usually the next two lowest frequency nodes are of the same
981
+ * type (leaf or non-leaf), so check those cases first.
982
+ */
983
+ if (i + 1 <= last_idx &&
984
+ (b == e || (A[i + 1] & FREQ_MASK) <= (A[b] & FREQ_MASK))) {
985
+ /* Two leaves */
986
+ new_freq = (A[i] & FREQ_MASK) + (A[i + 1] & FREQ_MASK);
987
+ i += 2;
988
+ } else if (b + 2 <= e &&
989
+ (i > last_idx ||
990
+ (A[b + 1] & FREQ_MASK) < (A[i] & FREQ_MASK))) {
991
+ /* Two non-leaves */
992
+ new_freq = (A[b] & FREQ_MASK) + (A[b + 1] & FREQ_MASK);
993
+ A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK);
994
+ A[b + 1] = (e << NUM_SYMBOL_BITS) |
995
+ (A[b + 1] & SYMBOL_MASK);
996
+ b += 2;
997
+ } else {
998
+ /* One leaf and one non-leaf */
999
+ new_freq = (A[i] & FREQ_MASK) + (A[b] & FREQ_MASK);
1000
+ A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK);
1001
+ i++;
1002
+ b++;
1003
+ }
1004
+ A[e] = new_freq | (A[e] & SYMBOL_MASK);
1005
+ /*
1006
+ * A binary tree with 'n' leaves has 'n - 1' non-leaves, so the
1007
+ * tree is complete once we've created 'n - 1' non-leaves.
1008
+ */
1009
+ } while (++e < last_idx);
1010
+ }
1011
+
1012
+ /*
1013
+ * Given the stripped-down Huffman tree constructed by build_tree(), determine
1014
+ * the number of codewords that should be assigned each possible length, taking
1015
+ * into account the length-limited constraint.
1016
+ *
1017
+ * @A
1018
+ * The array produced by build_tree(), containing parent index information
1019
+ * for the non-leaf nodes of the Huffman tree. Each entry in this array is
1020
+ * a node; a node's parent always has a greater index than that node
1021
+ * itself. This function will overwrite the parent index information in
1022
+ * this array, so essentially it will destroy the tree. However, the data
1023
+ * in the low NUM_SYMBOL_BITS of each entry will be preserved.
1024
+ *
1025
+ * @root_idx
1026
+ * The 0-based index of the root node in 'A', and consequently one less
1027
+ * than the number of tree node entries in 'A'. (Or, really 2 less than
1028
+ * the actual length of 'A'.)
1029
+ *
1030
+ * @len_counts
1031
+ * An array of length ('max_codeword_len' + 1) in which the number of
1032
+ * codewords having each length <= max_codeword_len will be returned.
1033
+ *
1034
+ * @max_codeword_len
1035
+ * The maximum permissible codeword length.
1036
+ */
1037
+ static void
1038
+ compute_length_counts(u32 A[], unsigned root_idx, unsigned len_counts[],
1039
+ unsigned max_codeword_len)
1040
+ {
1041
+ unsigned len;
1042
+ int node;
1043
+
1044
+ /*
1045
+ * The key observations are:
1046
+ *
1047
+ * (1) We can traverse the non-leaf nodes of the tree, always visiting a
1048
+ * parent before its children, by simply iterating through the array
1049
+ * in reverse order. Consequently, we can compute the depth of each
1050
+ * node in one pass, overwriting the parent indices with depths.
1051
+ *
1052
+ * (2) We can initially assume that in the real Huffman tree, both
1053
+ * children of the root are leaves. This corresponds to two
1054
+ * codewords of length 1. Then, whenever we visit a (non-leaf) node
1055
+ * during the traversal, we modify this assumption to account for
1056
+ * the current node *not* being a leaf, but rather its two children
1057
+ * being leaves. This causes the loss of one codeword for the
1058
+ * current depth and the addition of two codewords for the current
1059
+ * depth plus one.
1060
+ *
1061
+ * (3) We can handle the length-limited constraint fairly easily by
1062
+ * simply using the largest length available when a depth exceeds
1063
+ * max_codeword_len.
1064
+ */
1065
+
1066
+ for (len = 0; len <= max_codeword_len; len++)
1067
+ len_counts[len] = 0;
1068
+ len_counts[1] = 2;
1069
+
1070
+ /* Set the root node's depth to 0. */
1071
+ A[root_idx] &= SYMBOL_MASK;
1072
+
1073
+ for (node = root_idx - 1; node >= 0; node--) {
1074
+
1075
+ /* Calculate the depth of this node. */
1076
+
1077
+ unsigned parent = A[node] >> NUM_SYMBOL_BITS;
1078
+ unsigned parent_depth = A[parent] >> NUM_SYMBOL_BITS;
1079
+ unsigned depth = parent_depth + 1;
1080
+
1081
+ /*
1082
+ * Set the depth of this node so that it is available when its
1083
+ * children (if any) are processed.
1084
+ */
1085
+ A[node] = (A[node] & SYMBOL_MASK) | (depth << NUM_SYMBOL_BITS);
1086
+
1087
+ /*
1088
+ * If needed, decrease the length to meet the length-limited
1089
+ * constraint. This is not the optimal method for generating
1090
+ * length-limited Huffman codes! But it should be good enough.
1091
+ */
1092
+ if (depth >= max_codeword_len) {
1093
+ depth = max_codeword_len;
1094
+ do {
1095
+ depth--;
1096
+ } while (len_counts[depth] == 0);
1097
+ }
1098
+
1099
+ /*
1100
+ * Account for the fact that we have a non-leaf node at the
1101
+ * current depth.
1102
+ */
1103
+ len_counts[depth]--;
1104
+ len_counts[depth + 1] += 2;
1105
+ }
1106
+ }
1107
+
1108
+ /*
1109
+ * DEFLATE uses bit-reversed codewords, so we must bit-reverse the codewords
1110
+ * after generating them. All codewords have length <= 16 bits. If the CPU has
1111
+ * a bit-reversal instruction, then that is the fastest method. Otherwise the
1112
+ * fastest method is to reverse the bits in each of the two bytes using a table.
1113
+ * The table method is slightly faster than using bitwise operations to flip
1114
+ * adjacent 1, 2, 4, and then 8-bit fields, even if 2 to 4 codewords are packed
1115
+ * into a machine word and processed together using that method.
1116
+ */
1117
+
1118
+ #ifdef rbit32
1119
+ static forceinline u32 reverse_codeword(u32 codeword, u8 len)
1120
+ {
1121
+ return rbit32(codeword) >> ((32 - len) & 31);
1122
+ }
1123
+ #else
1124
+ /* Generated by scripts/gen_bitreverse_tab.py */
1125
+ static const u8 bitreverse_tab[256] = {
1126
+ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
1127
+ 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
1128
+ 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
1129
+ 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
1130
+ 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
1131
+ 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
1132
+ 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
1133
+ 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
1134
+ 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
1135
+ 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
1136
+ 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
1137
+ 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
1138
+ 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
1139
+ 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
1140
+ 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
1141
+ 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
1142
+ 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
1143
+ 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
1144
+ 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
1145
+ 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
1146
+ 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
1147
+ 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
1148
+ 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
1149
+ 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
1150
+ 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
1151
+ 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
1152
+ 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
1153
+ 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
1154
+ 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
1155
+ 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
1156
+ 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
1157
+ 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
1158
+ };
1159
+
1160
+ static forceinline u32 reverse_codeword(u32 codeword, u8 len)
1161
+ {
1162
+ STATIC_ASSERT(DEFLATE_MAX_CODEWORD_LEN <= 16);
1163
+ codeword = ((u32)bitreverse_tab[codeword & 0xff] << 8) |
1164
+ bitreverse_tab[codeword >> 8];
1165
+ return codeword >> (16 - len);
1166
+ }
1167
+ #endif /* !rbit32 */
1168
+
1169
+ /*
1170
+ * Generate the codewords for a canonical Huffman code.
1171
+ *
1172
+ * @A
1173
+ * The output array for codewords. In addition, initially this
1174
+ * array must contain the symbols, sorted primarily by frequency and
1175
+ * secondarily by symbol value, in the low NUM_SYMBOL_BITS bits of
1176
+ * each entry.
1177
+ *
1178
+ * @len
1179
+ * Output array for codeword lengths.
1180
+ *
1181
+ * @len_counts
1182
+ * An array that provides the number of codewords that will have
1183
+ * each possible length <= max_codeword_len.
1184
+ *
1185
+ * @max_codeword_len
1186
+ * Maximum length, in bits, of each codeword.
1187
+ *
1188
+ * @num_syms
1189
+ * Number of symbols in the alphabet, including symbols with zero
1190
+ * frequency. This is the length of the 'A' and 'len' arrays.
1191
+ */
1192
+ static void
1193
+ gen_codewords(u32 A[], u8 lens[], const unsigned len_counts[],
1194
+ unsigned max_codeword_len, unsigned num_syms)
1195
+ {
1196
+ u32 next_codewords[DEFLATE_MAX_CODEWORD_LEN + 1];
1197
+ unsigned i;
1198
+ unsigned len;
1199
+ unsigned sym;
1200
+
1201
+ /*
1202
+ * Given the number of codewords that will have each length, assign
1203
+ * codeword lengths to symbols. We do this by assigning the lengths in
1204
+ * decreasing order to the symbols sorted primarily by increasing
1205
+ * frequency and secondarily by increasing symbol value.
1206
+ */
1207
+ for (i = 0, len = max_codeword_len; len >= 1; len--) {
1208
+ unsigned count = len_counts[len];
1209
+
1210
+ while (count--)
1211
+ lens[A[i++] & SYMBOL_MASK] = len;
1212
+ }
1213
+
1214
+ /*
1215
+ * Generate the codewords themselves. We initialize the
1216
+ * 'next_codewords' array to provide the lexicographically first
1217
+ * codeword of each length, then assign codewords in symbol order. This
1218
+ * produces a canonical code.
1219
+ */
1220
+ next_codewords[0] = 0;
1221
+ next_codewords[1] = 0;
1222
+ for (len = 2; len <= max_codeword_len; len++)
1223
+ next_codewords[len] =
1224
+ (next_codewords[len - 1] + len_counts[len - 1]) << 1;
1225
+
1226
+ for (sym = 0; sym < num_syms; sym++) {
1227
+ /* DEFLATE requires bit-reversed codewords. */
1228
+ A[sym] = reverse_codeword(next_codewords[lens[sym]]++,
1229
+ lens[sym]);
1230
+ }
1231
+ }
1232
+
1233
+ /*
1234
+ * ---------------------------------------------------------------------
1235
+ * deflate_make_huffman_code()
1236
+ * ---------------------------------------------------------------------
1237
+ *
1238
+ * Given an alphabet and the frequency of each symbol in it, construct a
1239
+ * length-limited canonical Huffman code.
1240
+ *
1241
+ * @num_syms
1242
+ * The number of symbols in the alphabet. The symbols are the integers in
1243
+ * the range [0, num_syms - 1]. This parameter must be at least 2 and
1244
+ * must not exceed (1 << NUM_SYMBOL_BITS).
1245
+ *
1246
+ * @max_codeword_len
1247
+ * The maximum permissible codeword length.
1248
+ *
1249
+ * @freqs
1250
+ * An array of length @num_syms that gives the frequency of each symbol.
1251
+ * It is valid for some, none, or all of the frequencies to be 0. The sum
1252
+ * of frequencies must not exceed (1 << NUM_FREQ_BITS) - 1.
1253
+ *
1254
+ * @lens
1255
+ * An array of @num_syms entries in which this function will return the
1256
+ * length, in bits, of the codeword assigned to each symbol. Symbols with
1257
+ * 0 frequency will not have codewords per se, but their entries in this
1258
+ * array will be set to 0. No lengths greater than @max_codeword_len will
1259
+ * be assigned.
1260
+ *
1261
+ * @codewords
1262
+ * An array of @num_syms entries in which this function will return the
1263
+ * codeword for each symbol, right-justified and padded on the left with
1264
+ * zeroes. Codewords for symbols with 0 frequency will be undefined.
1265
+ *
1266
+ * ---------------------------------------------------------------------
1267
+ *
1268
+ * This function builds a length-limited canonical Huffman code.
1269
+ *
1270
+ * A length-limited Huffman code contains no codewords longer than some
1271
+ * specified length, and has exactly (with some algorithms) or approximately
1272
+ * (with the algorithm used here) the minimum weighted path length from the
1273
+ * root, given this constraint.
1274
+ *
1275
+ * A canonical Huffman code satisfies the properties that a longer codeword
1276
+ * never lexicographically precedes a shorter codeword, and the lexicographic
1277
+ * ordering of codewords of the same length is the same as the lexicographic
1278
+ * ordering of the corresponding symbols. A canonical Huffman code, or more
1279
+ * generally a canonical prefix code, can be reconstructed from only a list
1280
+ * containing the codeword length of each symbol.
1281
+ *
1282
+ * The classic algorithm to generate a Huffman code creates a node for each
1283
+ * symbol, then inserts these nodes into a min-heap keyed by symbol frequency.
1284
+ * Then, repeatedly, the two lowest-frequency nodes are removed from the
1285
+ * min-heap and added as the children of a new node having frequency equal to
1286
+ * the sum of its two children, which is then inserted into the min-heap. When
1287
+ * only a single node remains in the min-heap, it is the root of the Huffman
1288
+ * tree. The codeword for each symbol is determined by the path needed to reach
1289
+ * the corresponding node from the root. Descending to the left child appends a
1290
+ * 0 bit, whereas descending to the right child appends a 1 bit.
1291
+ *
1292
+ * The classic algorithm is relatively easy to understand, but it is subject to
1293
+ * a number of inefficiencies. In practice, it is fastest to first sort the
1294
+ * symbols by frequency. (This itself can be subject to an optimization based
1295
+ * on the fact that most frequencies tend to be low.) At the same time, we sort
1296
+ * secondarily by symbol value, which aids the process of generating a canonical
1297
+ * code. Then, during tree construction, no heap is necessary because both the
1298
+ * leaf nodes and the unparented non-leaf nodes can be easily maintained in
1299
+ * sorted order. Consequently, there can never be more than two possibilities
1300
+ * for the next-lowest-frequency node.
1301
+ *
1302
+ * In addition, because we're generating a canonical code, we actually don't
1303
+ * need the leaf nodes of the tree at all, only the non-leaf nodes. This is
1304
+ * because for canonical code generation we don't need to know where the symbols
1305
+ * are in the tree. Rather, we only need to know how many leaf nodes have each
1306
+ * depth (codeword length). And this information can, in fact, be quickly
1307
+ * generated from the tree of non-leaves only.
1308
+ *
1309
+ * Furthermore, we can build this stripped-down Huffman tree directly in the
1310
+ * array in which the codewords are to be generated, provided that these array
1311
+ * slots are large enough to hold a symbol and frequency value.
1312
+ *
1313
+ * Still furthermore, we don't even need to maintain explicit child pointers.
1314
+ * We only need the parent pointers, and even those can be overwritten in-place
1315
+ * with depth information as part of the process of extracting codeword lengths
1316
+ * from the tree. So in summary, we do NOT need a big structure like:
1317
+ *
1318
+ * struct huffman_tree_node {
1319
+ * unsigned int symbol;
1320
+ * unsigned int frequency;
1321
+ * unsigned int depth;
1322
+ * struct huffman_tree_node *left_child;
1323
+ * struct huffman_tree_node *right_child;
1324
+ * };
1325
+ *
1326
+ *
1327
+ * ... which often gets used in "naive" implementations of Huffman code
1328
+ * generation.
1329
+ *
1330
+ * Many of these optimizations are based on the implementation in 7-Zip (source
1331
+ * file: C/HuffEnc.c), which was placed in the public domain by Igor Pavlov.
1332
+ */
1333
+ static void
1334
+ deflate_make_huffman_code(unsigned num_syms, unsigned max_codeword_len,
1335
+ const u32 freqs[], u8 lens[], u32 codewords[])
1336
+ {
1337
+ u32 *A = codewords;
1338
+ unsigned num_used_syms;
1339
+
1340
+ STATIC_ASSERT(DEFLATE_MAX_NUM_SYMS <= 1 << NUM_SYMBOL_BITS);
1341
+ STATIC_ASSERT(MAX_BLOCK_LENGTH <= ((u32)1 << NUM_FREQ_BITS) - 1);
1342
+
1343
+ /*
1344
+ * We begin by sorting the symbols primarily by frequency and
1345
+ * secondarily by symbol value. As an optimization, the array used for
1346
+ * this purpose ('A') shares storage with the space in which we will
1347
+ * eventually return the codewords.
1348
+ */
1349
+ num_used_syms = sort_symbols(num_syms, freqs, lens, A);
1350
+ /*
1351
+ * 'num_used_syms' is the number of symbols with nonzero frequency.
1352
+ * This may be less than @num_syms. 'num_used_syms' is also the number
1353
+ * of entries in 'A' that are valid. Each entry consists of a distinct
1354
+ * symbol and a nonzero frequency packed into a 32-bit integer.
1355
+ */
1356
+
1357
+ /*
1358
+ * A complete Huffman code must contain at least 2 codewords. Yet, it's
1359
+ * possible that fewer than 2 symbols were used. When this happens,
1360
+ * it's usually for the offset code (0-1 symbols used). But it's also
1361
+ * theoretically possible for the litlen and pre codes (1 symbol used).
1362
+ *
1363
+ * The DEFLATE RFC explicitly allows the offset code to contain just 1
1364
+ * codeword, or even be completely empty. But it's silent about the
1365
+ * other codes. It also doesn't say whether, in the 1-codeword case,
1366
+ * the codeword (which it says must be 1 bit) is '0' or '1'.
1367
+ *
1368
+ * In any case, some DEFLATE decompressors reject these cases. zlib
1369
+ * generally allows them, but it does reject precodes that have just 1
1370
+ * codeword. More problematically, zlib v1.2.1 and earlier rejected
1371
+ * empty offset codes, and this behavior can also be seen in Windows
1372
+ * Explorer's ZIP unpacker (supposedly even still in Windows 11).
1373
+ *
1374
+ * Other DEFLATE compressors, including zlib, always send at least 2
1375
+ * codewords in order to make a complete Huffman code. Therefore, this
1376
+ * is a case where practice does not entirely match the specification.
1377
+ * We follow practice by generating 2 codewords of length 1: codeword
1378
+ * '0' for symbol 0, and codeword '1' for another symbol -- the used
1379
+ * symbol if it exists and is not symbol 0, otherwise symbol 1. This
1380
+ * does worsen the compression ratio by having to send an unnecessary
1381
+ * offset codeword length. But this only affects rare cases such as
1382
+ * blocks containing all literals, and it only makes a tiny difference.
1383
+ */
1384
+ if (unlikely(num_used_syms < 2)) {
1385
+ unsigned sym = num_used_syms ? (A[0] & SYMBOL_MASK) : 0;
1386
+ unsigned nonzero_idx = sym ? sym : 1;
1387
+
1388
+ codewords[0] = 0;
1389
+ lens[0] = 1;
1390
+ codewords[nonzero_idx] = 1;
1391
+ lens[nonzero_idx] = 1;
1392
+ return;
1393
+ }
1394
+
1395
+ /*
1396
+ * Build a stripped-down version of the Huffman tree, sharing the array
1397
+ * 'A' with the symbol values. Then extract length counts from the tree
1398
+ * and use them to generate the final codewords.
1399
+ */
1400
+
1401
+ build_tree(A, num_used_syms);
1402
+
1403
+ {
1404
+ unsigned len_counts[DEFLATE_MAX_CODEWORD_LEN + 1];
1405
+
1406
+ compute_length_counts(A, num_used_syms - 2,
1407
+ len_counts, max_codeword_len);
1408
+
1409
+ gen_codewords(A, lens, len_counts, max_codeword_len, num_syms);
1410
+ }
1411
+ }
1412
+
1413
+ /*
1414
+ * Clear the Huffman symbol frequency counters. This must be called when
1415
+ * starting a new DEFLATE block.
1416
+ */
1417
+ static void
1418
+ deflate_reset_symbol_frequencies(struct libdeflate_compressor *c)
1419
+ {
1420
+ memset(&c->freqs, 0, sizeof(c->freqs));
1421
+ }
1422
+
1423
+ /*
1424
+ * Build the literal/length and offset Huffman codes for a DEFLATE block.
1425
+ *
1426
+ * This takes as input the frequency tables for each alphabet and produces as
1427
+ * output a set of tables that map symbols to codewords and codeword lengths.
1428
+ */
1429
+ static void
1430
+ deflate_make_huffman_codes(const struct deflate_freqs *freqs,
1431
+ struct deflate_codes *codes)
1432
+ {
1433
+ deflate_make_huffman_code(DEFLATE_NUM_LITLEN_SYMS,
1434
+ MAX_LITLEN_CODEWORD_LEN,
1435
+ freqs->litlen,
1436
+ codes->lens.litlen,
1437
+ codes->codewords.litlen);
1438
+
1439
+ deflate_make_huffman_code(DEFLATE_NUM_OFFSET_SYMS,
1440
+ MAX_OFFSET_CODEWORD_LEN,
1441
+ freqs->offset,
1442
+ codes->lens.offset,
1443
+ codes->codewords.offset);
1444
+ }
1445
+
1446
+ /* Initialize c->static_codes. */
1447
+ static void
1448
+ deflate_init_static_codes(struct libdeflate_compressor *c)
1449
+ {
1450
+ unsigned i;
1451
+
1452
+ for (i = 0; i < 144; i++)
1453
+ c->freqs.litlen[i] = 1 << (9 - 8);
1454
+ for (; i < 256; i++)
1455
+ c->freqs.litlen[i] = 1 << (9 - 9);
1456
+ for (; i < 280; i++)
1457
+ c->freqs.litlen[i] = 1 << (9 - 7);
1458
+ for (; i < 288; i++)
1459
+ c->freqs.litlen[i] = 1 << (9 - 8);
1460
+
1461
+ for (i = 0; i < 32; i++)
1462
+ c->freqs.offset[i] = 1 << (5 - 5);
1463
+
1464
+ deflate_make_huffman_codes(&c->freqs, &c->static_codes);
1465
+ }
1466
+
1467
+ /* Return the offset slot for the given match offset, using the small map. */
1468
+ static forceinline unsigned
1469
+ deflate_get_offset_slot(u32 offset)
1470
+ {
1471
+ /*
1472
+ * 1 <= offset <= 32768 here. For 1 <= offset <= 256,
1473
+ * deflate_offset_slot[offset - 1] gives the slot.
1474
+ *
1475
+ * For 257 <= offset <= 32768, we take advantage of the fact that 257 is
1476
+ * the beginning of slot 16, and each slot [16..30) is exactly 1 << 7 ==
1477
+ * 128 times larger than each slot [2..16) (since the number of extra
1478
+ * bits increases by 1 every 2 slots). Thus, the slot is:
1479
+ *
1480
+ * deflate_offset_slot[2 + ((offset - 257) >> 7)] + (16 - 2)
1481
+ * == deflate_offset_slot[((offset - 1) >> 7)] + 14
1482
+ *
1483
+ * Define 'n = (offset <= 256) ? 0 : 7'. Then any offset is handled by:
1484
+ *
1485
+ * deflate_offset_slot[(offset - 1) >> n] + (n << 1)
1486
+ *
1487
+ * For better performance, replace 'n = (offset <= 256) ? 0 : 7' with
1488
+ * the equivalent (for offset <= 536871168) 'n = (256 - offset) >> 29'.
1489
+ */
1490
+ unsigned n = (256 - offset) >> 29;
1491
+
1492
+ ASSERT(offset >= 1 && offset <= 32768);
1493
+
1494
+ return deflate_offset_slot[(offset - 1) >> n] + (n << 1);
1495
+ }
1496
+
1497
+ static unsigned
1498
+ deflate_compute_precode_items(const u8 lens[], const unsigned num_lens,
1499
+ u32 precode_freqs[], unsigned precode_items[])
1500
+ {
1501
+ unsigned *itemptr;
1502
+ unsigned run_start;
1503
+ unsigned run_end;
1504
+ unsigned extra_bits;
1505
+ u8 len;
1506
+
1507
+ memset(precode_freqs, 0,
1508
+ DEFLATE_NUM_PRECODE_SYMS * sizeof(precode_freqs[0]));
1509
+
1510
+ itemptr = precode_items;
1511
+ run_start = 0;
1512
+ do {
1513
+ /* Find the next run of codeword lengths. */
1514
+
1515
+ /* len = the length being repeated */
1516
+ len = lens[run_start];
1517
+
1518
+ /* Extend the run. */
1519
+ run_end = run_start;
1520
+ do {
1521
+ run_end++;
1522
+ } while (run_end != num_lens && len == lens[run_end]);
1523
+
1524
+ if (len == 0) {
1525
+ /* Run of zeroes. */
1526
+
1527
+ /* Symbol 18: RLE 11 to 138 zeroes at a time. */
1528
+ while ((run_end - run_start) >= 11) {
1529
+ extra_bits = MIN((run_end - run_start) - 11,
1530
+ 0x7F);
1531
+ precode_freqs[18]++;
1532
+ *itemptr++ = 18 | (extra_bits << 5);
1533
+ run_start += 11 + extra_bits;
1534
+ }
1535
+
1536
+ /* Symbol 17: RLE 3 to 10 zeroes at a time. */
1537
+ if ((run_end - run_start) >= 3) {
1538
+ extra_bits = MIN((run_end - run_start) - 3,
1539
+ 0x7);
1540
+ precode_freqs[17]++;
1541
+ *itemptr++ = 17 | (extra_bits << 5);
1542
+ run_start += 3 + extra_bits;
1543
+ }
1544
+ } else {
1545
+
1546
+ /* A run of nonzero lengths. */
1547
+
1548
+ /* Symbol 16: RLE 3 to 6 of the previous length. */
1549
+ if ((run_end - run_start) >= 4) {
1550
+ precode_freqs[len]++;
1551
+ *itemptr++ = len;
1552
+ run_start++;
1553
+ do {
1554
+ extra_bits = MIN((run_end - run_start) -
1555
+ 3, 0x3);
1556
+ precode_freqs[16]++;
1557
+ *itemptr++ = 16 | (extra_bits << 5);
1558
+ run_start += 3 + extra_bits;
1559
+ } while ((run_end - run_start) >= 3);
1560
+ }
1561
+ }
1562
+
1563
+ /* Output any remaining lengths without RLE. */
1564
+ while (run_start != run_end) {
1565
+ precode_freqs[len]++;
1566
+ *itemptr++ = len;
1567
+ run_start++;
1568
+ }
1569
+ } while (run_start != num_lens);
1570
+
1571
+ return itemptr - precode_items;
1572
+ }
1573
+
1574
+ /*
1575
+ * Huffman codeword lengths for dynamic Huffman blocks are compressed using a
1576
+ * separate Huffman code, the "precode", which contains a symbol for each
1577
+ * possible codeword length in the larger code as well as several special
1578
+ * symbols to represent repeated codeword lengths (a form of run-length
1579
+ * encoding). The precode is itself constructed in canonical form, and its
1580
+ * codeword lengths are represented literally in 19 3-bit fields that
1581
+ * immediately precede the compressed codeword lengths of the larger code.
1582
+ */
1583
+
1584
+ /* Precompute the information needed to output dynamic Huffman codes. */
1585
+ static void
1586
+ deflate_precompute_huffman_header(struct libdeflate_compressor *c)
1587
+ {
1588
+ /* Compute how many litlen and offset symbols are needed. */
1589
+
1590
+ for (c->o.precode.num_litlen_syms = DEFLATE_NUM_LITLEN_SYMS;
1591
+ c->o.precode.num_litlen_syms > 257;
1592
+ c->o.precode.num_litlen_syms--)
1593
+ if (c->codes.lens.litlen[c->o.precode.num_litlen_syms - 1] != 0)
1594
+ break;
1595
+
1596
+ for (c->o.precode.num_offset_syms = DEFLATE_NUM_OFFSET_SYMS;
1597
+ c->o.precode.num_offset_syms > 1;
1598
+ c->o.precode.num_offset_syms--)
1599
+ if (c->codes.lens.offset[c->o.precode.num_offset_syms - 1] != 0)
1600
+ break;
1601
+
1602
+ /*
1603
+ * If we're not using the full set of literal/length codeword lengths,
1604
+ * then temporarily move the offset codeword lengths over so that the
1605
+ * literal/length and offset codeword lengths are contiguous.
1606
+ */
1607
+ STATIC_ASSERT(offsetof(struct deflate_lens, offset) ==
1608
+ DEFLATE_NUM_LITLEN_SYMS);
1609
+ if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) {
1610
+ memmove((u8 *)&c->codes.lens + c->o.precode.num_litlen_syms,
1611
+ (u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS,
1612
+ c->o.precode.num_offset_syms);
1613
+ }
1614
+
1615
+ /*
1616
+ * Compute the "items" (RLE / literal tokens and extra bits) with which
1617
+ * the codeword lengths in the larger code will be output.
1618
+ */
1619
+ c->o.precode.num_items =
1620
+ deflate_compute_precode_items((u8 *)&c->codes.lens,
1621
+ c->o.precode.num_litlen_syms +
1622
+ c->o.precode.num_offset_syms,
1623
+ c->o.precode.freqs,
1624
+ c->o.precode.items);
1625
+
1626
+ /* Build the precode. */
1627
+ deflate_make_huffman_code(DEFLATE_NUM_PRECODE_SYMS,
1628
+ MAX_PRE_CODEWORD_LEN,
1629
+ c->o.precode.freqs, c->o.precode.lens,
1630
+ c->o.precode.codewords);
1631
+
1632
+ /* Count how many precode lengths we actually need to output. */
1633
+ for (c->o.precode.num_explicit_lens = DEFLATE_NUM_PRECODE_SYMS;
1634
+ c->o.precode.num_explicit_lens > 4;
1635
+ c->o.precode.num_explicit_lens--)
1636
+ if (c->o.precode.lens[deflate_precode_lens_permutation[
1637
+ c->o.precode.num_explicit_lens - 1]] != 0)
1638
+ break;
1639
+
1640
+ /* Restore the offset codeword lengths if needed. */
1641
+ if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) {
1642
+ memmove((u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS,
1643
+ (u8 *)&c->codes.lens + c->o.precode.num_litlen_syms,
1644
+ c->o.precode.num_offset_syms);
1645
+ }
1646
+ }
1647
+
1648
+ /*
1649
+ * To make it faster to output matches, compute the "full" match length
1650
+ * codewords, i.e. the concatenation of the litlen codeword and the extra bits
1651
+ * for each possible match length.
1652
+ */
1653
+ static void
1654
+ deflate_compute_full_len_codewords(struct libdeflate_compressor *c,
1655
+ const struct deflate_codes *codes)
1656
+ {
1657
+ unsigned len;
1658
+
1659
+ STATIC_ASSERT(MAX_LITLEN_CODEWORD_LEN +
1660
+ DEFLATE_MAX_EXTRA_LENGTH_BITS <= 32);
1661
+
1662
+ for (len = DEFLATE_MIN_MATCH_LEN; len <= DEFLATE_MAX_MATCH_LEN; len++) {
1663
+ unsigned slot = deflate_length_slot[len];
1664
+ unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + slot;
1665
+ u32 extra_bits = len - deflate_length_slot_base[slot];
1666
+
1667
+ c->o.length.codewords[len] =
1668
+ codes->codewords.litlen[litlen_sym] |
1669
+ (extra_bits << codes->lens.litlen[litlen_sym]);
1670
+ c->o.length.lens[len] = codes->lens.litlen[litlen_sym] +
1671
+ deflate_extra_length_bits[slot];
1672
+ }
1673
+ }
1674
+
1675
+ /* Write a match to the output buffer. */
1676
+ #define WRITE_MATCH(c_, codes_, length_, offset_, offset_slot_) \
1677
+ do { \
1678
+ const struct libdeflate_compressor *c__ = (c_); \
1679
+ const struct deflate_codes *codes__ = (codes_); \
1680
+ unsigned length__ = (length_); \
1681
+ unsigned offset__ = (offset_); \
1682
+ unsigned offset_slot__ = (offset_slot_); \
1683
+ \
1684
+ /* Litlen symbol and extra length bits */ \
1685
+ STATIC_ASSERT(CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \
1686
+ DEFLATE_MAX_EXTRA_LENGTH_BITS)); \
1687
+ ADD_BITS(c__->o.length.codewords[length__], \
1688
+ c__->o.length.lens[length__]); \
1689
+ \
1690
+ if (!CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \
1691
+ DEFLATE_MAX_EXTRA_LENGTH_BITS + \
1692
+ MAX_OFFSET_CODEWORD_LEN + \
1693
+ DEFLATE_MAX_EXTRA_OFFSET_BITS)) \
1694
+ FLUSH_BITS(); \
1695
+ \
1696
+ /* Offset symbol */ \
1697
+ ADD_BITS(codes__->codewords.offset[offset_slot__], \
1698
+ codes__->lens.offset[offset_slot__]); \
1699
+ \
1700
+ if (!CAN_BUFFER(MAX_OFFSET_CODEWORD_LEN + \
1701
+ DEFLATE_MAX_EXTRA_OFFSET_BITS)) \
1702
+ FLUSH_BITS(); \
1703
+ \
1704
+ /* Extra offset bits */ \
1705
+ ADD_BITS(offset__ - deflate_offset_slot_base[offset_slot__], \
1706
+ deflate_extra_offset_bits[offset_slot__]); \
1707
+ \
1708
+ FLUSH_BITS(); \
1709
+ } while (0)
1710
+
1711
+ /*
1712
+ * Choose the best type of block to use (dynamic Huffman, static Huffman, or
1713
+ * uncompressed), then output it.
1714
+ *
1715
+ * The uncompressed data of the block is @block_begin[0..@block_length-1]. The
1716
+ * sequence of literals and matches that will be used to compress the block (if
1717
+ * a compressed block is chosen) is given by @sequences if it's non-NULL, or
1718
+ * else @c->p.n.optimum_nodes. @c->freqs and @c->codes must be already set
1719
+ * according to the literals, matches, and end-of-block symbol.
1720
+ */
1721
+ static void
1722
+ deflate_flush_block(struct libdeflate_compressor *c,
1723
+ struct deflate_output_bitstream *os,
1724
+ const u8 *block_begin, u32 block_length,
1725
+ const struct deflate_sequence *sequences,
1726
+ bool is_final_block)
1727
+ {
1728
+ /*
1729
+ * It is hard to get compilers to understand that writes to 'os->next'
1730
+ * don't alias 'os'. That hurts performance significantly, as
1731
+ * everything in 'os' would keep getting re-loaded. ('restrict'
1732
+ * *should* do the trick, but it's unreliable.) Therefore, we keep all
1733
+ * the output bitstream state in local variables, and output bits using
1734
+ * macros. This is similar to what the decompressor does.
1735
+ */
1736
+ const u8 *in_next = block_begin;
1737
+ const u8 * const in_end = block_begin + block_length;
1738
+ bitbuf_t bitbuf = os->bitbuf;
1739
+ unsigned bitcount = os->bitcount;
1740
+ u8 *out_next = os->next;
1741
+ u8 * const out_fast_end =
1742
+ os->end - MIN(WORDBYTES - 1, os->end - out_next);
1743
+ /*
1744
+ * The cost for each block type, in bits. Start with the cost of the
1745
+ * block header which is 3 bits.
1746
+ */
1747
+ u32 dynamic_cost = 3;
1748
+ u32 static_cost = 3;
1749
+ u32 uncompressed_cost = 3;
1750
+ u32 best_cost;
1751
+ struct deflate_codes *codes;
1752
+ unsigned sym;
1753
+
1754
+ ASSERT(block_length >= MIN_BLOCK_LENGTH ||
1755
+ (is_final_block && block_length > 0));
1756
+ is_final_block=is_final_block&&c->in_is_final_block;
1757
+
1758
+ ASSERT(block_length <= MAX_BLOCK_LENGTH);
1759
+ ASSERT(bitcount <= 7);
1760
+ ASSERT((bitbuf & ~(((bitbuf_t)1 << bitcount) - 1)) == 0);
1761
+ ASSERT(out_next <= os->end);
1762
+ ASSERT(!os->overflow);
1763
+
1764
+ /* Precompute the precode items and build the precode. */
1765
+ deflate_precompute_huffman_header(c);
1766
+
1767
+ /* Account for the cost of encoding dynamic Huffman codes. */
1768
+ dynamic_cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens);
1769
+ for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) {
1770
+ u32 extra = deflate_extra_precode_bits[sym];
1771
+
1772
+ dynamic_cost += c->o.precode.freqs[sym] *
1773
+ (extra + c->o.precode.lens[sym]);
1774
+ }
1775
+
1776
+ /* Account for the cost of encoding literals. */
1777
+ for (sym = 0; sym < 144; sym++) {
1778
+ dynamic_cost += c->freqs.litlen[sym] *
1779
+ c->codes.lens.litlen[sym];
1780
+ static_cost += c->freqs.litlen[sym] * 8;
1781
+ }
1782
+ for (; sym < 256; sym++) {
1783
+ dynamic_cost += c->freqs.litlen[sym] *
1784
+ c->codes.lens.litlen[sym];
1785
+ static_cost += c->freqs.litlen[sym] * 9;
1786
+ }
1787
+
1788
+ /* Account for the cost of encoding the end-of-block symbol. */
1789
+ dynamic_cost += c->codes.lens.litlen[DEFLATE_END_OF_BLOCK];
1790
+ static_cost += 7;
1791
+
1792
+ /* Account for the cost of encoding lengths. */
1793
+ for (sym = DEFLATE_FIRST_LEN_SYM;
1794
+ sym < DEFLATE_FIRST_LEN_SYM + ARRAY_LEN(deflate_extra_length_bits);
1795
+ sym++) {
1796
+ u32 extra = deflate_extra_length_bits[
1797
+ sym - DEFLATE_FIRST_LEN_SYM];
1798
+
1799
+ dynamic_cost += c->freqs.litlen[sym] *
1800
+ (extra + c->codes.lens.litlen[sym]);
1801
+ static_cost += c->freqs.litlen[sym] *
1802
+ (extra + c->static_codes.lens.litlen[sym]);
1803
+ }
1804
+
1805
+ /* Account for the cost of encoding offsets. */
1806
+ for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++) {
1807
+ u32 extra = deflate_extra_offset_bits[sym];
1808
+
1809
+ dynamic_cost += c->freqs.offset[sym] *
1810
+ (extra + c->codes.lens.offset[sym]);
1811
+ static_cost += c->freqs.offset[sym] * (extra + 5);
1812
+ }
1813
+
1814
+ /* Compute the cost of using uncompressed blocks. */
1815
+ uncompressed_cost += (-(bitcount + 3) & 7) + 32 +
1816
+ (40 * (DIV_ROUND_UP(block_length,
1817
+ UINT16_MAX) - 1)) +
1818
+ (8 * block_length);
1819
+
1820
+ /*
1821
+ * Choose and output the cheapest type of block. If there is a tie,
1822
+ * prefer uncompressed, then static, then dynamic.
1823
+ */
1824
+
1825
+ best_cost = MIN(dynamic_cost, MIN(static_cost, uncompressed_cost));
1826
+
1827
+ /* If the block isn't going to fit, then stop early. */
1828
+ if (DIV_ROUND_UP(bitcount + best_cost, 8) > os->end - out_next) {
1829
+ os->overflow = true;
1830
+ return;
1831
+ }
1832
+ /*
1833
+ * Else, now we know that the block fits, so no further bounds checks on
1834
+ * the output buffer are required until the next block.
1835
+ */
1836
+
1837
+ if (best_cost == uncompressed_cost) {
1838
+ /*
1839
+ * Uncompressed block(s). DEFLATE limits the length of
1840
+ * uncompressed blocks to UINT16_MAX bytes, so if the length of
1841
+ * the "block" we're flushing is over UINT16_MAX, we actually
1842
+ * output multiple blocks.
1843
+ */
1844
+ do {
1845
+ u8 bfinal = 0;
1846
+ size_t len = UINT16_MAX;
1847
+
1848
+ if (in_end - in_next <= UINT16_MAX) {
1849
+ bfinal = is_final_block;
1850
+ len = in_end - in_next;
1851
+ }
1852
+ /* It was already checked that there is enough space. */
1853
+ ASSERT(os->end - out_next >=
1854
+ DIV_ROUND_UP(bitcount + 3, 8) + 4 + len);
1855
+ /*
1856
+ * Output BFINAL (1 bit) and BTYPE (2 bits), then align
1857
+ * to a byte boundary.
1858
+ */
1859
+ STATIC_ASSERT(DEFLATE_BLOCKTYPE_UNCOMPRESSED == 0);
1860
+ *out_next++ = (bfinal << bitcount) | bitbuf;
1861
+ if (bitcount > 5)
1862
+ *out_next++ = 0;
1863
+ bitbuf = 0;
1864
+ bitcount = 0;
1865
+ /* Output LEN and NLEN, then the data itself. */
1866
+ put_unaligned_le16(len, out_next);
1867
+ out_next += 2;
1868
+ put_unaligned_le16(~len, out_next);
1869
+ out_next += 2;
1870
+ memcpy(out_next, in_next, len);
1871
+ out_next += len;
1872
+ in_next += len;
1873
+ } while (in_next != in_end);
1874
+ /* Done outputting uncompressed block(s) */
1875
+ goto out;
1876
+ }
1877
+
1878
+ if (best_cost == static_cost) {
1879
+ /* Static Huffman block */
1880
+ codes = &c->static_codes;
1881
+ ADD_BITS(is_final_block, 1);
1882
+ ADD_BITS(DEFLATE_BLOCKTYPE_STATIC_HUFFMAN, 2);
1883
+ FLUSH_BITS();
1884
+ } else {
1885
+ const unsigned num_explicit_lens = c->o.precode.num_explicit_lens;
1886
+ const unsigned num_precode_items = c->o.precode.num_items;
1887
+ unsigned precode_sym, precode_item;
1888
+ unsigned i;
1889
+
1890
+ /* Dynamic Huffman block */
1891
+
1892
+ codes = &c->codes;
1893
+ STATIC_ASSERT(CAN_BUFFER(1 + 2 + 5 + 5 + 4 + 3));
1894
+ ADD_BITS(is_final_block, 1);
1895
+ ADD_BITS(DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN, 2);
1896
+ ADD_BITS(c->o.precode.num_litlen_syms - 257, 5);
1897
+ ADD_BITS(c->o.precode.num_offset_syms - 1, 5);
1898
+ ADD_BITS(num_explicit_lens - 4, 4);
1899
+
1900
+ /* Output the lengths of the codewords in the precode. */
1901
+ if (CAN_BUFFER(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) {
1902
+ /*
1903
+ * A 64-bit bitbuffer is just one bit too small to hold
1904
+ * the maximum number of precode lens, so to minimize
1905
+ * flushes we merge one len with the previous fields.
1906
+ */
1907
+ precode_sym = deflate_precode_lens_permutation[0];
1908
+ ADD_BITS(c->o.precode.lens[precode_sym], 3);
1909
+ FLUSH_BITS();
1910
+ i = 1; /* num_explicit_lens >= 4 */
1911
+ do {
1912
+ precode_sym =
1913
+ deflate_precode_lens_permutation[i];
1914
+ ADD_BITS(c->o.precode.lens[precode_sym], 3);
1915
+ } while (++i < num_explicit_lens);
1916
+ FLUSH_BITS();
1917
+ } else {
1918
+ FLUSH_BITS();
1919
+ i = 0;
1920
+ do {
1921
+ precode_sym =
1922
+ deflate_precode_lens_permutation[i];
1923
+ ADD_BITS(c->o.precode.lens[precode_sym], 3);
1924
+ FLUSH_BITS();
1925
+ } while (++i < num_explicit_lens);
1926
+ }
1927
+
1928
+ /*
1929
+ * Output the lengths of the codewords in the litlen and offset
1930
+ * codes, encoded by the precode.
1931
+ */
1932
+ i = 0;
1933
+ do {
1934
+ precode_item = c->o.precode.items[i];
1935
+ precode_sym = precode_item & 0x1F;
1936
+ STATIC_ASSERT(CAN_BUFFER(MAX_PRE_CODEWORD_LEN + 7));
1937
+ ADD_BITS(c->o.precode.codewords[precode_sym],
1938
+ c->o.precode.lens[precode_sym]);
1939
+ ADD_BITS(precode_item >> 5,
1940
+ deflate_extra_precode_bits[precode_sym]);
1941
+ FLUSH_BITS();
1942
+ } while (++i < num_precode_items);
1943
+ }
1944
+
1945
+ /* Output the literals and matches for a dynamic or static block. */
1946
+ ASSERT(bitcount <= 7);
1947
+ deflate_compute_full_len_codewords(c, codes);
1948
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
1949
+ if (sequences == NULL) {
1950
+ /* Output the literals and matches from the minimum-cost path */
1951
+ struct deflate_optimum_node *cur_node =
1952
+ &c->p.n.optimum_nodes[0];
1953
+ struct deflate_optimum_node * const end_node =
1954
+ &c->p.n.optimum_nodes[block_length];
1955
+ do {
1956
+ unsigned length = cur_node->item & OPTIMUM_LEN_MASK;
1957
+ unsigned offset = cur_node->item >>
1958
+ OPTIMUM_OFFSET_SHIFT;
1959
+ if (length == 1) {
1960
+ /* Literal */
1961
+ ADD_BITS(codes->codewords.litlen[offset],
1962
+ codes->lens.litlen[offset]);
1963
+ FLUSH_BITS();
1964
+ } else {
1965
+ /* Match */
1966
+ WRITE_MATCH(c, codes, length, offset,
1967
+ c->p.n.offset_slot_full[offset]);
1968
+ }
1969
+ cur_node += length;
1970
+ } while (cur_node != end_node);
1971
+ } else
1972
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
1973
+ {
1974
+ /* Output the literals and matches from the sequences list. */
1975
+ const struct deflate_sequence *seq;
1976
+
1977
+ for (seq = sequences; ; seq++) {
1978
+ u32 litrunlen = seq->litrunlen_and_length &
1979
+ SEQ_LITRUNLEN_MASK;
1980
+ unsigned length = seq->litrunlen_and_length >>
1981
+ SEQ_LENGTH_SHIFT;
1982
+ unsigned lit;
1983
+
1984
+ /* Output a run of literals. */
1985
+ if (CAN_BUFFER(4 * MAX_LITLEN_CODEWORD_LEN)) {
1986
+ for (; litrunlen >= 4; litrunlen -= 4) {
1987
+ lit = *in_next++;
1988
+ ADD_BITS(codes->codewords.litlen[lit],
1989
+ codes->lens.litlen[lit]);
1990
+ lit = *in_next++;
1991
+ ADD_BITS(codes->codewords.litlen[lit],
1992
+ codes->lens.litlen[lit]);
1993
+ lit = *in_next++;
1994
+ ADD_BITS(codes->codewords.litlen[lit],
1995
+ codes->lens.litlen[lit]);
1996
+ lit = *in_next++;
1997
+ ADD_BITS(codes->codewords.litlen[lit],
1998
+ codes->lens.litlen[lit]);
1999
+ FLUSH_BITS();
2000
+ }
2001
+ if (litrunlen-- != 0) {
2002
+ lit = *in_next++;
2003
+ ADD_BITS(codes->codewords.litlen[lit],
2004
+ codes->lens.litlen[lit]);
2005
+ if (litrunlen-- != 0) {
2006
+ lit = *in_next++;
2007
+ ADD_BITS(codes->codewords.litlen[lit],
2008
+ codes->lens.litlen[lit]);
2009
+ if (litrunlen-- != 0) {
2010
+ lit = *in_next++;
2011
+ ADD_BITS(codes->codewords.litlen[lit],
2012
+ codes->lens.litlen[lit]);
2013
+ }
2014
+ }
2015
+ FLUSH_BITS();
2016
+ }
2017
+ } else {
2018
+ while (litrunlen--) {
2019
+ lit = *in_next++;
2020
+ ADD_BITS(codes->codewords.litlen[lit],
2021
+ codes->lens.litlen[lit]);
2022
+ FLUSH_BITS();
2023
+ }
2024
+ }
2025
+
2026
+ if (length == 0) { /* Last sequence? */
2027
+ ASSERT(in_next == in_end);
2028
+ break;
2029
+ }
2030
+
2031
+ /* Output a match. */
2032
+ WRITE_MATCH(c, codes, length, seq->offset,
2033
+ seq->offset_slot);
2034
+ in_next += length;
2035
+ }
2036
+ }
2037
+
2038
+ /* Output the end-of-block symbol. */
2039
+ ASSERT(bitcount <= 7);
2040
+ ADD_BITS(codes->codewords.litlen[DEFLATE_END_OF_BLOCK],
2041
+ codes->lens.litlen[DEFLATE_END_OF_BLOCK]);
2042
+ FLUSH_BITS();
2043
+ out:
2044
+ ASSERT(bitcount <= 7);
2045
+ /*
2046
+ * Assert that the block cost was computed correctly. This is relied on
2047
+ * above for the bounds check on the output buffer. Also,
2048
+ * libdeflate_deflate_compress_bound() relies on this via the assumption
2049
+ * that uncompressed blocks will always be used when cheapest.
2050
+ */
2051
+ ASSERT(8 * (out_next - os->next) + bitcount - os->bitcount == best_cost);
2052
+ os->bitbuf = bitbuf;
2053
+ os->bitcount = bitcount;
2054
+ os->next = out_next;
2055
+ }
2056
+
2057
+ static forceinline void
2058
+ deflate_finish_block(struct libdeflate_compressor *c,
2059
+ struct deflate_output_bitstream *os,
2060
+ const u8 *block_begin, u32 block_length,
2061
+ const struct deflate_sequence *sequences,
2062
+ bool is_final_block)
2063
+ {
2064
+ c->freqs.litlen[DEFLATE_END_OF_BLOCK]++;
2065
+ deflate_make_huffman_codes(&c->freqs, &c->codes);
2066
+ deflate_flush_block(c, os, block_begin, block_length, sequences,
2067
+ is_final_block);
2068
+ }
2069
+
2070
+ /******************************************************************************/
2071
+
2072
+ /*
2073
+ * Block splitting algorithm. The problem is to decide when it is worthwhile to
2074
+ * start a new block with new Huffman codes. There is a theoretically optimal
2075
+ * solution: recursively consider every possible block split, considering the
2076
+ * exact cost of each block, and choose the minimum cost approach. But this is
2077
+ * far too slow. Instead, as an approximation, we can count symbols and after
2078
+ * every N symbols, compare the expected distribution of symbols based on the
2079
+ * previous data with the actual distribution. If they differ "by enough", then
2080
+ * start a new block.
2081
+ *
2082
+ * As an optimization and heuristic, we don't distinguish between every symbol
2083
+ * but rather we combine many symbols into a single "observation type". For
2084
+ * literals we only look at the high bits and low bits, and for matches we only
2085
+ * look at whether the match is long or not. The assumption is that for typical
2086
+ * "real" data, places that are good block boundaries will tend to be noticeable
2087
+ * based only on changes in these aggregate probabilities, without looking for
2088
+ * subtle differences in individual symbols. For example, a change from ASCII
2089
+ * bytes to non-ASCII bytes, or from few matches (generally less compressible)
2090
+ * to many matches (generally more compressible), would be easily noticed based
2091
+ * on the aggregates.
2092
+ *
2093
+ * For determining whether the probability distributions are "different enough"
2094
+ * to start a new block, the simple heuristic of splitting when the sum of
2095
+ * absolute differences exceeds a constant seems to be good enough. We also add
2096
+ * a number proportional to the block length so that the algorithm is more
2097
+ * likely to end long blocks than short blocks. This reflects the general
2098
+ * expectation that it will become increasingly beneficial to start a new block
2099
+ * as the current block grows longer.
2100
+ *
2101
+ * Finally, for an approximation, it is not strictly necessary that the exact
2102
+ * symbols being used are considered. With "near-optimal parsing", for example,
2103
+ * the actual symbols that will be used are unknown until after the block
2104
+ * boundary is chosen and the block has been optimized. Since the final choices
2105
+ * cannot be used, we can use preliminary "greedy" choices instead.
2106
+ */
2107
+
2108
+ /* Initialize the block split statistics when starting a new block. */
2109
+ static void
2110
+ init_block_split_stats(struct block_split_stats *stats)
2111
+ {
2112
+ int i;
2113
+
2114
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++) {
2115
+ stats->new_observations[i] = 0;
2116
+ stats->observations[i] = 0;
2117
+ }
2118
+ stats->num_new_observations = 0;
2119
+ stats->num_observations = 0;
2120
+ }
2121
+
2122
+ /*
2123
+ * Literal observation. Heuristic: use the top 2 bits and low 1 bits of the
2124
+ * literal, for 8 possible literal observation types.
2125
+ */
2126
+ static forceinline void
2127
+ observe_literal(struct block_split_stats *stats, u8 lit)
2128
+ {
2129
+ stats->new_observations[((lit >> 5) & 0x6) | (lit & 1)]++;
2130
+ stats->num_new_observations++;
2131
+ }
2132
+
2133
+ /*
2134
+ * Match observation. Heuristic: use one observation type for "short match" and
2135
+ * one observation type for "long match".
2136
+ */
2137
+ static forceinline void
2138
+ observe_match(struct block_split_stats *stats, unsigned length)
2139
+ {
2140
+ stats->new_observations[NUM_LITERAL_OBSERVATION_TYPES +
2141
+ (length >= 9)]++;
2142
+ stats->num_new_observations++;
2143
+ }
2144
+
2145
+ static void
2146
+ merge_new_observations(struct block_split_stats *stats)
2147
+ {
2148
+ int i;
2149
+
2150
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++) {
2151
+ stats->observations[i] += stats->new_observations[i];
2152
+ stats->new_observations[i] = 0;
2153
+ }
2154
+ stats->num_observations += stats->num_new_observations;
2155
+ stats->num_new_observations = 0;
2156
+ }
2157
+
2158
+ static bool
2159
+ do_end_block_check(struct block_split_stats *stats, u32 block_length)
2160
+ {
2161
+ if (stats->num_observations > 0) {
2162
+ /*
2163
+ * Compute the sum of absolute differences of probabilities. To
2164
+ * avoid needing to use floating point arithmetic or do slow
2165
+ * divisions, we do all arithmetic with the probabilities
2166
+ * multiplied by num_observations * num_new_observations. E.g.,
2167
+ * for the "old" observations the probabilities would be
2168
+ * (double)observations[i] / num_observations, but since we
2169
+ * multiply by both num_observations and num_new_observations we
2170
+ * really do observations[i] * num_new_observations.
2171
+ */
2172
+ u32 total_delta = 0;
2173
+ u32 num_items;
2174
+ u32 cutoff;
2175
+ int i;
2176
+
2177
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++) {
2178
+ u32 expected = stats->observations[i] *
2179
+ stats->num_new_observations;
2180
+ u32 actual = stats->new_observations[i] *
2181
+ stats->num_observations;
2182
+ u32 delta = (actual > expected) ? actual - expected :
2183
+ expected - actual;
2184
+
2185
+ total_delta += delta;
2186
+ }
2187
+
2188
+ num_items = stats->num_observations +
2189
+ stats->num_new_observations;
2190
+ /*
2191
+ * Heuristic: the cutoff is when the sum of absolute differences
2192
+ * of probabilities becomes at least 200/512. As above, the
2193
+ * probability is multiplied by both num_new_observations and
2194
+ * num_observations. Be careful to avoid integer overflow.
2195
+ */
2196
+ cutoff = stats->num_new_observations * 200 / 512 *
2197
+ stats->num_observations;
2198
+ /*
2199
+ * Very short blocks have a lot of overhead for the Huffman
2200
+ * codes, so only use them if it clearly seems worthwhile.
2201
+ * (This is an additional penalty, which adds to the smaller
2202
+ * penalty below which scales more slowly.)
2203
+ */
2204
+ if (block_length < 10000 && num_items < 8192)
2205
+ cutoff += (u64)cutoff * (8192 - num_items) / 8192;
2206
+
2207
+ /* Ready to end the block? */
2208
+ if (total_delta +
2209
+ (block_length / 4096) * stats->num_observations >= cutoff)
2210
+ return true;
2211
+ }
2212
+ merge_new_observations(stats);
2213
+ return false;
2214
+ }
2215
+
2216
+ static forceinline bool
2217
+ ready_to_check_block(const struct block_split_stats *stats,
2218
+ const u8 *in_block_begin, const u8 *in_next,
2219
+ const u8 *in_end)
2220
+ {
2221
+ return stats->num_new_observations >= NUM_OBSERVATIONS_PER_BLOCK_CHECK
2222
+ && in_next - in_block_begin >= MIN_BLOCK_LENGTH
2223
+ && in_end - in_next >= MIN_BLOCK_LENGTH;
2224
+ }
2225
+
2226
+ static forceinline bool
2227
+ should_end_block(struct block_split_stats *stats,
2228
+ const u8 *in_block_begin, const u8 *in_next, const u8 *in_end)
2229
+ {
2230
+ /* Ready to try to end the block (again)? */
2231
+ if (!ready_to_check_block(stats, in_block_begin, in_next, in_end))
2232
+ return false;
2233
+
2234
+ return do_end_block_check(stats, in_next - in_block_begin);
2235
+ }
2236
+
2237
+ /******************************************************************************/
2238
+
2239
+ static void
2240
+ deflate_begin_sequences(struct libdeflate_compressor *c,
2241
+ struct deflate_sequence *first_seq)
2242
+ {
2243
+ deflate_reset_symbol_frequencies(c);
2244
+ first_seq->litrunlen_and_length = 0;
2245
+ }
2246
+
2247
+ static forceinline void
2248
+ deflate_choose_literal(struct libdeflate_compressor *c, unsigned literal,
2249
+ bool gather_split_stats, struct deflate_sequence *seq)
2250
+ {
2251
+ c->freqs.litlen[literal]++;
2252
+
2253
+ if (gather_split_stats)
2254
+ observe_literal(&c->split_stats, literal);
2255
+
2256
+ STATIC_ASSERT(MAX_BLOCK_LENGTH <= SEQ_LITRUNLEN_MASK);
2257
+ seq->litrunlen_and_length++;
2258
+ }
2259
+
2260
+ static forceinline void
2261
+ deflate_choose_match(struct libdeflate_compressor *c,
2262
+ unsigned length, unsigned offset, bool gather_split_stats,
2263
+ struct deflate_sequence **seq_p)
2264
+ {
2265
+ struct deflate_sequence *seq = *seq_p;
2266
+ unsigned length_slot = deflate_length_slot[length];
2267
+ unsigned offset_slot = deflate_get_offset_slot(offset);
2268
+
2269
+ c->freqs.litlen[DEFLATE_FIRST_LEN_SYM + length_slot]++;
2270
+ c->freqs.offset[offset_slot]++;
2271
+ if (gather_split_stats)
2272
+ observe_match(&c->split_stats, length);
2273
+
2274
+ seq->litrunlen_and_length |= (u32)length << SEQ_LENGTH_SHIFT;
2275
+ seq->offset = offset;
2276
+ seq->offset_slot = offset_slot;
2277
+
2278
+ seq++;
2279
+ seq->litrunlen_and_length = 0;
2280
+ *seq_p = seq;
2281
+ }
2282
+
2283
+ /*
2284
+ * Decrease the maximum and nice match lengths if we're approaching the end of
2285
+ * the input buffer.
2286
+ */
2287
+ static forceinline void
2288
+ adjust_max_and_nice_len(unsigned *max_len, unsigned *nice_len, size_t remaining)
2289
+ {
2290
+ if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) {
2291
+ *max_len = remaining;
2292
+ *nice_len = MIN(*nice_len, *max_len);
2293
+ }
2294
+ }
2295
+
2296
+ /*
2297
+ * Choose the minimum match length for the greedy and lazy parsers.
2298
+ *
2299
+ * By default the minimum match length is 3, which is the smallest length the
2300
+ * DEFLATE format allows. However, with greedy and lazy parsing, some data
2301
+ * (e.g. DNA sequencing data) benefits greatly from a longer minimum length.
2302
+ * Typically, this is because literals are very cheap. In general, the
2303
+ * near-optimal parser handles this case naturally, but the greedy and lazy
2304
+ * parsers need a heuristic to decide when to use short matches.
2305
+ *
2306
+ * The heuristic we use is to make the minimum match length depend on the number
2307
+ * of different literals that exist in the data. If there are many different
2308
+ * literals, then literals will probably be expensive, so short matches will
2309
+ * probably be worthwhile. Conversely, if not many literals are used, then
2310
+ * probably literals will be cheap and short matches won't be worthwhile.
2311
+ */
2312
+ static unsigned
2313
+ choose_min_match_len(unsigned num_used_literals, unsigned max_search_depth)
2314
+ {
2315
+ /* map from num_used_literals to min_len */
2316
+ static const u8 min_lens[] = {
2317
+ 9, 9, 9, 9, 9, 9, 8, 8, 7, 7, 6, 6, 6, 6, 6, 6,
2318
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
2319
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4,
2320
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2321
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2322
+ /* The rest is implicitly 3. */
2323
+ };
2324
+ unsigned min_len;
2325
+
2326
+ STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN <= 3);
2327
+ STATIC_ASSERT(ARRAY_LEN(min_lens) <= DEFLATE_NUM_LITERALS + 1);
2328
+
2329
+ if (num_used_literals >= ARRAY_LEN(min_lens))
2330
+ return 3;
2331
+ min_len = min_lens[num_used_literals];
2332
+ /*
2333
+ * With a low max_search_depth, it may be too hard to find long matches.
2334
+ */
2335
+ if (max_search_depth < 16) {
2336
+ if (max_search_depth < 5)
2337
+ min_len = MIN(min_len, 4);
2338
+ else if (max_search_depth < 10)
2339
+ min_len = MIN(min_len, 5);
2340
+ else
2341
+ min_len = MIN(min_len, 7);
2342
+ }
2343
+ return min_len;
2344
+ }
2345
+
2346
+ static unsigned
2347
+ calculate_min_match_len(const u8 *data, size_t data_len,
2348
+ unsigned max_search_depth)
2349
+ {
2350
+ u8 used[256] = { 0 };
2351
+ unsigned num_used_literals = 0;
2352
+ size_t i;
2353
+
2354
+ /*
2355
+ * For very short inputs, the static Huffman code has a good chance of
2356
+ * being best, in which case there is no reason to avoid short matches.
2357
+ */
2358
+ if (data_len < 512)
2359
+ return DEFLATE_MIN_MATCH_LEN;
2360
+
2361
+ /*
2362
+ * For an initial approximation, scan the first 4 KiB of data. The
2363
+ * caller may use recalculate_min_match_len() to update min_len later.
2364
+ */
2365
+ data_len = MIN(data_len, 4096);
2366
+ for (i = 0; i < data_len; i++)
2367
+ used[data[i]] = 1;
2368
+ for (i = 0; i < 256; i++)
2369
+ num_used_literals += used[i];
2370
+ return choose_min_match_len(num_used_literals, max_search_depth);
2371
+ }
2372
+
2373
+ /*
2374
+ * Recalculate the minimum match length for a block, now that we know the
2375
+ * distribution of literals that are actually being used (freqs->litlen).
2376
+ */
2377
+ static unsigned
2378
+ recalculate_min_match_len(const struct deflate_freqs *freqs,
2379
+ unsigned max_search_depth)
2380
+ {
2381
+ u32 literal_freq = 0;
2382
+ u32 cutoff;
2383
+ unsigned num_used_literals = 0;
2384
+ int i;
2385
+
2386
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
2387
+ literal_freq += freqs->litlen[i];
2388
+
2389
+ cutoff = literal_freq >> 10; /* Ignore literals used very rarely. */
2390
+
2391
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++) {
2392
+ if (freqs->litlen[i] > cutoff)
2393
+ num_used_literals++;
2394
+ }
2395
+ return choose_min_match_len(num_used_literals, max_search_depth);
2396
+ }
2397
+
2398
+ static forceinline const u8 *
2399
+ choose_max_block_end(const u8 *in_block_begin, const u8 *in_end,
2400
+ size_t soft_max_len)
2401
+ {
2402
+ if (in_end - in_block_begin < soft_max_len + MIN_BLOCK_LENGTH)
2403
+ return in_end;
2404
+ return in_block_begin + soft_max_len;
2405
+ }
2406
+
2407
+ /*
2408
+ * This is the level 0 "compressor". It always outputs uncompressed blocks.
2409
+ */
2410
+ static size_t
2411
+ deflate_compress_none(const u8 *in, size_t in_nbytes,
2412
+ u8 *out, size_t out_nbytes_avail,
2413
+ bitbuf_t bitbuf,unsigned bitcount,u8 is_final_block)
2414
+ {
2415
+ const u8 *in_next = in;
2416
+ const u8 * const in_end = in + in_nbytes;
2417
+ u8 *out_next = out;
2418
+ u8 * const out_end = out + out_nbytes_avail;
2419
+ ASSERT(bitcount<=7);
2420
+ STATIC_ASSERT(DEFLATE_BLOCKTYPE_UNCOMPRESSED == 0);
2421
+
2422
+ /*
2423
+ * If the input is zero-length, we still must output a block in order
2424
+ * for the output to be a valid DEFLATE stream. Handle this case
2425
+ * specially to avoid potentially passing NULL to memcpy() below.
2426
+ */
2427
+ if (unlikely((in_nbytes == 0)&&(bitcount<=5))) {
2428
+ if (unlikely(out_nbytes_avail < 5))
2429
+ return 0;
2430
+ /* BFINAL and BTYPE */
2431
+ *out_next++ = (u8)((is_final_block<<bitcount) | bitbuf);
2432
+ /* LEN and NLEN */
2433
+ put_unaligned_le32(0xFFFF0000, out_next);
2434
+ return 5;
2435
+ }
2436
+
2437
+ do {
2438
+ u8 bfinal = 0;
2439
+ size_t len = UINT16_MAX;
2440
+
2441
+ if (in_end - in_next <= UINT16_MAX) {
2442
+ bfinal = is_final_block;
2443
+ len = in_end - in_next;
2444
+ }
2445
+
2446
+ if (bitcount==0){
2447
+ if (out_end - out_next < 5 + len)
2448
+ return 0;
2449
+ /*
2450
+ * Output BFINAL and BTYPE. The stream is already byte-aligned
2451
+ * here, so this step always requires outputting exactly 1 byte.
2452
+ */
2453
+ *out_next++ = bfinal | (DEFLATE_BLOCKTYPE_UNCOMPRESSED << 1);
2454
+ }else{
2455
+ /* It was already checked that there is enough space. */
2456
+ if (out_end - out_next < DIV_ROUND_UP(bitcount + 3, 8) + 4 + len)
2457
+ return 0;
2458
+ /*
2459
+ * Output BFINAL (1 bit) and BTYPE (2 bits), then align
2460
+ * to a byte boundary.
2461
+ */
2462
+ *out_next++ = (bfinal << bitcount) | bitbuf;
2463
+ if (unlikely(bitcount > 5))
2464
+ *out_next++ = 0;
2465
+ bitbuf = 0;
2466
+ bitcount = 0;
2467
+ }
2468
+
2469
+ /* Output LEN and NLEN, then the data itself. */
2470
+ put_unaligned_le16(len, out_next);
2471
+ out_next += 2;
2472
+ put_unaligned_le16(~len, out_next);
2473
+ out_next += 2;
2474
+ memcpy(out_next, in_next, len);
2475
+ out_next += len;
2476
+ in_next += len;
2477
+ } while (in_next != in_end);
2478
+
2479
+ return out_next - out;
2480
+ }
2481
+
2482
+ /*
2483
+ * This is a faster variant of deflate_compress_greedy(). It uses the
2484
+ * ht_matchfinder rather than the hc_matchfinder. It also skips the block
2485
+ * splitting algorithm and just uses fixed length blocks. c->max_search_depth
2486
+ * has no effect with this algorithm, as it is hardcoded in ht_matchfinder.h.
2487
+ */
2488
+ static void
2489
+ deflate_compress_fastest(struct libdeflate_compressor * restrict c,
2490
+ const u8* in_block_with_dict,size_t dict_nbytes, size_t in_nbytes,
2491
+ size_t in_border_nbytes,struct deflate_output_bitstream *os)
2492
+ {
2493
+ const u8 *in_next = in_block_with_dict+dict_nbytes;
2494
+ const u8 *in_end = in_next + in_nbytes;
2495
+ const u8* in_border_end= in_end + in_border_nbytes;
2496
+ const u8 *in_cur_base = in_block_with_dict;
2497
+ size_t dict_nbytes_continue;
2498
+ unsigned max_len = DEFLATE_MAX_MATCH_LEN;
2499
+ unsigned nice_len = MIN(c->nice_match_length, max_len);
2500
+ u32 next_hash;
2501
+
2502
+ if (c->dict_pos_for_blocks_continue == ~(size_t)0){
2503
+ dict_nbytes_continue=0;
2504
+ next_hash=0;
2505
+ ht_matchfinder_init(&c->p.f.ht_mf);
2506
+ }else{
2507
+ dict_nbytes_continue=dict_nbytes - c->dict_pos_for_blocks_continue;
2508
+ next_hash=c->next_hashes_for_blocks_continue0;
2509
+ ASSERT(c->slide_pos_for_blocks_continue<=MATCHFINDER_WINDOW_SIZE);
2510
+ in_cur_base=in_block_with_dict+dict_nbytes - c->slide_pos_for_blocks_continue;
2511
+ }
2512
+
2513
+ if (dict_nbytes > dict_nbytes_continue){
2514
+ ASSERT(dict_nbytes-dict_nbytes_continue<=MATCHFINDER_WINDOW_SIZE);
2515
+ ht_matchfinder_skip_bytes(&c->p.f.ht_mf,
2516
+ &in_cur_base,
2517
+ in_cur_base+dict_nbytes_continue,
2518
+ in_border_end,
2519
+ dict_nbytes-dict_nbytes_continue,
2520
+ &next_hash);
2521
+ }
2522
+
2523
+ do {
2524
+ /* Starting a new DEFLATE block */
2525
+
2526
+ const u8 * const in_block_begin = in_next;
2527
+ const u8 * const in_max_block_end = choose_max_block_end(
2528
+ in_next, in_end, FAST_SOFT_MAX_BLOCK_LENGTH);
2529
+ struct deflate_sequence *seq = c->p.f.sequences;
2530
+
2531
+ deflate_begin_sequences(c, seq);
2532
+
2533
+ do {
2534
+ u32 length;
2535
+ u32 offset;
2536
+ size_t remaining = in_border_end - in_next;
2537
+ size_t length_limit = in_end - in_next;
2538
+
2539
+ if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) {
2540
+ max_len = remaining;
2541
+ if (unlikely(length_limit<HT_MATCHFINDER_REQUIRED_NBYTES)){
2542
+ do {
2543
+ deflate_choose_literal(c,
2544
+ *in_next++, false, seq);
2545
+ } while (--length_limit);
2546
+ break;
2547
+ }
2548
+ nice_len = MIN(nice_len, max_len);
2549
+ }
2550
+ length = ht_matchfinder_longest_match(&c->p.f.ht_mf,
2551
+ &in_cur_base,
2552
+ in_next,
2553
+ max_len,
2554
+ nice_len,
2555
+ &next_hash,
2556
+ &offset);
2557
+ length=MIN(length_limit,length);
2558
+ if (length>=HT_MATCHFINDER_MIN_MATCH_LEN) {
2559
+ /* Match found */
2560
+ deflate_choose_match(c, length, offset, false,
2561
+ &seq);
2562
+ ht_matchfinder_skip_bytes(&c->p.f.ht_mf,
2563
+ &in_cur_base,
2564
+ in_next + 1,
2565
+ in_border_end,
2566
+ length - 1,
2567
+ &next_hash);
2568
+ in_next += length;
2569
+ } else {
2570
+ /* No match found */
2571
+ deflate_choose_literal(c, *in_next++, false,
2572
+ seq);
2573
+ }
2574
+
2575
+ /* Check if it's time to output another block. */
2576
+ } while (in_next < in_max_block_end &&
2577
+ seq < &c->p.f.sequences[FAST_SEQ_STORE_LENGTH]);
2578
+
2579
+ deflate_finish_block(c, os, in_block_begin,
2580
+ in_next - in_block_begin,
2581
+ c->p.f.sequences, in_next == in_end);
2582
+ } while (in_next != in_end && !os->overflow);
2583
+ c->next_hashes_for_blocks_continue0=next_hash;
2584
+ c->slide_pos_for_blocks_continue=in_end-in_cur_base;
2585
+ }
2586
+
2587
+ /*
2588
+ * This is the "greedy" DEFLATE compressor. It always chooses the longest match.
2589
+ */
2590
+ static void
2591
+ deflate_compress_greedy(struct libdeflate_compressor * restrict c,
2592
+ const u8* in_block_with_dict,size_t dict_nbytes, size_t in_nbytes,
2593
+ size_t in_border_nbytes,struct deflate_output_bitstream *os)
2594
+ {
2595
+ const u8 *in_next = in_block_with_dict+dict_nbytes;
2596
+ const u8 *in_end = in_next + in_nbytes;
2597
+ const u8* in_border_end= in_end + in_border_nbytes;
2598
+ const u8 *in_cur_base = in_block_with_dict;
2599
+ size_t dict_nbytes_continue;
2600
+ unsigned max_len = DEFLATE_MAX_MATCH_LEN;
2601
+ unsigned nice_len = MIN(c->nice_match_length, max_len);
2602
+ u32 next_hashes[2];
2603
+
2604
+ if (c->dict_pos_for_blocks_continue == ~(size_t)0){
2605
+ dict_nbytes_continue=0;
2606
+ next_hashes[0]=0;
2607
+ next_hashes[1]=0;
2608
+ hc_matchfinder_init(&c->p.g.hc_mf);
2609
+ }else{
2610
+ dict_nbytes_continue=dict_nbytes - c->dict_pos_for_blocks_continue;
2611
+ next_hashes[0]=c->next_hashes_for_blocks_continue0;
2612
+ next_hashes[1]=c->next_hashes_for_blocks_continue1;
2613
+ ASSERT(c->slide_pos_for_blocks_continue<=MATCHFINDER_WINDOW_SIZE);
2614
+ in_cur_base=in_block_with_dict+dict_nbytes - c->slide_pos_for_blocks_continue;
2615
+ }
2616
+ if (dict_nbytes > dict_nbytes_continue){
2617
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2618
+ &in_cur_base,
2619
+ in_cur_base+dict_nbytes_continue,
2620
+ in_border_end,
2621
+ dict_nbytes-dict_nbytes_continue,
2622
+ next_hashes);
2623
+ }
2624
+
2625
+ do {
2626
+ /* Starting a new DEFLATE block */
2627
+
2628
+ const u8 * const in_block_begin = in_next;
2629
+ const u8 * const in_max_block_end = choose_max_block_end(
2630
+ in_next, in_end, SOFT_MAX_BLOCK_LENGTH);
2631
+ struct deflate_sequence *seq = c->p.g.sequences;
2632
+ unsigned min_len;
2633
+
2634
+ init_block_split_stats(&c->split_stats);
2635
+ deflate_begin_sequences(c, seq);
2636
+ min_len = calculate_min_match_len(in_next,
2637
+ in_max_block_end - in_next,
2638
+ c->max_search_depth);
2639
+ do {
2640
+ u32 length;
2641
+ u32 offset;
2642
+ const size_t length_limit = in_end - in_next;
2643
+
2644
+ adjust_max_and_nice_len(&max_len, &nice_len,
2645
+ in_border_end - in_next);
2646
+ length = hc_matchfinder_longest_match(
2647
+ &c->p.g.hc_mf,
2648
+ &in_cur_base,
2649
+ in_next,
2650
+ min_len - 1,
2651
+ max_len,
2652
+ nice_len,
2653
+ c->max_search_depth,
2654
+ next_hashes,
2655
+ &offset);
2656
+ length=MIN(length_limit,length);
2657
+ if (length >= min_len &&
2658
+ (length > DEFLATE_MIN_MATCH_LEN ||
2659
+ offset <= 4096)) {
2660
+ /* Match found */
2661
+ deflate_choose_match(c, length, offset, true,
2662
+ &seq);
2663
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2664
+ &in_cur_base,
2665
+ in_next + 1,
2666
+ in_border_end,
2667
+ length - 1,
2668
+ next_hashes);
2669
+ in_next += length;
2670
+ } else {
2671
+ /* No match found */
2672
+ deflate_choose_literal(c, *in_next++, true,
2673
+ seq);
2674
+ }
2675
+
2676
+ /* Check if it's time to output another block. */
2677
+ } while (in_next < in_max_block_end &&
2678
+ seq < &c->p.g.sequences[SEQ_STORE_LENGTH] &&
2679
+ !should_end_block(&c->split_stats,
2680
+ in_block_begin, in_next, in_end));
2681
+
2682
+ deflate_finish_block(c, os, in_block_begin,
2683
+ in_next - in_block_begin,
2684
+ c->p.g.sequences, in_next == in_end);
2685
+ } while (in_next != in_end && !os->overflow);
2686
+ c->next_hashes_for_blocks_continue0=next_hashes[0];
2687
+ c->next_hashes_for_blocks_continue1=next_hashes[1];
2688
+ c->slide_pos_for_blocks_continue=in_end-in_cur_base;
2689
+ }
2690
+
2691
+ static void
2692
+ deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c,
2693
+ const u8 *in_block_with_dict,size_t dict_nbytes, size_t in_nbytes,
2694
+ size_t in_border_nbytes,struct deflate_output_bitstream *os)
2695
+ {
2696
+ const u8 *in_next = in_block_with_dict+dict_nbytes;
2697
+ const u8 *in_end = in_next + in_nbytes;
2698
+ const u8* in_border_end= in_end + in_border_nbytes;
2699
+ const u8 *in_cur_base = in_block_with_dict;
2700
+ size_t dict_nbytes_continue;
2701
+ unsigned max_len = DEFLATE_MAX_MATCH_LEN;
2702
+ unsigned nice_len = MIN(c->nice_match_length, max_len);
2703
+ u32 next_hashes[2];
2704
+
2705
+ if (c->dict_pos_for_blocks_continue == ~(size_t)0){
2706
+ dict_nbytes_continue=0;
2707
+ next_hashes[0]=0;
2708
+ next_hashes[1]=0;
2709
+ hc_matchfinder_init(&c->p.g.hc_mf);
2710
+ }else{
2711
+ dict_nbytes_continue=dict_nbytes - c->dict_pos_for_blocks_continue;
2712
+ next_hashes[0]=c->next_hashes_for_blocks_continue0;
2713
+ next_hashes[1]=c->next_hashes_for_blocks_continue1;
2714
+ ASSERT(c->slide_pos_for_blocks_continue<=MATCHFINDER_WINDOW_SIZE);
2715
+ in_cur_base=in_block_with_dict+dict_nbytes - c->slide_pos_for_blocks_continue;
2716
+ }
2717
+ if (dict_nbytes > dict_nbytes_continue){
2718
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2719
+ &in_cur_base,
2720
+ in_cur_base+dict_nbytes_continue,
2721
+ in_border_end,
2722
+ dict_nbytes-dict_nbytes_continue,
2723
+ next_hashes);
2724
+ }
2725
+
2726
+ do {
2727
+ /* Starting a new DEFLATE block */
2728
+
2729
+ const u8 * const in_block_begin = in_next;
2730
+ const u8 * const in_max_block_end = choose_max_block_end(
2731
+ in_next, in_end, SOFT_MAX_BLOCK_LENGTH);
2732
+ const u8 *next_recalc_min_len =
2733
+ in_next + MIN(in_end - in_next, 10000);
2734
+ struct deflate_sequence *seq = c->p.g.sequences;
2735
+ unsigned min_len;
2736
+
2737
+ init_block_split_stats(&c->split_stats);
2738
+ deflate_begin_sequences(c, seq);
2739
+ min_len = calculate_min_match_len(in_next,
2740
+ in_max_block_end - in_next,
2741
+ c->max_search_depth);
2742
+ do {
2743
+ unsigned cur_len;
2744
+ unsigned cur_offset;
2745
+ unsigned next_len;
2746
+ unsigned next_offset;
2747
+ size_t length_limit = in_end - in_next;
2748
+
2749
+ /*
2750
+ * Recalculate the minimum match length if it hasn't
2751
+ * been done recently.
2752
+ */
2753
+ if (in_next >= next_recalc_min_len) {
2754
+ min_len = recalculate_min_match_len(
2755
+ &c->freqs,
2756
+ c->max_search_depth);
2757
+ next_recalc_min_len +=
2758
+ MIN(in_end - next_recalc_min_len,
2759
+ in_next - in_block_begin);
2760
+ }
2761
+
2762
+ /* Find the longest match at the current position. */
2763
+ adjust_max_and_nice_len(&max_len, &nice_len,
2764
+ in_border_end - in_next);
2765
+ cur_len = hc_matchfinder_longest_match(
2766
+ &c->p.g.hc_mf,
2767
+ &in_cur_base,
2768
+ in_next,
2769
+ min_len - 1,
2770
+ max_len,
2771
+ nice_len,
2772
+ c->max_search_depth,
2773
+ next_hashes,
2774
+ &cur_offset);
2775
+ cur_len=MIN(length_limit,cur_len);
2776
+ if (cur_len < min_len ||
2777
+ (cur_len == DEFLATE_MIN_MATCH_LEN &&
2778
+ cur_offset > 8192)) {
2779
+ /* No match found. Choose a literal. */
2780
+ deflate_choose_literal(c, *in_next++, true,
2781
+ seq);
2782
+ continue;
2783
+ }
2784
+ in_next++;
2785
+
2786
+ have_cur_match:
2787
+ /*
2788
+ * We have a match at the current position.
2789
+ * If it's very long, choose it immediately.
2790
+ */
2791
+ if (cur_len >= nice_len) {
2792
+ deflate_choose_match(c, cur_len, cur_offset,
2793
+ true, &seq);
2794
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2795
+ &in_cur_base,
2796
+ in_next,
2797
+ in_border_end,
2798
+ cur_len - 1,
2799
+ next_hashes);
2800
+ in_next += cur_len - 1;
2801
+ continue;
2802
+ }
2803
+
2804
+ /*
2805
+ * Try to find a better match at the next position.
2806
+ *
2807
+ * Note: since we already have a match at the *current*
2808
+ * position, we use only half the 'max_search_depth'
2809
+ * when checking the *next* position. This is a useful
2810
+ * trade-off because it's more worthwhile to use a
2811
+ * greater search depth on the initial match.
2812
+ *
2813
+ * Note: it's possible to structure the code such that
2814
+ * there's only one call to longest_match(), which
2815
+ * handles both the "find the initial match" and "try to
2816
+ * find a better match" cases. However, it is faster to
2817
+ * have two call sites, with longest_match() inlined at
2818
+ * each.
2819
+ */
2820
+ adjust_max_and_nice_len(&max_len, &nice_len,
2821
+ in_border_end - in_next);
2822
+ length_limit = in_end - in_next;
2823
+ next_len = hc_matchfinder_longest_match(
2824
+ &c->p.g.hc_mf,
2825
+ &in_cur_base,
2826
+ in_next++,
2827
+ cur_len - 1,
2828
+ max_len,
2829
+ nice_len,
2830
+ c->max_search_depth >> 1,
2831
+ next_hashes,
2832
+ &next_offset);
2833
+ next_len=MIN(length_limit,next_len);
2834
+ if (next_len >= cur_len &&
2835
+ 4 * (int)(next_len - cur_len) +
2836
+ ((int)bsr32(cur_offset) -
2837
+ (int)bsr32(next_offset)) > 2) {
2838
+ /*
2839
+ * Found a better match at the next position.
2840
+ * Output a literal. Then the next match
2841
+ * becomes the current match.
2842
+ */
2843
+ deflate_choose_literal(c, *(in_next - 2), true,
2844
+ seq);
2845
+ cur_len = next_len;
2846
+ cur_offset = next_offset;
2847
+ goto have_cur_match;
2848
+ }
2849
+
2850
+ if (c->lazy2) {
2851
+ /* In lazy2 mode, look ahead another position */
2852
+ adjust_max_and_nice_len(&max_len, &nice_len,
2853
+ in_border_end - in_next);
2854
+ length_limit = in_end - in_next;
2855
+ next_len = hc_matchfinder_longest_match(
2856
+ &c->p.g.hc_mf,
2857
+ &in_cur_base,
2858
+ in_next++,
2859
+ cur_len - 1,
2860
+ max_len,
2861
+ nice_len,
2862
+ c->max_search_depth >> 2,
2863
+ next_hashes,
2864
+ &next_offset);
2865
+ next_len=MIN(length_limit,next_len);
2866
+ if (next_len >= cur_len &&
2867
+ 4 * (int)(next_len - cur_len) +
2868
+ ((int)bsr32(cur_offset) -
2869
+ (int)bsr32(next_offset)) > 6) {
2870
+ /*
2871
+ * There's a much better match two
2872
+ * positions ahead, so use two literals.
2873
+ */
2874
+ deflate_choose_literal(
2875
+ c, *(in_next - 3), true, seq);
2876
+ deflate_choose_literal(
2877
+ c, *(in_next - 2), true, seq);
2878
+ cur_len = next_len;
2879
+ cur_offset = next_offset;
2880
+ goto have_cur_match;
2881
+ }
2882
+ /*
2883
+ * No better match at either of the next 2
2884
+ * positions. Output the current match.
2885
+ */
2886
+ deflate_choose_match(c, cur_len, cur_offset,
2887
+ true, &seq);
2888
+ if (cur_len > 3) {
2889
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2890
+ &in_cur_base,
2891
+ in_next,
2892
+ in_border_end,
2893
+ cur_len - 3,
2894
+ next_hashes);
2895
+ in_next += cur_len - 3;
2896
+ }
2897
+ } else { /* !lazy2 */
2898
+ /*
2899
+ * No better match at the next position. Output
2900
+ * the current match.
2901
+ */
2902
+ deflate_choose_match(c, cur_len, cur_offset,
2903
+ true, &seq);
2904
+ hc_matchfinder_skip_bytes(&c->p.g.hc_mf,
2905
+ &in_cur_base,
2906
+ in_next,
2907
+ in_border_end,
2908
+ cur_len - 2,
2909
+ next_hashes);
2910
+ in_next += cur_len - 2;
2911
+ }
2912
+ /* Check if it's time to output another block. */
2913
+ } while (in_next < in_max_block_end &&
2914
+ seq < &c->p.g.sequences[SEQ_STORE_LENGTH] &&
2915
+ !should_end_block(&c->split_stats,
2916
+ in_block_begin, in_next, in_end));
2917
+
2918
+ deflate_finish_block(c, os, in_block_begin,
2919
+ in_next - in_block_begin,
2920
+ c->p.g.sequences, in_next == in_end);
2921
+ } while (in_next != in_end && !os->overflow);
2922
+ c->next_hashes_for_blocks_continue0=next_hashes[0];
2923
+ c->next_hashes_for_blocks_continue1=next_hashes[1];
2924
+ c->slide_pos_for_blocks_continue=in_end-in_cur_base;
2925
+ }
2926
+
2927
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
2928
+
2929
+ /*
2930
+ * Follow the minimum-cost path in the graph of possible match/literal choices
2931
+ * for the current block and compute the frequencies of the Huffman symbols that
2932
+ * would be needed to output those matches and literals.
2933
+ */
2934
+ static void
2935
+ deflate_tally_item_list(struct libdeflate_compressor *c, u32 block_length)
2936
+ {
2937
+ struct deflate_optimum_node *cur_node = &c->p.n.optimum_nodes[0];
2938
+ struct deflate_optimum_node *end_node =
2939
+ &c->p.n.optimum_nodes[block_length];
2940
+
2941
+ do {
2942
+ unsigned length = cur_node->item & OPTIMUM_LEN_MASK;
2943
+ unsigned offset = cur_node->item >> OPTIMUM_OFFSET_SHIFT;
2944
+
2945
+ if (length == 1) {
2946
+ /* Literal */
2947
+ c->freqs.litlen[offset]++;
2948
+ } else {
2949
+ /* Match */
2950
+ c->freqs.litlen[DEFLATE_FIRST_LEN_SYM +
2951
+ deflate_length_slot[length]]++;
2952
+ c->freqs.offset[c->p.n.offset_slot_full[offset]]++;
2953
+ }
2954
+ cur_node += length;
2955
+ } while (cur_node != end_node);
2956
+
2957
+ /* Tally the end-of-block symbol. */
2958
+ c->freqs.litlen[DEFLATE_END_OF_BLOCK]++;
2959
+ }
2960
+
2961
+ static void
2962
+ deflate_choose_all_literals(struct libdeflate_compressor *c,
2963
+ const u8 *block, u32 block_length)
2964
+ {
2965
+ u32 i;
2966
+
2967
+ deflate_reset_symbol_frequencies(c);
2968
+ for (i = 0; i < block_length; i++)
2969
+ c->freqs.litlen[block[i]]++;
2970
+ c->freqs.litlen[DEFLATE_END_OF_BLOCK]++;
2971
+
2972
+ deflate_make_huffman_codes(&c->freqs, &c->codes);
2973
+ }
2974
+
2975
+ /*
2976
+ * Compute the exact cost, in bits, that would be required to output the matches
2977
+ * and literals described by @c->freqs as a dynamic Huffman block. The litlen
2978
+ * and offset codes are assumed to have already been built in @c->codes.
2979
+ */
2980
+ static u32
2981
+ deflate_compute_true_cost(struct libdeflate_compressor *c)
2982
+ {
2983
+ u32 cost = 0;
2984
+ unsigned sym;
2985
+
2986
+ deflate_precompute_huffman_header(c);
2987
+
2988
+ memset(&c->codes.lens.litlen[c->o.precode.num_litlen_syms], 0,
2989
+ DEFLATE_NUM_LITLEN_SYMS - c->o.precode.num_litlen_syms);
2990
+
2991
+ cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens);
2992
+ for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) {
2993
+ cost += c->o.precode.freqs[sym] *
2994
+ (c->o.precode.lens[sym] +
2995
+ deflate_extra_precode_bits[sym]);
2996
+ }
2997
+
2998
+ for (sym = 0; sym < DEFLATE_FIRST_LEN_SYM; sym++)
2999
+ cost += c->freqs.litlen[sym] * c->codes.lens.litlen[sym];
3000
+
3001
+ for (; sym < DEFLATE_FIRST_LEN_SYM +
3002
+ ARRAY_LEN(deflate_extra_length_bits); sym++)
3003
+ cost += c->freqs.litlen[sym] *
3004
+ (c->codes.lens.litlen[sym] +
3005
+ deflate_extra_length_bits[sym - DEFLATE_FIRST_LEN_SYM]);
3006
+
3007
+ for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++)
3008
+ cost += c->freqs.offset[sym] *
3009
+ (c->codes.lens.offset[sym] +
3010
+ deflate_extra_offset_bits[sym]);
3011
+ return cost;
3012
+ }
3013
+
3014
+ /* Set the current cost model from the codeword lengths specified in @lens. */
3015
+ static void
3016
+ deflate_set_costs_from_codes(struct libdeflate_compressor *c,
3017
+ const struct deflate_lens *lens)
3018
+ {
3019
+ unsigned i;
3020
+
3021
+ /* Literals */
3022
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++) {
3023
+ u32 bits = (lens->litlen[i] ?
3024
+ lens->litlen[i] : LITERAL_NOSTAT_BITS);
3025
+
3026
+ c->p.n.costs.literal[i] = bits * BIT_COST;
3027
+ }
3028
+
3029
+ /* Lengths */
3030
+ for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) {
3031
+ unsigned length_slot = deflate_length_slot[i];
3032
+ unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + length_slot;
3033
+ u32 bits = (lens->litlen[litlen_sym] ?
3034
+ lens->litlen[litlen_sym] : LENGTH_NOSTAT_BITS);
3035
+
3036
+ bits += deflate_extra_length_bits[length_slot];
3037
+ c->p.n.costs.length[i] = bits * BIT_COST;
3038
+ }
3039
+
3040
+ /* Offset slots */
3041
+ for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) {
3042
+ u32 bits = (lens->offset[i] ?
3043
+ lens->offset[i] : OFFSET_NOSTAT_BITS);
3044
+
3045
+ bits += deflate_extra_offset_bits[i];
3046
+ c->p.n.costs.offset_slot[i] = bits * BIT_COST;
3047
+ }
3048
+ }
3049
+
3050
+ /*
3051
+ * This lookup table gives the default cost of a literal symbol and of a length
3052
+ * symbol, depending on the characteristics of the input data. It was generated
3053
+ * by scripts/gen_default_litlen_costs.py.
3054
+ *
3055
+ * This table is indexed first by the estimated match probability:
3056
+ *
3057
+ * i=0: data doesn't contain many matches [match_prob=0.25]
3058
+ * i=1: neutral [match_prob=0.50]
3059
+ * i=2: data contains lots of matches [match_prob=0.75]
3060
+ *
3061
+ * This lookup produces a subtable which maps the number of distinct used
3062
+ * literals to the default cost of a literal symbol, i.e.:
3063
+ *
3064
+ * int(-log2((1 - match_prob) / num_used_literals) * BIT_COST)
3065
+ *
3066
+ * ... for num_used_literals in [1, 256] (and 0, which is copied from 1). This
3067
+ * accounts for literals usually getting cheaper as the number of distinct
3068
+ * literals decreases, and as the proportion of literals to matches increases.
3069
+ *
3070
+ * The lookup also produces the cost of a length symbol, which is:
3071
+ *
3072
+ * int(-log2(match_prob/NUM_LEN_SLOTS) * BIT_COST)
3073
+ *
3074
+ * Note: we don't currently assign different costs to different literal symbols,
3075
+ * or to different length symbols, as this is hard to do in a useful way.
3076
+ */
3077
+ static const struct {
3078
+ u8 used_lits_to_lit_cost[257];
3079
+ u8 len_sym_cost;
3080
+ } default_litlen_costs[] = {
3081
+ { /* match_prob = 0.25 */
3082
+ .used_lits_to_lit_cost = {
3083
+ 6, 6, 22, 32, 38, 43, 48, 51,
3084
+ 54, 57, 59, 61, 64, 65, 67, 69,
3085
+ 70, 72, 73, 74, 75, 76, 77, 79,
3086
+ 80, 80, 81, 82, 83, 84, 85, 85,
3087
+ 86, 87, 88, 88, 89, 89, 90, 91,
3088
+ 91, 92, 92, 93, 93, 94, 95, 95,
3089
+ 96, 96, 96, 97, 97, 98, 98, 99,
3090
+ 99, 99, 100, 100, 101, 101, 101, 102,
3091
+ 102, 102, 103, 103, 104, 104, 104, 105,
3092
+ 105, 105, 105, 106, 106, 106, 107, 107,
3093
+ 107, 108, 108, 108, 108, 109, 109, 109,
3094
+ 109, 110, 110, 110, 111, 111, 111, 111,
3095
+ 112, 112, 112, 112, 112, 113, 113, 113,
3096
+ 113, 114, 114, 114, 114, 114, 115, 115,
3097
+ 115, 115, 115, 116, 116, 116, 116, 116,
3098
+ 117, 117, 117, 117, 117, 118, 118, 118,
3099
+ 118, 118, 118, 119, 119, 119, 119, 119,
3100
+ 120, 120, 120, 120, 120, 120, 121, 121,
3101
+ 121, 121, 121, 121, 121, 122, 122, 122,
3102
+ 122, 122, 122, 123, 123, 123, 123, 123,
3103
+ 123, 123, 124, 124, 124, 124, 124, 124,
3104
+ 124, 125, 125, 125, 125, 125, 125, 125,
3105
+ 125, 126, 126, 126, 126, 126, 126, 126,
3106
+ 127, 127, 127, 127, 127, 127, 127, 127,
3107
+ 128, 128, 128, 128, 128, 128, 128, 128,
3108
+ 128, 129, 129, 129, 129, 129, 129, 129,
3109
+ 129, 129, 130, 130, 130, 130, 130, 130,
3110
+ 130, 130, 130, 131, 131, 131, 131, 131,
3111
+ 131, 131, 131, 131, 131, 132, 132, 132,
3112
+ 132, 132, 132, 132, 132, 132, 132, 133,
3113
+ 133, 133, 133, 133, 133, 133, 133, 133,
3114
+ 133, 134, 134, 134, 134, 134, 134, 134,
3115
+ 134,
3116
+ },
3117
+ .len_sym_cost = 109,
3118
+ }, { /* match_prob = 0.5 */
3119
+ .used_lits_to_lit_cost = {
3120
+ 16, 16, 32, 41, 48, 53, 57, 60,
3121
+ 64, 66, 69, 71, 73, 75, 76, 78,
3122
+ 80, 81, 82, 83, 85, 86, 87, 88,
3123
+ 89, 90, 91, 92, 92, 93, 94, 95,
3124
+ 96, 96, 97, 98, 98, 99, 99, 100,
3125
+ 101, 101, 102, 102, 103, 103, 104, 104,
3126
+ 105, 105, 106, 106, 107, 107, 108, 108,
3127
+ 108, 109, 109, 110, 110, 110, 111, 111,
3128
+ 112, 112, 112, 113, 113, 113, 114, 114,
3129
+ 114, 115, 115, 115, 115, 116, 116, 116,
3130
+ 117, 117, 117, 118, 118, 118, 118, 119,
3131
+ 119, 119, 119, 120, 120, 120, 120, 121,
3132
+ 121, 121, 121, 122, 122, 122, 122, 122,
3133
+ 123, 123, 123, 123, 124, 124, 124, 124,
3134
+ 124, 125, 125, 125, 125, 125, 126, 126,
3135
+ 126, 126, 126, 127, 127, 127, 127, 127,
3136
+ 128, 128, 128, 128, 128, 128, 129, 129,
3137
+ 129, 129, 129, 129, 130, 130, 130, 130,
3138
+ 130, 130, 131, 131, 131, 131, 131, 131,
3139
+ 131, 132, 132, 132, 132, 132, 132, 133,
3140
+ 133, 133, 133, 133, 133, 133, 134, 134,
3141
+ 134, 134, 134, 134, 134, 134, 135, 135,
3142
+ 135, 135, 135, 135, 135, 135, 136, 136,
3143
+ 136, 136, 136, 136, 136, 136, 137, 137,
3144
+ 137, 137, 137, 137, 137, 137, 138, 138,
3145
+ 138, 138, 138, 138, 138, 138, 138, 139,
3146
+ 139, 139, 139, 139, 139, 139, 139, 139,
3147
+ 140, 140, 140, 140, 140, 140, 140, 140,
3148
+ 140, 141, 141, 141, 141, 141, 141, 141,
3149
+ 141, 141, 141, 142, 142, 142, 142, 142,
3150
+ 142, 142, 142, 142, 142, 142, 143, 143,
3151
+ 143, 143, 143, 143, 143, 143, 143, 143,
3152
+ 144,
3153
+ },
3154
+ .len_sym_cost = 93,
3155
+ }, { /* match_prob = 0.75 */
3156
+ .used_lits_to_lit_cost = {
3157
+ 32, 32, 48, 57, 64, 69, 73, 76,
3158
+ 80, 82, 85, 87, 89, 91, 92, 94,
3159
+ 96, 97, 98, 99, 101, 102, 103, 104,
3160
+ 105, 106, 107, 108, 108, 109, 110, 111,
3161
+ 112, 112, 113, 114, 114, 115, 115, 116,
3162
+ 117, 117, 118, 118, 119, 119, 120, 120,
3163
+ 121, 121, 122, 122, 123, 123, 124, 124,
3164
+ 124, 125, 125, 126, 126, 126, 127, 127,
3165
+ 128, 128, 128, 129, 129, 129, 130, 130,
3166
+ 130, 131, 131, 131, 131, 132, 132, 132,
3167
+ 133, 133, 133, 134, 134, 134, 134, 135,
3168
+ 135, 135, 135, 136, 136, 136, 136, 137,
3169
+ 137, 137, 137, 138, 138, 138, 138, 138,
3170
+ 139, 139, 139, 139, 140, 140, 140, 140,
3171
+ 140, 141, 141, 141, 141, 141, 142, 142,
3172
+ 142, 142, 142, 143, 143, 143, 143, 143,
3173
+ 144, 144, 144, 144, 144, 144, 145, 145,
3174
+ 145, 145, 145, 145, 146, 146, 146, 146,
3175
+ 146, 146, 147, 147, 147, 147, 147, 147,
3176
+ 147, 148, 148, 148, 148, 148, 148, 149,
3177
+ 149, 149, 149, 149, 149, 149, 150, 150,
3178
+ 150, 150, 150, 150, 150, 150, 151, 151,
3179
+ 151, 151, 151, 151, 151, 151, 152, 152,
3180
+ 152, 152, 152, 152, 152, 152, 153, 153,
3181
+ 153, 153, 153, 153, 153, 153, 154, 154,
3182
+ 154, 154, 154, 154, 154, 154, 154, 155,
3183
+ 155, 155, 155, 155, 155, 155, 155, 155,
3184
+ 156, 156, 156, 156, 156, 156, 156, 156,
3185
+ 156, 157, 157, 157, 157, 157, 157, 157,
3186
+ 157, 157, 157, 158, 158, 158, 158, 158,
3187
+ 158, 158, 158, 158, 158, 158, 159, 159,
3188
+ 159, 159, 159, 159, 159, 159, 159, 159,
3189
+ 160,
3190
+ },
3191
+ .len_sym_cost = 84,
3192
+ },
3193
+ };
3194
+
3195
+ /*
3196
+ * Choose the default costs for literal and length symbols. These symbols are
3197
+ * both part of the litlen alphabet.
3198
+ */
3199
+ static void
3200
+ deflate_choose_default_litlen_costs(struct libdeflate_compressor *c,
3201
+ const u8 *block_begin, u32 block_length,
3202
+ u32 *lit_cost, u32 *len_sym_cost)
3203
+ {
3204
+ unsigned num_used_literals = 0;
3205
+ u32 literal_freq = block_length;
3206
+ u32 match_freq = 0;
3207
+ u32 cutoff;
3208
+ u32 i;
3209
+
3210
+ /* Calculate the number of distinct literals that exist in the data. */
3211
+ memset(c->freqs.litlen, 0,
3212
+ DEFLATE_NUM_LITERALS * sizeof(c->freqs.litlen[0]));
3213
+ cutoff = literal_freq >> 11; /* Ignore literals used very rarely. */
3214
+ for (i = 0; i < block_length; i++)
3215
+ c->freqs.litlen[block_begin[i]]++;
3216
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++) {
3217
+ if (c->freqs.litlen[i] > cutoff)
3218
+ num_used_literals++;
3219
+ }
3220
+ if (num_used_literals == 0)
3221
+ num_used_literals = 1;
3222
+
3223
+ /*
3224
+ * Estimate the relative frequency of literals and matches in the
3225
+ * optimal parsing solution. We don't know the optimal solution, so
3226
+ * this can only be a very rough estimate. Therefore, we basically use
3227
+ * the match frequency from a greedy parse. We also apply the min_len
3228
+ * heuristic used by the greedy and lazy parsers, to avoid counting too
3229
+ * many matches when literals are cheaper than short matches.
3230
+ */
3231
+ match_freq = 0;
3232
+ i = choose_min_match_len(num_used_literals, c->max_search_depth);
3233
+ for (; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) {
3234
+ match_freq += c->p.n.match_len_freqs[i];
3235
+ literal_freq -= i * c->p.n.match_len_freqs[i];
3236
+ }
3237
+ if ((s32)literal_freq < 0) /* shouldn't happen */
3238
+ literal_freq = 0;
3239
+
3240
+ if (match_freq > literal_freq)
3241
+ i = 2; /* many matches */
3242
+ else if (match_freq * 4 > literal_freq)
3243
+ i = 1; /* neutral */
3244
+ else
3245
+ i = 0; /* few matches */
3246
+
3247
+ STATIC_ASSERT(BIT_COST == 16);
3248
+ *lit_cost = default_litlen_costs[i].used_lits_to_lit_cost[
3249
+ num_used_literals];
3250
+ *len_sym_cost = default_litlen_costs[i].len_sym_cost;
3251
+ }
3252
+
3253
+ static forceinline u32
3254
+ deflate_default_length_cost(unsigned len, u32 len_sym_cost)
3255
+ {
3256
+ unsigned slot = deflate_length_slot[len];
3257
+ u32 num_extra_bits = deflate_extra_length_bits[slot];
3258
+
3259
+ return len_sym_cost + (num_extra_bits * BIT_COST);
3260
+ }
3261
+
3262
+ static forceinline u32
3263
+ deflate_default_offset_slot_cost(unsigned slot)
3264
+ {
3265
+ u32 num_extra_bits = deflate_extra_offset_bits[slot];
3266
+ /*
3267
+ * Assume that all offset symbols are equally probable.
3268
+ * The resulting cost is 'int(-log2(1/30) * BIT_COST)',
3269
+ * where 30 is the number of potentially-used offset symbols.
3270
+ */
3271
+ u32 offset_sym_cost = 4*BIT_COST + (907*BIT_COST)/1000;
3272
+
3273
+ return offset_sym_cost + (num_extra_bits * BIT_COST);
3274
+ }
3275
+
3276
+ /* Set default symbol costs for the first block's first optimization pass. */
3277
+ static void
3278
+ deflate_set_default_costs(struct libdeflate_compressor *c,
3279
+ u32 lit_cost, u32 len_sym_cost)
3280
+ {
3281
+ unsigned i;
3282
+
3283
+ /* Literals */
3284
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
3285
+ c->p.n.costs.literal[i] = lit_cost;
3286
+
3287
+ /* Lengths */
3288
+ for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++)
3289
+ c->p.n.costs.length[i] =
3290
+ deflate_default_length_cost(i, len_sym_cost);
3291
+
3292
+ /* Offset slots */
3293
+ for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++)
3294
+ c->p.n.costs.offset_slot[i] =
3295
+ deflate_default_offset_slot_cost(i);
3296
+ }
3297
+
3298
+ static forceinline void
3299
+ deflate_adjust_cost(u32 *cost_p, u32 default_cost, int change_amount)
3300
+ {
3301
+ if (change_amount == 0)
3302
+ /* Block is very similar to previous; prefer previous costs. */
3303
+ *cost_p = (default_cost + 3 * *cost_p) / 4;
3304
+ else if (change_amount == 1)
3305
+ *cost_p = (default_cost + *cost_p) / 2;
3306
+ else if (change_amount == 2)
3307
+ *cost_p = (5 * default_cost + 3 * *cost_p) / 8;
3308
+ else
3309
+ /* Block differs greatly from previous; prefer default costs. */
3310
+ *cost_p = (3 * default_cost + *cost_p) / 4;
3311
+ }
3312
+
3313
+ static forceinline void
3314
+ deflate_adjust_costs_impl(struct libdeflate_compressor *c,
3315
+ u32 lit_cost, u32 len_sym_cost, int change_amount)
3316
+ {
3317
+ unsigned i;
3318
+
3319
+ /* Literals */
3320
+ for (i = 0; i < DEFLATE_NUM_LITERALS; i++)
3321
+ deflate_adjust_cost(&c->p.n.costs.literal[i], lit_cost,
3322
+ change_amount);
3323
+
3324
+ /* Lengths */
3325
+ for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++)
3326
+ deflate_adjust_cost(&c->p.n.costs.length[i],
3327
+ deflate_default_length_cost(i,
3328
+ len_sym_cost),
3329
+ change_amount);
3330
+
3331
+ /* Offset slots */
3332
+ for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++)
3333
+ deflate_adjust_cost(&c->p.n.costs.offset_slot[i],
3334
+ deflate_default_offset_slot_cost(i),
3335
+ change_amount);
3336
+ }
3337
+
3338
+ /*
3339
+ * Adjust the costs when beginning a new block.
3340
+ *
3341
+ * Since the current costs are optimized for the data already, it can be helpful
3342
+ * to reuse them instead of starting over with the default costs. However, this
3343
+ * depends on how similar the new block is to the previous block. Therefore,
3344
+ * use a heuristic to decide how similar the blocks are, and mix together the
3345
+ * current costs and the default costs accordingly.
3346
+ */
3347
+ static void
3348
+ deflate_adjust_costs(struct libdeflate_compressor *c,
3349
+ u32 lit_cost, u32 len_sym_cost)
3350
+ {
3351
+ u64 total_delta = 0;
3352
+ u64 cutoff;
3353
+ int i;
3354
+
3355
+ /*
3356
+ * Decide how different the current block is from the previous block,
3357
+ * using the block splitting statistics from the current and previous
3358
+ * blocks. The more different the current block is, the more we prefer
3359
+ * the default costs rather than the previous block's costs.
3360
+ *
3361
+ * The algorithm here is similar to the end-of-block check one, but here
3362
+ * we compare two entire blocks rather than a partial block with a small
3363
+ * extra part, and therefore we need 64-bit numbers in some places.
3364
+ */
3365
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++) {
3366
+ u64 prev = (u64)c->p.n.prev_observations[i] *
3367
+ c->split_stats.num_observations;
3368
+ u64 cur = (u64)c->split_stats.observations[i] *
3369
+ c->p.n.prev_num_observations;
3370
+
3371
+ total_delta += prev > cur ? prev - cur : cur - prev;
3372
+ }
3373
+ cutoff = ((u64)c->p.n.prev_num_observations *
3374
+ c->split_stats.num_observations * 200) / 512;
3375
+
3376
+ if (total_delta > 3 * cutoff)
3377
+ /* Big change in the data; just use the default costs. */
3378
+ deflate_set_default_costs(c, lit_cost, len_sym_cost);
3379
+ else if (4 * total_delta > 9 * cutoff)
3380
+ deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 3);
3381
+ else if (2 * total_delta > 3 * cutoff)
3382
+ deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 2);
3383
+ else if (2 * total_delta > cutoff)
3384
+ deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 1);
3385
+ else
3386
+ deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 0);
3387
+ }
3388
+
3389
+ static void
3390
+ deflate_set_initial_costs(struct libdeflate_compressor *c,
3391
+ const u8 *block_begin, u32 block_length,
3392
+ bool is_first_block)
3393
+ {
3394
+ u32 lit_cost, len_sym_cost;
3395
+
3396
+ deflate_choose_default_litlen_costs(c, block_begin, block_length,
3397
+ &lit_cost, &len_sym_cost);
3398
+ if (is_first_block)
3399
+ deflate_set_default_costs(c, lit_cost, len_sym_cost);
3400
+ else
3401
+ deflate_adjust_costs(c, lit_cost, len_sym_cost);
3402
+ }
3403
+
3404
+ /*
3405
+ * Find the minimum-cost path through the graph of possible match/literal
3406
+ * choices for this block.
3407
+ *
3408
+ * We find the minimum cost path from 'c->p.n.optimum_nodes[0]', which
3409
+ * represents the node at the beginning of the block, to
3410
+ * 'c->p.n.optimum_nodes[block_length]', which represents the node at the end of
3411
+ * the block. Edge costs are evaluated using the cost model 'c->p.n.costs'.
3412
+ *
3413
+ * The algorithm works backwards, starting at the end node and proceeding
3414
+ * backwards one node at a time. At each node, the minimum cost to reach the
3415
+ * end node is computed and the match/literal choice that begins that path is
3416
+ * saved.
3417
+ */
3418
+ static void
3419
+ deflate_find_min_cost_path(struct libdeflate_compressor *c,
3420
+ const u32 block_length,
3421
+ const struct lz_match *cache_ptr)
3422
+ {
3423
+ struct deflate_optimum_node *end_node =
3424
+ &c->p.n.optimum_nodes[block_length];
3425
+ struct deflate_optimum_node *cur_node = end_node;
3426
+
3427
+ cur_node->cost_to_end = 0;
3428
+ do {
3429
+ unsigned num_matches;
3430
+ unsigned literal;
3431
+ u32 best_cost_to_end;
3432
+
3433
+ cur_node--;
3434
+ cache_ptr--;
3435
+
3436
+ num_matches = cache_ptr->length;
3437
+ literal = cache_ptr->offset;
3438
+
3439
+ /* It's always possible to choose a literal. */
3440
+ best_cost_to_end = c->p.n.costs.literal[literal] +
3441
+ (cur_node + 1)->cost_to_end;
3442
+ cur_node->item = ((u32)literal << OPTIMUM_OFFSET_SHIFT) | 1;
3443
+
3444
+ /* Also consider matches if there are any. */
3445
+ if (num_matches) {
3446
+ const struct lz_match *match;
3447
+ unsigned len;
3448
+ unsigned offset;
3449
+ unsigned offset_slot;
3450
+ u32 offset_cost;
3451
+ u32 cost_to_end;
3452
+
3453
+ /*
3454
+ * Consider each length from the minimum
3455
+ * (DEFLATE_MIN_MATCH_LEN) to the length of the longest
3456
+ * match found at this position. For each length, we
3457
+ * consider only the smallest offset for which that
3458
+ * length is available. Although this is not guaranteed
3459
+ * to be optimal due to the possibility of a larger
3460
+ * offset costing less than a smaller offset to code,
3461
+ * this is a very useful heuristic.
3462
+ */
3463
+ match = cache_ptr - num_matches;
3464
+ len = DEFLATE_MIN_MATCH_LEN;
3465
+ do {
3466
+ offset = match->offset;
3467
+ offset_slot = c->p.n.offset_slot_full[offset];
3468
+ offset_cost =
3469
+ c->p.n.costs.offset_slot[offset_slot];
3470
+ do {
3471
+ cost_to_end = offset_cost +
3472
+ c->p.n.costs.length[len] +
3473
+ (cur_node + len)->cost_to_end;
3474
+ if (cost_to_end < best_cost_to_end) {
3475
+ best_cost_to_end = cost_to_end;
3476
+ cur_node->item = len |
3477
+ ((u32)offset <<
3478
+ OPTIMUM_OFFSET_SHIFT);
3479
+ }
3480
+ } while (++len <= match->length);
3481
+ } while (++match != cache_ptr);
3482
+ cache_ptr -= num_matches;
3483
+ }
3484
+ cur_node->cost_to_end = best_cost_to_end;
3485
+ } while (cur_node != &c->p.n.optimum_nodes[0]);
3486
+
3487
+ deflate_reset_symbol_frequencies(c);
3488
+ deflate_tally_item_list(c, block_length);
3489
+ deflate_make_huffman_codes(&c->freqs, &c->codes);
3490
+ }
3491
+
3492
+ /*
3493
+ * Choose the literals and matches for the current block, then output the block.
3494
+ *
3495
+ * To choose the literal/match sequence, we find the minimum-cost path through
3496
+ * the block's graph of literal/match choices, given a cost model. However, the
3497
+ * true cost of each symbol is unknown until the Huffman codes have been built,
3498
+ * but at the same time the Huffman codes depend on the frequencies of chosen
3499
+ * symbols. Consequently, multiple passes must be used to try to approximate an
3500
+ * optimal solution. The first pass uses default costs, mixed with the costs
3501
+ * from the previous block when it seems appropriate. Later passes use the
3502
+ * Huffman codeword lengths from the previous pass as the costs.
3503
+ *
3504
+ * As an alternate strategy, also consider using only literals. The boolean
3505
+ * returned in *used_only_literals indicates whether that strategy was best.
3506
+ */
3507
+ static void
3508
+ deflate_optimize_and_flush_block(struct libdeflate_compressor *c,
3509
+ struct deflate_output_bitstream *os,
3510
+ const u8 *block_begin, u32 block_length,
3511
+ const struct lz_match *cache_ptr,
3512
+ bool is_first_block, bool is_final_block, bool _is_in_dict,
3513
+ bool *used_only_literals)
3514
+ {
3515
+ unsigned num_passes_remaining =_is_in_dict ? 1: c->p.n.max_optim_passes;
3516
+ u32 best_true_cost = UINT32_MAX;
3517
+ u32 true_cost;
3518
+ u32 only_lits_cost;
3519
+ u32 static_cost = UINT32_MAX;
3520
+ struct deflate_sequence seq_;
3521
+ struct deflate_sequence *seq = NULL;
3522
+ u32 i;
3523
+
3524
+ /*
3525
+ * On some data, using only literals (no matches) ends up being better
3526
+ * than what the iterative optimization algorithm produces. Therefore,
3527
+ * consider using only literals.
3528
+ */
3529
+ deflate_choose_all_literals(c, block_begin, block_length);
3530
+ only_lits_cost = deflate_compute_true_cost(c);
3531
+
3532
+ /*
3533
+ * Force the block to really end at the desired length, even if some
3534
+ * matches extend beyond it.
3535
+ */
3536
+ for (i = block_length;
3537
+ i <= MIN(block_length - 1 + DEFLATE_MAX_MATCH_LEN,
3538
+ ARRAY_LEN(c->p.n.optimum_nodes) - 1); i++)
3539
+ c->p.n.optimum_nodes[i].cost_to_end = 0x80000000;
3540
+
3541
+ /*
3542
+ * Sometimes a static Huffman block ends up being cheapest, particularly
3543
+ * if the block is small. So, if the block is sufficiently small, find
3544
+ * the optimal static block solution and remember its cost.
3545
+ */
3546
+ if (block_length <= c->p.n.max_len_to_optimize_static_block) {
3547
+ /* Save c->p.n.costs temporarily. */
3548
+ c->p.n.costs_saved = c->p.n.costs;
3549
+
3550
+ deflate_set_costs_from_codes(c, &c->static_codes.lens);
3551
+ deflate_find_min_cost_path(c, block_length, cache_ptr);
3552
+ static_cost = c->p.n.optimum_nodes[0].cost_to_end / BIT_COST;
3553
+ static_cost += 7; /* for the end-of-block symbol */
3554
+
3555
+ /* Restore c->p.n.costs. */
3556
+ c->p.n.costs = c->p.n.costs_saved;
3557
+ }
3558
+
3559
+ /* Initialize c->p.n.costs with default costs. */
3560
+ deflate_set_initial_costs(c, block_begin, block_length, is_first_block);
3561
+
3562
+ do {
3563
+ /*
3564
+ * Find the minimum-cost path for this pass.
3565
+ * Also set c->freqs and c->codes to match the path.
3566
+ */
3567
+ deflate_find_min_cost_path(c, block_length, cache_ptr);
3568
+
3569
+ /*
3570
+ * Compute the exact cost of the block if the path were to be
3571
+ * used. Note that this differs from
3572
+ * c->p.n.optimum_nodes[0].cost_to_end in that true_cost uses
3573
+ * the actual Huffman codes instead of c->p.n.costs.
3574
+ */
3575
+ true_cost = deflate_compute_true_cost(c);
3576
+
3577
+ /*
3578
+ * If the cost didn't improve much from the previous pass, then
3579
+ * doing more passes probably won't be helpful, so stop early.
3580
+ */
3581
+ if (true_cost + c->p.n.min_improvement_to_continue >
3582
+ best_true_cost)
3583
+ break;
3584
+
3585
+ best_true_cost = true_cost;
3586
+
3587
+ /* Save the cost model that gave 'best_true_cost'. */
3588
+ c->p.n.costs_saved = c->p.n.costs;
3589
+
3590
+ /* Update the cost model from the Huffman codes. */
3591
+ deflate_set_costs_from_codes(c, &c->codes.lens);
3592
+
3593
+ } while (--num_passes_remaining);
3594
+
3595
+ *used_only_literals = false;
3596
+ if (MIN(only_lits_cost, static_cost) < best_true_cost) {
3597
+ if (only_lits_cost < static_cost) {
3598
+ /* Using only literals ended up being best! */
3599
+ deflate_choose_all_literals(c, block_begin, block_length);
3600
+ deflate_set_costs_from_codes(c, &c->codes.lens);
3601
+ seq_.litrunlen_and_length = block_length;
3602
+ seq = &seq_;
3603
+ *used_only_literals = true;
3604
+ } else {
3605
+ /* Static block ended up being best! */
3606
+ deflate_set_costs_from_codes(c, &c->static_codes.lens);
3607
+ deflate_find_min_cost_path(c, block_length, cache_ptr);
3608
+ }
3609
+ } else if (true_cost >=
3610
+ best_true_cost + c->p.n.min_bits_to_use_nonfinal_path) {
3611
+ /*
3612
+ * The best solution was actually from a non-final optimization
3613
+ * pass, so recover and use the min-cost path from that pass.
3614
+ */
3615
+ c->p.n.costs = c->p.n.costs_saved;
3616
+ deflate_find_min_cost_path(c, block_length, cache_ptr);
3617
+ deflate_set_costs_from_codes(c, &c->codes.lens);
3618
+ }
3619
+ if (!_is_in_dict)
3620
+ deflate_flush_block(c, os, block_begin, block_length, seq, is_final_block);
3621
+ }
3622
+
3623
+ static void
3624
+ deflate_near_optimal_init_stats(struct libdeflate_compressor *c)
3625
+ {
3626
+ init_block_split_stats(&c->split_stats);
3627
+ memset(c->p.n.new_match_len_freqs, 0,
3628
+ sizeof(c->p.n.new_match_len_freqs));
3629
+ memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs));
3630
+ }
3631
+
3632
+ static void
3633
+ deflate_near_optimal_merge_stats(struct libdeflate_compressor *c)
3634
+ {
3635
+ unsigned i;
3636
+
3637
+ merge_new_observations(&c->split_stats);
3638
+ for (i = 0; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) {
3639
+ c->p.n.match_len_freqs[i] += c->p.n.new_match_len_freqs[i];
3640
+ c->p.n.new_match_len_freqs[i] = 0;
3641
+ }
3642
+ }
3643
+
3644
+ /*
3645
+ * Save some literal/match statistics from the previous block so that
3646
+ * deflate_adjust_costs() will be able to decide how much the current block
3647
+ * differs from the previous one.
3648
+ */
3649
+ static void
3650
+ deflate_near_optimal_save_stats(struct libdeflate_compressor *c)
3651
+ {
3652
+ int i;
3653
+
3654
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++)
3655
+ c->p.n.prev_observations[i] = c->split_stats.observations[i];
3656
+ c->p.n.prev_num_observations = c->split_stats.num_observations;
3657
+ }
3658
+
3659
+ static void
3660
+ deflate_near_optimal_clear_old_stats(struct libdeflate_compressor *c)
3661
+ {
3662
+ int i;
3663
+
3664
+ for (i = 0; i < NUM_OBSERVATION_TYPES; i++)
3665
+ c->split_stats.observations[i] = 0;
3666
+ c->split_stats.num_observations = 0;
3667
+ memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs));
3668
+ }
3669
+
3670
+
3671
+
3672
+ #define _DEF_near_optimal_init_dict() { \
3673
+ next_hashes[0]=0; next_hashes[1]=0; \
3674
+ bt_matchfinder_init(&c->p.n.bt_mf); \
3675
+ deflate_near_optimal_init_stats(c); }
3676
+
3677
+ #define _DEF_near_optimal_next_slide() { in_next_slide = in_cur_base + MATCHFINDER_WINDOW_SIZE; }
3678
+ #define _DEF_near_optimal_slide() { \
3679
+ bt_matchfinder_slide_window(&c->p.n.bt_mf); \
3680
+ in_cur_base = in_next; \
3681
+ _DEF_near_optimal_next_slide(); }
3682
+
3683
+ /*
3684
+ * This is the "near-optimal" DEFLATE compressor. It computes the optimal
3685
+ * representation of each DEFLATE block using a minimum-cost path search over
3686
+ * the graph of possible match/literal choices for that block, assuming a
3687
+ * certain cost for each Huffman symbol.
3688
+ *
3689
+ * For several reasons, the end result is not guaranteed to be optimal:
3690
+ *
3691
+ * - Nonoptimal choice of blocks
3692
+ * - Heuristic limitations on which matches are actually considered
3693
+ * - Symbol costs are unknown until the symbols have already been chosen
3694
+ * (so iterative optimization must be used)
3695
+ */
3696
+ static void
3697
+ deflate_compress_near_optimal(struct libdeflate_compressor * restrict c,
3698
+ const u8 *in_block_with_dict,size_t dict_nbytes, size_t in_nbytes,
3699
+ size_t in_border_nbytes,struct deflate_output_bitstream *os)
3700
+ {
3701
+ const u8* in=in_block_with_dict;
3702
+ const u8 *in_next;
3703
+ const u8 *in_block_begin;
3704
+ const u8 *in_end = in_block_with_dict + dict_nbytes + in_nbytes;
3705
+ const u8* in_border_end= in_end + in_border_nbytes;
3706
+ const u8 *in_cur_base=in_block_with_dict;
3707
+ const u8 *in_next_slide;
3708
+ size_t dict_nbytes_continue;
3709
+ unsigned max_len = DEFLATE_MAX_MATCH_LEN;
3710
+ unsigned nice_len = MIN(c->nice_match_length, max_len);
3711
+ struct lz_match *cache_ptr = c->p.n.match_cache;
3712
+ u32 next_hashes[2];
3713
+ bool prev_block_used_only_literals = false;
3714
+
3715
+ if (c->dict_pos_for_blocks_continue == ~(size_t)0){
3716
+ dict_nbytes_continue=0;
3717
+ _DEF_near_optimal_init_dict();
3718
+ }else{
3719
+ dict_nbytes_continue=dict_nbytes - c->dict_pos_for_blocks_continue;
3720
+ next_hashes[0]=c->next_hashes_for_blocks_continue0;
3721
+ next_hashes[1]=c->next_hashes_for_blocks_continue1;
3722
+ ASSERT(c->slide_pos_for_blocks_continue<=MATCHFINDER_WINDOW_SIZE);
3723
+ in_cur_base=in_block_with_dict+dict_nbytes - c->slide_pos_for_blocks_continue;
3724
+ }
3725
+ in_next=in_block_with_dict+dict_nbytes_continue;
3726
+ _DEF_near_optimal_next_slide();
3727
+
3728
+ if (dict_nbytes>dict_nbytes_continue){
3729
+ ASSERT(dict_nbytes-dict_nbytes_continue<=MATCHFINDER_WINDOW_SIZE);
3730
+ const u8 * const in_max_block_end = in_next + dict_nbytes-dict_nbytes_continue;
3731
+ for (;;) {
3732
+ if (in_next == in_next_slide)
3733
+ _DEF_near_optimal_slide();
3734
+
3735
+ adjust_max_and_nice_len(&max_len, &nice_len, in_border_end - in_next);
3736
+ bt_matchfinder_skip_byte(
3737
+ &c->p.n.bt_mf,
3738
+ in_cur_base,
3739
+ in_next - in_cur_base,
3740
+ nice_len,
3741
+ c->max_search_depth,
3742
+ next_hashes);
3743
+ in_next++;
3744
+
3745
+ if (in_next >= in_max_block_end)
3746
+ break;
3747
+ }
3748
+ }
3749
+ in_block_begin = in_next;
3750
+
3751
+ do {
3752
+ /* Starting a new DEFLATE block */
3753
+ const u8 * const in_max_block_end = choose_max_block_end(
3754
+ in_block_begin, in_end, SOFT_MAX_BLOCK_LENGTH);
3755
+ const u8 *prev_end_block_check = NULL;
3756
+ bool change_detected = false;
3757
+ const u8 *next_observation = in_next;
3758
+ unsigned min_len;
3759
+
3760
+ /*
3761
+ * Use the minimum match length heuristic to improve the
3762
+ * literal/match statistics gathered during matchfinding.
3763
+ * However, the actual near-optimal parse won't respect min_len,
3764
+ * as it can accurately assess the costs of different matches.
3765
+ *
3766
+ * If the "use only literals" strategy happened to be the best
3767
+ * strategy on the previous block, then probably the
3768
+ * min_match_len heuristic is still not aggressive enough for
3769
+ * the data, so force gathering literal stats only.
3770
+ */
3771
+ if (prev_block_used_only_literals)
3772
+ min_len = DEFLATE_MAX_MATCH_LEN + 1;
3773
+ else
3774
+ min_len = calculate_min_match_len(
3775
+ in_block_begin,
3776
+ in_max_block_end - in_block_begin,
3777
+ c->max_search_depth);
3778
+
3779
+ /*
3780
+ * Find matches until we decide to end the block. We end the
3781
+ * block if any of the following is true:
3782
+ *
3783
+ * (1) Maximum block length has been reached
3784
+ * (2) Match catch may overflow.
3785
+ * (3) Block split heuristic says to split now.
3786
+ */
3787
+ for (;;) {
3788
+ struct lz_match *matches;
3789
+ unsigned best_len;
3790
+
3791
+ /* Slide the window forward if needed. */
3792
+ if (in_next == in_next_slide)
3793
+ _DEF_near_optimal_slide();
3794
+
3795
+ /*
3796
+ * Find matches with the current position using the
3797
+ * binary tree matchfinder and save them in match_cache.
3798
+ *
3799
+ * Note: the binary tree matchfinder is more suited for
3800
+ * optimal parsing than the hash chain matchfinder. The
3801
+ * reasons for this include:
3802
+ *
3803
+ * - The binary tree matchfinder can find more matches
3804
+ * in the same number of steps.
3805
+ * - One of the major advantages of hash chains is that
3806
+ * skipping positions (not searching for matches at
3807
+ * them) is faster; however, with optimal parsing we
3808
+ * search for matches at almost all positions, so this
3809
+ * advantage of hash chains is negated.
3810
+ */
3811
+ matches = cache_ptr;
3812
+ best_len = 0;
3813
+ adjust_max_and_nice_len(&max_len, &nice_len, in_border_end - in_next);
3814
+ if (likely(max_len >= BT_MATCHFINDER_REQUIRED_NBYTES)) {
3815
+ cache_ptr = bt_matchfinder_get_matches(
3816
+ &c->p.n.bt_mf,
3817
+ in_cur_base,
3818
+ in_next - in_cur_base,
3819
+ max_len,
3820
+ nice_len,
3821
+ c->max_search_depth,
3822
+ next_hashes,
3823
+ matches);
3824
+ if (cache_ptr > matches){
3825
+ const size_t length_limit = in_end - in_next;
3826
+ best_len=MIN(cache_ptr[-1].length,length_limit);
3827
+ }
3828
+ }
3829
+ if (in_next >= next_observation) {
3830
+ if (best_len >= min_len) {
3831
+ observe_match(&c->split_stats,
3832
+ best_len);
3833
+ next_observation = in_next + best_len;
3834
+ c->p.n.new_match_len_freqs[best_len]++;
3835
+ } else {
3836
+ observe_literal(&c->split_stats,
3837
+ *in_next);
3838
+ next_observation = in_next + 1;
3839
+ }
3840
+ }
3841
+
3842
+ cache_ptr->length = cache_ptr - matches;
3843
+ cache_ptr->offset = *in_next;
3844
+ in_next++;
3845
+ cache_ptr++;
3846
+
3847
+ /*
3848
+ * If there was a very long match found, don't cache any
3849
+ * matches for the bytes covered by that match. This
3850
+ * avoids degenerate behavior when compressing highly
3851
+ * redundant data, where the number of matches can be
3852
+ * very large.
3853
+ *
3854
+ * This heuristic doesn't actually hurt the compression
3855
+ * ratio very much. If there's a long match, then the
3856
+ * data must be highly compressible, so it doesn't
3857
+ * matter much what we do.
3858
+ */
3859
+ if (best_len >= DEFLATE_MIN_MATCH_LEN &&
3860
+ best_len >= nice_len) {
3861
+ --best_len;
3862
+ do {
3863
+ if (in_next == in_next_slide)
3864
+ _DEF_near_optimal_slide();
3865
+ adjust_max_and_nice_len(&max_len,
3866
+ &nice_len,
3867
+ in_border_end - in_next);
3868
+ if (max_len >=
3869
+ BT_MATCHFINDER_REQUIRED_NBYTES) {
3870
+ bt_matchfinder_skip_byte(
3871
+ &c->p.n.bt_mf,
3872
+ in_cur_base,
3873
+ in_next - in_cur_base,
3874
+ nice_len,
3875
+ c->max_search_depth,
3876
+ next_hashes);
3877
+ }
3878
+ cache_ptr->length = 0;
3879
+ cache_ptr->offset = *in_next;
3880
+ in_next++;
3881
+ cache_ptr++;
3882
+ } while (--best_len);
3883
+ }
3884
+ /* Maximum block length or end of input reached? */
3885
+ if (in_next >= in_max_block_end)
3886
+ break;
3887
+ /* Match cache overflowed? */
3888
+ if (cache_ptr >=
3889
+ &c->p.n.match_cache[MATCH_CACHE_LENGTH])
3890
+ break;
3891
+ /* Not ready to try to end the block (again)? */
3892
+ if (!ready_to_check_block(&c->split_stats,
3893
+ in_block_begin, in_next,
3894
+ in_end))
3895
+ continue;
3896
+ /* Check if it would be worthwhile to end the block. */
3897
+ if (do_end_block_check(&c->split_stats,
3898
+ in_next - in_block_begin)) {
3899
+ change_detected = true;
3900
+ break;
3901
+ }
3902
+ /* Ending the block doesn't seem worthwhile here. */
3903
+ deflate_near_optimal_merge_stats(c);
3904
+ prev_end_block_check = in_next;
3905
+ }
3906
+ /*
3907
+ * All the matches for this block have been cached. Now choose
3908
+ * the precise end of the block and the sequence of items to
3909
+ * output to represent it, then flush the block.
3910
+ */
3911
+ if (change_detected && prev_end_block_check != NULL) {
3912
+ /*
3913
+ * The block is being ended because a recent chunk of
3914
+ * data differs from the rest of the block. We could
3915
+ * end the block at 'in_next' like the greedy and lazy
3916
+ * compressors do, but that's not ideal since it would
3917
+ * include the differing chunk in the block. The
3918
+ * near-optimal compressor has time to do a better job.
3919
+ * Therefore, we rewind to just before the chunk, and
3920
+ * output a block that only goes up to there.
3921
+ *
3922
+ * We then set things up to correctly start the next
3923
+ * block, considering that some work has already been
3924
+ * done on it (some matches found and stats gathered).
3925
+ */
3926
+ struct lz_match *orig_cache_ptr = cache_ptr;
3927
+ const u8 *in_block_end = prev_end_block_check;
3928
+ u32 block_length = in_block_end - in_block_begin;
3929
+ bool is_first = (in_block_begin == in);
3930
+ bool is_final = false;
3931
+ u32 num_bytes_to_rewind = in_next - in_block_end;
3932
+ size_t cache_len_rewound;
3933
+
3934
+ /* Rewind the match cache. */
3935
+ do {
3936
+ cache_ptr--;
3937
+ cache_ptr -= cache_ptr->length;
3938
+ } while (--num_bytes_to_rewind);
3939
+ cache_len_rewound = orig_cache_ptr - cache_ptr;
3940
+
3941
+ deflate_optimize_and_flush_block(
3942
+ c, os, in_block_begin,
3943
+ block_length, cache_ptr,
3944
+ is_first, is_final, false,
3945
+ &prev_block_used_only_literals);
3946
+ memmove(c->p.n.match_cache, cache_ptr,
3947
+ cache_len_rewound * sizeof(*cache_ptr));
3948
+ cache_ptr = &c->p.n.match_cache[cache_len_rewound];
3949
+ deflate_near_optimal_save_stats(c);
3950
+ /*
3951
+ * Clear the stats for the just-flushed block, leaving
3952
+ * just the stats for the beginning of the next block.
3953
+ */
3954
+ deflate_near_optimal_clear_old_stats(c);
3955
+ in_block_begin = in_block_end;
3956
+ } else {
3957
+ /*
3958
+ * The block is being ended for a reason other than a
3959
+ * differing data chunk being detected. Don't rewind at
3960
+ * all; just end the block at the current position.
3961
+ */
3962
+ u32 block_length = in_next - in_block_begin;
3963
+ bool is_first = (in_block_begin == in);
3964
+ bool is_final = (in_next == in_end);
3965
+
3966
+ deflate_near_optimal_merge_stats(c);
3967
+ deflate_optimize_and_flush_block(
3968
+ c, os, in_block_begin,
3969
+ block_length, cache_ptr,
3970
+ is_first, is_final, false,
3971
+ &prev_block_used_only_literals);
3972
+ cache_ptr = &c->p.n.match_cache[0];
3973
+ deflate_near_optimal_save_stats(c);
3974
+ deflate_near_optimal_init_stats(c);
3975
+ in_block_begin = in_next;
3976
+ }
3977
+ } while (in_next != in_end && !os->overflow);
3978
+ c->next_hashes_for_blocks_continue0=next_hashes[0];
3979
+ c->next_hashes_for_blocks_continue1=next_hashes[1];
3980
+ c->slide_pos_for_blocks_continue=in_end-in_cur_base;
3981
+ }
3982
+
3983
+ /* Initialize c->p.n.offset_slot_full. */
3984
+ static void
3985
+ deflate_init_offset_slot_full(struct libdeflate_compressor *c)
3986
+ {
3987
+ unsigned offset_slot;
3988
+ unsigned offset;
3989
+ unsigned offset_end;
3990
+
3991
+ for (offset_slot = 0; offset_slot < ARRAY_LEN(deflate_offset_slot_base);
3992
+ offset_slot++) {
3993
+ offset = deflate_offset_slot_base[offset_slot];
3994
+ offset_end = offset +
3995
+ (1 << deflate_extra_offset_bits[offset_slot]);
3996
+ do {
3997
+ c->p.n.offset_slot_full[offset] = offset_slot;
3998
+ } while (++offset != offset_end);
3999
+ }
4000
+ }
4001
+
4002
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
4003
+
4004
+ LIBDEFLATEAPI struct libdeflate_compressor *
4005
+ libdeflate_alloc_compressor_ex(int compression_level,
4006
+ const struct libdeflate_options *options)
4007
+ {
4008
+ struct libdeflate_compressor *c;
4009
+ size_t size = offsetof(struct libdeflate_compressor, p);
4010
+
4011
+ check_buildtime_parameters();
4012
+
4013
+ /*
4014
+ * Note: if more fields are added to libdeflate_options, this code will
4015
+ * need to be updated to support both the old and new structs.
4016
+ */
4017
+ if (options->sizeof_options != sizeof(*options))
4018
+ return NULL;
4019
+
4020
+ if (compression_level < 0 || compression_level > 12)
4021
+ return NULL;
4022
+
4023
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
4024
+ if (compression_level >= 10)
4025
+ size += sizeof(c->p.n);
4026
+ else
4027
+ #endif
4028
+ {
4029
+ if (compression_level >= 2)
4030
+ size += sizeof(c->p.g);
4031
+ else if (compression_level == 1)
4032
+ size += sizeof(c->p.f);
4033
+ }
4034
+
4035
+ c = libdeflate_aligned_malloc(options->malloc_func ?
4036
+ options->malloc_func :
4037
+ libdeflate_default_malloc_func,
4038
+ MATCHFINDER_MEM_ALIGNMENT, size);
4039
+ if (!c)
4040
+ return NULL;
4041
+ c->free_func = options->free_func ?
4042
+ options->free_func : libdeflate_default_free_func;
4043
+
4044
+ c->compression_level = compression_level;
4045
+ c->in_is_final_block = false;
4046
+ _compress_block_reset(c);
4047
+
4048
+ /*
4049
+ * The higher the compression level, the more we should bother trying to
4050
+ * compress very small inputs.
4051
+ */
4052
+ c->max_passthrough_size = 55 - (compression_level * 4);
4053
+
4054
+ switch (compression_level) {
4055
+ case 0:
4056
+ c->max_passthrough_size = SIZE_MAX;
4057
+ c->impl = NULL; /* not used */
4058
+ break;
4059
+ case 1:
4060
+ c->impl = deflate_compress_fastest;
4061
+ /* max_search_depth is unused. */
4062
+ c->nice_match_length = 32;
4063
+ break;
4064
+ case 2:
4065
+ c->impl = deflate_compress_greedy;
4066
+ c->max_search_depth = 6;
4067
+ c->nice_match_length = 10;
4068
+ break;
4069
+ case 3:
4070
+ c->impl = deflate_compress_greedy;
4071
+ c->max_search_depth = 12;
4072
+ c->nice_match_length = 14;
4073
+ break;
4074
+ case 4:
4075
+ c->impl = deflate_compress_greedy;
4076
+ c->max_search_depth = 16;
4077
+ c->nice_match_length = 30;
4078
+ break;
4079
+ case 5:
4080
+ c->impl = deflate_compress_lazy_generic;
4081
+ c->lazy2 = false;
4082
+ c->max_search_depth = 16;
4083
+ c->nice_match_length = 30;
4084
+ break;
4085
+ case 6:
4086
+ c->impl = deflate_compress_lazy_generic;
4087
+ c->lazy2 = false;
4088
+ c->max_search_depth = 35;
4089
+ c->nice_match_length = 65;
4090
+ break;
4091
+ case 7:
4092
+ c->impl = deflate_compress_lazy_generic;
4093
+ c->lazy2 = false;
4094
+ c->max_search_depth = 100;
4095
+ c->nice_match_length = 130;
4096
+ break;
4097
+ case 8:
4098
+ c->impl = deflate_compress_lazy_generic;
4099
+ c->lazy2 = true;
4100
+ c->max_search_depth = 300;
4101
+ c->nice_match_length = DEFLATE_MAX_MATCH_LEN;
4102
+ break;
4103
+ case 9:
4104
+ #if !SUPPORT_NEAR_OPTIMAL_PARSING
4105
+ default:
4106
+ #endif
4107
+ c->impl = deflate_compress_lazy_generic;
4108
+ c->lazy2 = true;
4109
+ c->max_search_depth = 600;
4110
+ c->nice_match_length = DEFLATE_MAX_MATCH_LEN;
4111
+ break;
4112
+ #if SUPPORT_NEAR_OPTIMAL_PARSING
4113
+ case 10:
4114
+ c->impl = deflate_compress_near_optimal;
4115
+ c->max_search_depth = 35;
4116
+ c->nice_match_length = 75;
4117
+ c->p.n.max_optim_passes = 2;
4118
+ c->p.n.min_improvement_to_continue = 32;
4119
+ c->p.n.min_bits_to_use_nonfinal_path = 32;
4120
+ c->p.n.max_len_to_optimize_static_block = 0;
4121
+ deflate_init_offset_slot_full(c);
4122
+ break;
4123
+ case 11:
4124
+ c->impl = deflate_compress_near_optimal;
4125
+ c->max_search_depth = 100;
4126
+ c->nice_match_length = 150;
4127
+ c->p.n.max_optim_passes = 4;
4128
+ c->p.n.min_improvement_to_continue = 16;
4129
+ c->p.n.min_bits_to_use_nonfinal_path = 16;
4130
+ c->p.n.max_len_to_optimize_static_block = 1000;
4131
+ deflate_init_offset_slot_full(c);
4132
+ break;
4133
+ case 12:
4134
+ default:
4135
+ c->impl = deflate_compress_near_optimal;
4136
+ c->max_search_depth = 300;
4137
+ c->nice_match_length = DEFLATE_MAX_MATCH_LEN;
4138
+ c->p.n.max_optim_passes = 10;
4139
+ c->p.n.min_improvement_to_continue = 1;
4140
+ c->p.n.min_bits_to_use_nonfinal_path = 1;
4141
+ c->p.n.max_len_to_optimize_static_block = 10000;
4142
+ deflate_init_offset_slot_full(c);
4143
+ break;
4144
+ #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
4145
+ }
4146
+
4147
+ deflate_init_static_codes(c);
4148
+
4149
+ return c;
4150
+ }
4151
+
4152
+
4153
+ LIBDEFLATEAPI struct libdeflate_compressor *
4154
+ libdeflate_alloc_compressor(int compression_level)
4155
+ {
4156
+ static const struct libdeflate_options defaults = {
4157
+ .sizeof_options = sizeof(defaults),
4158
+ };
4159
+ return libdeflate_alloc_compressor_ex(compression_level, &defaults);
4160
+ }
4161
+
4162
+ LIBDEFLATEAPI size_t
4163
+ libdeflate_deflate_compress(struct libdeflate_compressor *c,
4164
+ const void *in, size_t in_nbytes,
4165
+ void *out, size_t out_nbytes_avail)
4166
+ {
4167
+ _compress_block_reset(c);
4168
+ return libdeflate_deflate_compress_block_continue(c,in,0,in_nbytes,0,true,out,out_nbytes_avail,false);
4169
+ }
4170
+
4171
+
4172
+ static size_t _deflate_flush_to_byte_align(u8* out,size_t out_nbytes_avail,bitbuf_t bitbuf,unsigned bitcount){
4173
+ ASSERT(out<(out+out_nbytes_avail));
4174
+ ASSERT((bitcount>=1)&&(bitcount<=7));
4175
+ STATIC_ASSERT(WORDBITS >= 32);
4176
+ switch (bitcount) {
4177
+ case 1: case 3: case 5: case 7:{
4178
+ return deflate_compress_none(0,0,out,out_nbytes_avail,bitbuf,bitcount,0);
4179
+ } break;
4180
+ case 2:{ // 2,4,6 add static empty blocks
4181
+ if (unlikely(out_nbytes_avail<4)) return 0;
4182
+ bitbuf |= ((2<<20)|(2<<10)|2) <<2;
4183
+ put_unaligned_le32((u32)bitbuf,out);
4184
+ return 4;
4185
+ } break;
4186
+ case 4:{
4187
+ if (unlikely(out_nbytes_avail<3)) return 0;
4188
+ bitbuf |= ((2<<10)|2) <<4;
4189
+ put_unaligned_le16((u16)bitbuf,out);
4190
+ out[2]=(u8)(bitbuf>>16);
4191
+ return 3;
4192
+ } break;
4193
+ case 6:{
4194
+ if (unlikely(out_nbytes_avail<2)) return 0;
4195
+ bitbuf |= 2 <<6;
4196
+ put_unaligned_le16((u16)bitbuf,out);
4197
+ return 2;
4198
+ } break;
4199
+ default:
4200
+ return 0;
4201
+ }
4202
+ }
4203
+
4204
+
4205
+
4206
+ LIBDEFLATEAPI uint16_t libdeflate_deflate_compress_get_state(struct libdeflate_compressor *c){
4207
+ ASSERT(c->bitcount_back_for_block<=7);
4208
+ ASSERT(c->bitbuf_back_for_block==(uint16_t)(c->bitbuf_back_for_block<<3>>3));
4209
+ return (c->bitbuf_back_for_block<<3) | c->bitcount_back_for_block;
4210
+ }
4211
+
4212
+ LIBDEFLATEAPI void libdeflate_deflate_compress_set_state(struct libdeflate_compressor *c,uint16_t state){
4213
+ c->bitcount_back_for_block=state&7;
4214
+ c->bitbuf_back_for_block=state>>3;
4215
+ }
4216
+
4217
+ LIBDEFLATEAPI size_t
4218
+ libdeflate_deflate_compress_block_uncompressed(struct libdeflate_compressor *c,
4219
+ const void *in_block,size_t in_nbytes,int in_is_final_block,
4220
+ void *out, size_t out_nbytes_avail){
4221
+ struct deflate_output_bitstream os;
4222
+ c->in_is_final_block=in_is_final_block?1:0;
4223
+ os.bitbuf = c->bitbuf_back_for_block;
4224
+ os.bitcount = c->bitcount_back_for_block;
4225
+ _compress_block_reset(c);
4226
+ return deflate_compress_none(in_block,in_nbytes,out,out_nbytes_avail,os.bitbuf,os.bitcount,c->in_is_final_block);
4227
+ }
4228
+
4229
+ LIBDEFLATEAPI size_t
4230
+ libdeflate_deflate_compress_block(struct libdeflate_compressor *c,
4231
+ const void *in_block_with_dict,size_t dict_nbytes,size_t in_nbytes,int in_is_final_block,
4232
+ void *out, size_t out_nbytes_avail,int out_is_flush_to_byte_align)
4233
+ {
4234
+ c->dict_pos_for_blocks_continue=~(size_t)0;
4235
+ return libdeflate_deflate_compress_block_continue(c,in_block_with_dict,dict_nbytes,in_nbytes,0,in_is_final_block,
4236
+ out,out_nbytes_avail,out_is_flush_to_byte_align);
4237
+ }
4238
+
4239
+ LIBDEFLATEAPI void
4240
+ libdeflate_deflate_compress_block_reset(struct libdeflate_compressor *c){
4241
+ _compress_block_reset(c);
4242
+ }
4243
+
4244
+ LIBDEFLATEAPI size_t
4245
+ libdeflate_deflate_compress_block_continue(struct libdeflate_compressor *c,
4246
+ const void *in_block_with_dict,size_t dict_nbytes,size_t in_nbytes,
4247
+ size_t in_border_nbytes,int in_is_final_block,
4248
+ void *out, size_t out_nbytes_avail,int out_is_flush_to_byte_align){
4249
+ struct deflate_output_bitstream os;
4250
+ c->in_is_final_block=in_is_final_block?1:0;
4251
+ os.bitbuf = c->bitbuf_back_for_block;
4252
+ os.bitcount = c->bitcount_back_for_block;
4253
+ c->bitbuf_back_for_block=0;
4254
+ c->bitcount_back_for_block=0;
4255
+
4256
+ /*
4257
+ * For extremely short inputs, or for compression level 0, just output
4258
+ * uncompressed blocks.
4259
+ */
4260
+ if (unlikely(in_nbytes <= c->max_passthrough_size)){
4261
+ const u8* in=((const u8*)in_block_with_dict)+dict_nbytes;
4262
+ c->dict_pos_for_blocks_continue=(c->dict_pos_for_blocks_continue==~(size_t)0)?
4263
+ (~(size_t)0) : (c->dict_pos_for_blocks_continue+in_nbytes);
4264
+ c->slide_pos_for_blocks_continue+=in_nbytes;
4265
+ c->dict_pos_for_blocks_continue=(c->slide_pos_for_blocks_continue>MATCHFINDER_WINDOW_SIZE)?
4266
+ (~(size_t)0) : (c->dict_pos_for_blocks_continue);
4267
+ return deflate_compress_none(in,in_nbytes,out,out_nbytes_avail,os.bitbuf,os.bitcount,c->in_is_final_block);
4268
+ }
4269
+
4270
+ if (dict_nbytes>MATCHFINDER_WINDOW_SIZE){
4271
+ in_block_with_dict=(const u8*)in_block_with_dict+dict_nbytes-MATCHFINDER_WINDOW_SIZE;
4272
+ dict_nbytes=MATCHFINDER_WINDOW_SIZE;
4273
+ }
4274
+
4275
+ /* Initialize the output bitstream structure. */
4276
+ os.next = out;
4277
+ os.end = os.next + out_nbytes_avail;
4278
+ os.overflow = false;
4279
+
4280
+ /* Call the actual compression function. */
4281
+ (*c->impl)(c,in_block_with_dict,dict_nbytes,in_nbytes,in_border_nbytes,&os);
4282
+ c->dict_pos_for_blocks_continue=0;
4283
+
4284
+ /* Return 0 if the output buffer is too small. */
4285
+ if (os.overflow)
4286
+ return 0;
4287
+
4288
+ /*
4289
+ * Write the final byte if needed. This can't overflow the output
4290
+ * buffer because deflate_flush_block() would have set the overflow flag
4291
+ * if there wasn't enough space remaining for the full final block.
4292
+ */
4293
+ ASSERT(os.bitcount <= 7);
4294
+ if (os.bitcount) {
4295
+ if (in_is_final_block){
4296
+ ASSERT(os.next < os.end);
4297
+ *os.next++ = os.bitbuf;
4298
+ }else if (out_is_flush_to_byte_align){
4299
+ size_t fbytes=_deflate_flush_to_byte_align(os.next,os.end-os.next,os.bitbuf,os.bitcount);
4300
+ if (unlikely(fbytes==0)) return 0;
4301
+ os.next+=fbytes;
4302
+ }else{ //backup for next block
4303
+ c->bitbuf_back_for_block=os.bitbuf;
4304
+ c->bitcount_back_for_block=os.bitcount;
4305
+ }
4306
+ }
4307
+
4308
+ /* Return the compressed size in bytes. */
4309
+ return os.next - (u8 *)out;
4310
+ }
4311
+
4312
+ LIBDEFLATEAPI void
4313
+ libdeflate_free_compressor(struct libdeflate_compressor *c)
4314
+ {
4315
+ if (c)
4316
+ libdeflate_aligned_free(c->free_func, c);
4317
+ }
4318
+
4319
+ unsigned int
4320
+ libdeflate_get_compression_level(struct libdeflate_compressor *c)
4321
+ {
4322
+ return c->compression_level;
4323
+ }
4324
+
4325
+ LIBDEFLATEAPI size_t
4326
+ libdeflate_deflate_compress_bound(struct libdeflate_compressor *c,
4327
+ size_t in_nbytes)
4328
+ {
4329
+ size_t max_blocks;
4330
+
4331
+ /*
4332
+ * Since the compressor never uses a compressed block when an
4333
+ * uncompressed block is cheaper, the worst case can be no worse than
4334
+ * the case where only uncompressed blocks are used.
4335
+ *
4336
+ * This is true even though up to 7 bits are "wasted" to byte-align the
4337
+ * bitstream when a compressed block is followed by an uncompressed
4338
+ * block. This is because a compressed block wouldn't have been used if
4339
+ * it wasn't cheaper than an uncompressed block, and uncompressed blocks
4340
+ * always end on a byte boundary. So the alignment bits will, at worst,
4341
+ * go up to the place where the uncompressed block would have ended.
4342
+ */
4343
+
4344
+ /*
4345
+ * Calculate the maximum number of uncompressed blocks that the
4346
+ * compressor can use for 'in_nbytes' of data.
4347
+ *
4348
+ * The minimum length that is passed to deflate_flush_block() is
4349
+ * MIN_BLOCK_LENGTH bytes, except for the final block if needed. If
4350
+ * deflate_flush_block() decides to use an uncompressed block, it
4351
+ * actually will (in general) output a series of uncompressed blocks in
4352
+ * order to stay within the UINT16_MAX limit of DEFLATE. But this can
4353
+ * be disregarded here as long as '2 * MIN_BLOCK_LENGTH <= UINT16_MAX',
4354
+ * as in that case this behavior can't result in more blocks than the
4355
+ * case where deflate_flush_block() is called with min-length inputs.
4356
+ *
4357
+ * So the number of uncompressed blocks needed would be bounded by
4358
+ * DIV_ROUND_UP(in_nbytes, MIN_BLOCK_LENGTH). However, empty inputs
4359
+ * need 1 (empty) block, which gives the final expression below.
4360
+ */
4361
+ STATIC_ASSERT(2 * MIN_BLOCK_LENGTH <= UINT16_MAX);
4362
+ max_blocks = MAX(DIV_ROUND_UP(in_nbytes, MIN_BLOCK_LENGTH), 1);
4363
+
4364
+ /*
4365
+ * Each uncompressed block has 5 bytes of overhead, for the BFINAL,
4366
+ * BTYPE, LEN, and NLEN fields. (For the reason explained earlier, the
4367
+ * alignment bits at the very start of the block can be disregarded;
4368
+ * they would otherwise increase the overhead to 6 bytes per block.)
4369
+ * Therefore, the maximum number of overhead bytes is '5 * max_blocks'.
4370
+ * To get the final bound, add the number of uncompressed bytes.
4371
+ */
4372
+ return (5 * max_blocks) + in_nbytes;
4373
+ }
4374
+
4375
+
4376
+ static forceinline size_t
4377
+ _compress_bound_block(size_t _one_block){
4378
+ return libdeflate_deflate_compress_bound(NULL,_one_block)+5;
4379
+ }
4380
+
4381
+ LIBDEFLATEAPI size_t
4382
+ libdeflate_deflate_compress_bound_block(size_t in_block_nbytes){
4383
+ return _compress_bound_block(in_block_nbytes);
4384
+ }
4385
+
4386
+ LIBDEFLATEAPI uint64_t
4387
+ libdeflate_deflate_compress_bound_blocks(uint64_t in_stream_nbytes,size_t in_block_nbytes){
4388
+ uint64_t min_blocks;
4389
+ size_t last_block_nbytes;
4390
+ ASSERT(in_block_nbytes>0);
4391
+ min_blocks=in_stream_nbytes/in_block_nbytes;
4392
+ last_block_nbytes=in_stream_nbytes-in_block_nbytes*min_blocks;
4393
+ return _compress_bound_block(in_block_nbytes)*min_blocks+_compress_bound_block(last_block_nbytes);
4394
+ }