extzstd 0.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/README.md +38 -56
  4. data/contrib/zstd/CHANGELOG +613 -0
  5. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  6. data/contrib/zstd/CONTRIBUTING.md +406 -0
  7. data/contrib/zstd/COPYING +339 -0
  8. data/contrib/zstd/Makefile +420 -0
  9. data/contrib/zstd/README.md +179 -41
  10. data/contrib/zstd/TESTING.md +44 -0
  11. data/contrib/zstd/appveyor.yml +292 -0
  12. data/contrib/zstd/lib/BUCK +234 -0
  13. data/contrib/zstd/lib/Makefile +451 -0
  14. data/contrib/zstd/lib/README.md +207 -0
  15. data/contrib/zstd/{common → lib/common}/bitstream.h +187 -138
  16. data/contrib/zstd/lib/common/compiler.h +288 -0
  17. data/contrib/zstd/lib/common/cpu.h +213 -0
  18. data/contrib/zstd/lib/common/debug.c +24 -0
  19. data/contrib/zstd/lib/common/debug.h +107 -0
  20. data/contrib/zstd/lib/common/entropy_common.c +362 -0
  21. data/contrib/zstd/{common → lib/common}/error_private.c +25 -12
  22. data/contrib/zstd/{common → lib/common}/error_private.h +14 -10
  23. data/contrib/zstd/{common → lib/common}/fse.h +173 -92
  24. data/contrib/zstd/{common → lib/common}/fse_decompress.c +149 -85
  25. data/contrib/zstd/lib/common/huf.h +361 -0
  26. data/contrib/zstd/{common → lib/common}/mem.h +115 -59
  27. data/contrib/zstd/lib/common/pool.c +350 -0
  28. data/contrib/zstd/lib/common/pool.h +84 -0
  29. data/contrib/zstd/lib/common/threading.c +122 -0
  30. data/contrib/zstd/lib/common/threading.h +155 -0
  31. data/contrib/zstd/{common → lib/common}/xxhash.c +55 -96
  32. data/contrib/zstd/{common → lib/common}/xxhash.h +23 -47
  33. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  34. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  35. data/contrib/zstd/lib/common/zstd_errors.h +95 -0
  36. data/contrib/zstd/lib/common/zstd_internal.h +478 -0
  37. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +214 -319
  38. data/contrib/zstd/lib/compress/hist.c +181 -0
  39. data/contrib/zstd/lib/compress/hist.h +75 -0
  40. data/contrib/zstd/lib/compress/huf_compress.c +913 -0
  41. data/contrib/zstd/lib/compress/zstd_compress.c +5208 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1203 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +433 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +849 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  49. data/contrib/zstd/lib/compress/zstd_cwksp.h +561 -0
  50. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  52. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  54. data/contrib/zstd/lib/compress/zstd_lazy.c +1412 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.h +87 -0
  56. data/contrib/zstd/lib/compress/zstd_ldm.c +660 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.h +116 -0
  58. data/contrib/zstd/lib/compress/zstd_opt.c +1345 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  60. data/contrib/zstd/lib/compress/zstdmt_compress.c +1811 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.h +110 -0
  62. data/contrib/zstd/lib/decompress/huf_decompress.c +1350 -0
  63. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  65. data/contrib/zstd/lib/decompress/zstd_decompress.c +1930 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1540 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +62 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +190 -0
  69. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +68 -45
  70. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  71. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  73. data/contrib/zstd/lib/dictBuilder/cover.c +1245 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  75. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +0 -0
  77. data/contrib/zstd/lib/dictBuilder/fastcover.c +758 -0
  78. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +318 -194
  79. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  80. data/contrib/zstd/{legacy → lib/legacy}/zstd_legacy.h +171 -15
  81. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +191 -124
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +19 -5
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +125 -125
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +19 -5
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +125 -124
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +20 -6
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +151 -299
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +19 -5
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +237 -243
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +19 -6
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +130 -143
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +18 -5
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.c +158 -157
  94. data/contrib/zstd/{legacy → lib/legacy}/zstd_v07.h +19 -5
  95. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  96. data/contrib/zstd/lib/zstd.h +2391 -0
  97. data/ext/depend +2 -0
  98. data/ext/extconf.rb +15 -6
  99. data/ext/extzstd.c +76 -145
  100. data/ext/extzstd.h +80 -31
  101. data/ext/extzstd_stream.c +417 -142
  102. data/ext/libzstd_conf.h +8 -0
  103. data/ext/zstd_common.c +10 -7
  104. data/ext/zstd_compress.c +14 -5
  105. data/ext/zstd_decompress.c +5 -4
  106. data/ext/zstd_dictbuilder.c +9 -4
  107. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  108. data/ext/zstd_legacy_v01.c +3 -1
  109. data/ext/zstd_legacy_v02.c +3 -1
  110. data/ext/zstd_legacy_v03.c +3 -1
  111. data/ext/zstd_legacy_v04.c +3 -1
  112. data/ext/zstd_legacy_v05.c +3 -1
  113. data/ext/zstd_legacy_v06.c +3 -1
  114. data/ext/zstd_legacy_v07.c +3 -1
  115. data/gemstub.rb +10 -24
  116. data/lib/extzstd.rb +64 -179
  117. data/lib/extzstd/version.rb +6 -1
  118. data/test/test_basic.rb +9 -6
  119. metadata +113 -57
  120. data/HISTORY.ja +0 -5
  121. data/contrib/zstd/common/entropy_common.c +0 -225
  122. data/contrib/zstd/common/huf.h +0 -228
  123. data/contrib/zstd/common/zstd_common.c +0 -83
  124. data/contrib/zstd/common/zstd_errors.h +0 -60
  125. data/contrib/zstd/common/zstd_internal.h +0 -267
  126. data/contrib/zstd/compress/huf_compress.c +0 -533
  127. data/contrib/zstd/compress/zbuff_compress.c +0 -319
  128. data/contrib/zstd/compress/zstd_compress.c +0 -3264
  129. data/contrib/zstd/compress/zstd_opt.h +0 -900
  130. data/contrib/zstd/decompress/huf_decompress.c +0 -883
  131. data/contrib/zstd/decompress/zbuff_decompress.c +0 -252
  132. data/contrib/zstd/decompress/zstd_decompress.c +0 -1842
  133. data/contrib/zstd/dictBuilder/zdict.h +0 -111
  134. data/contrib/zstd/zstd.h +0 -640
@@ -1,228 +0,0 @@
1
- /* ******************************************************************
2
- Huffman coder, part of New Generation Entropy library
3
- header file
4
- Copyright (C) 2013-2016, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
-
12
- * Redistributions of source code must retain the above copyright
13
- notice, this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the following disclaimer
16
- in the documentation and/or other materials provided with the
17
- distribution.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- You can contact the author at :
32
- - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
- ****************************************************************** */
34
- #ifndef HUF_H_298734234
35
- #define HUF_H_298734234
36
-
37
- #if defined (__cplusplus)
38
- extern "C" {
39
- #endif
40
-
41
-
42
- /* *** Dependencies *** */
43
- #include <stddef.h> /* size_t */
44
-
45
-
46
- /* *** simple functions *** */
47
- /**
48
- HUF_compress() :
49
- Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'.
50
- 'dst' buffer must be already allocated.
51
- Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize).
52
- `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB.
53
- @return : size of compressed data (<= `dstCapacity`).
54
- Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
55
- if return == 1, srcData is a single repeated byte symbol (RLE compression).
56
- if HUF_isError(return), compression failed (more details using HUF_getErrorName())
57
- */
58
- size_t HUF_compress(void* dst, size_t dstCapacity,
59
- const void* src, size_t srcSize);
60
-
61
- /**
62
- HUF_decompress() :
63
- Decompress HUF data from buffer 'cSrc', of size 'cSrcSize',
64
- into already allocated buffer 'dst', of minimum size 'dstSize'.
65
- `dstSize` : **must** be the ***exact*** size of original (uncompressed) data.
66
- Note : in contrast with FSE, HUF_decompress can regenerate
67
- RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data,
68
- because it knows size to regenerate.
69
- @return : size of regenerated data (== dstSize),
70
- or an error code, which can be tested using HUF_isError()
71
- */
72
- size_t HUF_decompress(void* dst, size_t dstSize,
73
- const void* cSrc, size_t cSrcSize);
74
-
75
-
76
- /* ****************************************
77
- * Tool functions
78
- ******************************************/
79
- #define HUF_BLOCKSIZE_MAX (128 * 1024)
80
- size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
81
-
82
- /* Error Management */
83
- unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
84
- const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
85
-
86
-
87
- /* *** Advanced function *** */
88
-
89
- /** HUF_compress2() :
90
- * Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog` */
91
- size_t HUF_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
92
-
93
-
94
- #ifdef HUF_STATIC_LINKING_ONLY
95
-
96
- /* *** Dependencies *** */
97
- #include "mem.h" /* U32 */
98
-
99
-
100
- /* *** Constants *** */
101
- #define HUF_TABLELOG_ABSOLUTEMAX 16 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
102
- #define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
103
- #define HUF_TABLELOG_DEFAULT 11 /* tableLog by default, when not specified */
104
- #define HUF_SYMBOLVALUE_MAX 255
105
- #if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
106
- # error "HUF_TABLELOG_MAX is too large !"
107
- #endif
108
-
109
-
110
- /* ****************************************
111
- * Static allocation
112
- ******************************************/
113
- /* HUF buffer bounds */
114
- #define HUF_CTABLEBOUND 129
115
- #define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true if incompressible pre-filtered with fast heuristic */
116
- #define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
117
-
118
- /* static allocation of HUF's Compression Table */
119
- #define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
120
- U32 name##hb[maxSymbolValue+1]; \
121
- void* name##hv = &(name##hb); \
122
- HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
123
-
124
- /* static allocation of HUF's DTable */
125
- typedef U32 HUF_DTable;
126
- #define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog)))
127
- #define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \
128
- HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1)*0x1000001) }
129
- #define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \
130
- HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog)*0x1000001) }
131
-
132
-
133
- /* ****************************************
134
- * Advanced decompression functions
135
- ******************************************/
136
- size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
137
- size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
138
-
139
- size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
140
- size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
141
- size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
142
- size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
143
-
144
- size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
145
- size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
146
- size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
147
-
148
-
149
- /* ****************************************
150
- * HUF detailed API
151
- ******************************************/
152
- /*!
153
- HUF_compress() does the following:
154
- 1. count symbol occurrence from source[] into table count[] using FSE_count()
155
- 2. (optional) refine tableLog using HUF_optimalTableLog()
156
- 3. build Huffman table from count using HUF_buildCTable()
157
- 4. save Huffman table to memory buffer using HUF_writeCTable()
158
- 5. encode the data stream using HUF_compress4X_usingCTable()
159
-
160
- The following API allows targeting specific sub-functions for advanced tasks.
161
- For example, it's possible to compress several blocks using the same 'CTable',
162
- or to save and regenerate 'CTable' using external methods.
163
- */
164
- /* FSE_count() : find it within "fse.h" */
165
- unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
166
- typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
167
- size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits);
168
- size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
169
- size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
170
-
171
-
172
- /*! HUF_readStats() :
173
- Read compact Huffman tree, saved by HUF_writeCTable().
174
- `huffWeight` is destination buffer.
175
- @return : size read from `src` , or an error Code .
176
- Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */
177
- size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
178
- U32* nbSymbolsPtr, U32* tableLogPtr,
179
- const void* src, size_t srcSize);
180
-
181
- /** HUF_readCTable() :
182
- * Loading a CTable saved with HUF_writeCTable() */
183
- size_t HUF_readCTable (HUF_CElt* CTable, unsigned maxSymbolValue, const void* src, size_t srcSize);
184
-
185
-
186
- /*
187
- HUF_decompress() does the following:
188
- 1. select the decompression algorithm (X2, X4) based on pre-computed heuristics
189
- 2. build Huffman table from save, using HUF_readDTableXn()
190
- 3. decode 1 or 4 segments in parallel using HUF_decompressSXn_usingDTable
191
- */
192
-
193
- /** HUF_selectDecoder() :
194
- * Tells which decoder is likely to decode faster,
195
- * based on a set of pre-determined metrics.
196
- * @return : 0==HUF_decompress4X2, 1==HUF_decompress4X4 .
197
- * Assumption : 0 < cSrcSize < dstSize <= 128 KB */
198
- U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
199
-
200
- size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
201
- size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize);
202
-
203
- size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
204
- size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
205
- size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
206
-
207
-
208
- /* single stream variants */
209
-
210
- size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
211
- size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
212
-
213
- size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
214
- size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
215
-
216
- size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
217
- size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
218
- size_t HUF_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
219
-
220
-
221
- #endif /* HUF_STATIC_LINKING_ONLY */
222
-
223
-
224
- #if defined (__cplusplus)
225
- }
226
- #endif
227
-
228
- #endif /* HUF_H_298734234 */
@@ -1,83 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- */
9
-
10
-
11
-
12
- /*-*************************************
13
- * Dependencies
14
- ***************************************/
15
- #include <stdlib.h> /* malloc */
16
- #include "error_private.h"
17
- #define ZSTD_STATIC_LINKING_ONLY
18
- #include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
19
- #include "zbuff.h" /* declaration of ZBUFF_isError, ZBUFF_getErrorName */
20
-
21
-
22
- /*-****************************************
23
- * Version
24
- ******************************************/
25
- unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
26
-
27
-
28
- /*-****************************************
29
- * ZSTD Error Management
30
- ******************************************/
31
- /*! ZSTD_isError() :
32
- * tells if a return value is an error code */
33
- unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
34
-
35
- /*! ZSTD_getErrorName() :
36
- * provides error code string from function result (useful for debugging) */
37
- const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
38
-
39
- /*! ZSTD_getError() :
40
- * convert a `size_t` function result into a proper ZSTD_errorCode enum */
41
- ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
42
-
43
- /*! ZSTD_getErrorString() :
44
- * provides error code string from enum */
45
- const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
46
-
47
-
48
- /* **************************************************************
49
- * ZBUFF Error Management
50
- ****************************************************************/
51
- unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
52
-
53
- const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
54
-
55
-
56
-
57
- /*=**************************************************************
58
- * Custom allocator
59
- ****************************************************************/
60
- /* default uses stdlib */
61
- void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
62
- {
63
- void* address = malloc(size);
64
- (void)opaque;
65
- return address;
66
- }
67
-
68
- void ZSTD_defaultFreeFunction(void* opaque, void* address)
69
- {
70
- (void)opaque;
71
- free(address);
72
- }
73
-
74
- void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
75
- {
76
- return customMem.customAlloc(customMem.opaque, size);
77
- }
78
-
79
- void ZSTD_free(void* ptr, ZSTD_customMem customMem)
80
- {
81
- if (ptr!=NULL)
82
- customMem.customFree(customMem.opaque, ptr);
83
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- */
9
-
10
- #ifndef ZSTD_ERRORS_H_398273423
11
- #define ZSTD_ERRORS_H_398273423
12
-
13
- #if defined (__cplusplus)
14
- extern "C" {
15
- #endif
16
-
17
- /*===== dependency =====*/
18
- #include <stddef.h> /* size_t */
19
-
20
-
21
- /*-****************************************
22
- * error codes list
23
- ******************************************/
24
- typedef enum {
25
- ZSTD_error_no_error,
26
- ZSTD_error_GENERIC,
27
- ZSTD_error_prefix_unknown,
28
- ZSTD_error_version_unsupported,
29
- ZSTD_error_parameter_unknown,
30
- ZSTD_error_frameParameter_unsupported,
31
- ZSTD_error_frameParameter_unsupportedBy32bits,
32
- ZSTD_error_frameParameter_windowTooLarge,
33
- ZSTD_error_compressionParameter_unsupported,
34
- ZSTD_error_init_missing,
35
- ZSTD_error_memory_allocation,
36
- ZSTD_error_stage_wrong,
37
- ZSTD_error_dstSize_tooSmall,
38
- ZSTD_error_srcSize_wrong,
39
- ZSTD_error_corruption_detected,
40
- ZSTD_error_checksum_wrong,
41
- ZSTD_error_tableLog_tooLarge,
42
- ZSTD_error_maxSymbolValue_tooLarge,
43
- ZSTD_error_maxSymbolValue_tooSmall,
44
- ZSTD_error_dictionary_corrupted,
45
- ZSTD_error_dictionary_wrong,
46
- ZSTD_error_maxCode
47
- } ZSTD_ErrorCode;
48
-
49
- /*! ZSTD_getErrorCode() :
50
- convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
51
- which can be used to compare directly with enum list published into "error_public.h" */
52
- ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
53
- const char* ZSTD_getErrorString(ZSTD_ErrorCode code);
54
-
55
-
56
- #if defined (__cplusplus)
57
- }
58
- #endif
59
-
60
- #endif /* ZSTD_ERRORS_H_398273423 */
@@ -1,267 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- */
9
-
10
- #ifndef ZSTD_CCOMMON_H_MODULE
11
- #define ZSTD_CCOMMON_H_MODULE
12
-
13
- /*-*******************************************************
14
- * Compiler specifics
15
- *********************************************************/
16
- #ifdef _MSC_VER /* Visual Studio */
17
- # define FORCE_INLINE static __forceinline
18
- # include <intrin.h> /* For Visual 2005 */
19
- # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
20
- # pragma warning(disable : 4324) /* disable: C4324: padded structure */
21
- # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
22
- #else
23
- # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
24
- # ifdef __GNUC__
25
- # define FORCE_INLINE static inline __attribute__((always_inline))
26
- # else
27
- # define FORCE_INLINE static inline
28
- # endif
29
- # else
30
- # define FORCE_INLINE static
31
- # endif /* __STDC_VERSION__ */
32
- #endif
33
-
34
- #ifdef _MSC_VER
35
- # define FORCE_NOINLINE static __declspec(noinline)
36
- #else
37
- # ifdef __GNUC__
38
- # define FORCE_NOINLINE static __attribute__((__noinline__))
39
- # else
40
- # define FORCE_NOINLINE static
41
- # endif
42
- #endif
43
-
44
-
45
- /*-*************************************
46
- * Dependencies
47
- ***************************************/
48
- #include "mem.h"
49
- #include "error_private.h"
50
- #define ZSTD_STATIC_LINKING_ONLY
51
- #include "zstd.h"
52
-
53
-
54
- /*-*************************************
55
- * shared macros
56
- ***************************************/
57
- #define MIN(a,b) ((a)<(b) ? (a) : (b))
58
- #define MAX(a,b) ((a)>(b) ? (a) : (b))
59
- #define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
60
- #define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */
61
-
62
-
63
- /*-*************************************
64
- * Common constants
65
- ***************************************/
66
- #define ZSTD_OPT_NUM (1<<12)
67
- #define ZSTD_DICT_MAGIC 0xEC30A437 /* v0.7+ */
68
-
69
- #define ZSTD_REP_NUM 3 /* number of repcodes */
70
- #define ZSTD_REP_CHECK (ZSTD_REP_NUM) /* number of repcodes to check by the optimal parser */
71
- #define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
72
- #define ZSTD_REP_MOVE_OPT (ZSTD_REP_NUM)
73
- static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
74
-
75
- #define KB *(1 <<10)
76
- #define MB *(1 <<20)
77
- #define GB *(1U<<30)
78
-
79
- #define BIT7 128
80
- #define BIT6 64
81
- #define BIT5 32
82
- #define BIT4 16
83
- #define BIT1 2
84
- #define BIT0 1
85
-
86
- #define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
87
- static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
88
- static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
89
-
90
- #define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
91
- static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
92
- typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
93
-
94
- #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
95
- #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
96
-
97
- #define HufLog 12
98
- typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
99
-
100
- #define LONGNBSEQ 0x7F00
101
-
102
- #define MINMATCH 3
103
- #define EQUAL_READ32 4
104
-
105
- #define Litbits 8
106
- #define MaxLit ((1<<Litbits) - 1)
107
- #define MaxML 52
108
- #define MaxLL 35
109
- #define MaxOff 28
110
- #define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
111
- #define MLFSELog 9
112
- #define LLFSELog 9
113
- #define OffFSELog 8
114
-
115
- static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116
- 1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
117
- 13,14,15,16 };
118
- static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
119
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
120
- -1,-1,-1,-1 };
121
- #define LL_DEFAULTNORMLOG 6 /* for static allocation */
122
- static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
123
-
124
- static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126
- 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9,10,11,
127
- 12,13,14,15,16 };
128
- static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
129
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
130
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
131
- -1,-1,-1,-1,-1 };
132
- #define ML_DEFAULTNORMLOG 6 /* for static allocation */
133
- static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
134
-
135
- static const S16 OF_defaultNorm[MaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
136
- 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
137
- #define OF_DEFAULTNORMLOG 5 /* for static allocation */
138
- static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
139
-
140
-
141
- /*-*******************************************
142
- * Shared functions to include for inlining
143
- *********************************************/
144
- static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
145
- #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
146
-
147
- /*! ZSTD_wildcopy() :
148
- * custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
149
- #define WILDCOPY_OVERLENGTH 8
150
- MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, size_t length)
151
- {
152
- const BYTE* ip = (const BYTE*)src;
153
- BYTE* op = (BYTE*)dst;
154
- BYTE* const oend = op + length;
155
- do
156
- COPY8(op, ip)
157
- while (op < oend);
158
- }
159
-
160
- MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
161
- {
162
- const BYTE* ip = (const BYTE*)src;
163
- BYTE* op = (BYTE*)dst;
164
- BYTE* const oend = (BYTE*)dstEnd;
165
- do
166
- COPY8(op, ip)
167
- while (op < oend);
168
- }
169
-
170
-
171
- /*-*******************************************
172
- * Private interfaces
173
- *********************************************/
174
- typedef struct ZSTD_stats_s ZSTD_stats_t;
175
-
176
- typedef struct {
177
- U32 off;
178
- U32 len;
179
- } ZSTD_match_t;
180
-
181
- typedef struct {
182
- U32 price;
183
- U32 off;
184
- U32 mlen;
185
- U32 litlen;
186
- U32 rep[ZSTD_REP_NUM];
187
- } ZSTD_optimal_t;
188
-
189
-
190
- typedef struct seqDef_s {
191
- U32 offset;
192
- U16 litLength;
193
- U16 matchLength;
194
- } seqDef;
195
-
196
-
197
- typedef struct {
198
- seqDef* sequencesStart;
199
- seqDef* sequences;
200
- BYTE* litStart;
201
- BYTE* lit;
202
- BYTE* llCode;
203
- BYTE* mlCode;
204
- BYTE* ofCode;
205
- U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
206
- U32 longLengthPos;
207
- /* opt */
208
- ZSTD_optimal_t* priceTable;
209
- ZSTD_match_t* matchTable;
210
- U32* matchLengthFreq;
211
- U32* litLengthFreq;
212
- U32* litFreq;
213
- U32* offCodeFreq;
214
- U32 matchLengthSum;
215
- U32 matchSum;
216
- U32 litLengthSum;
217
- U32 litSum;
218
- U32 offCodeSum;
219
- U32 log2matchLengthSum;
220
- U32 log2matchSum;
221
- U32 log2litLengthSum;
222
- U32 log2litSum;
223
- U32 log2offCodeSum;
224
- U32 factor;
225
- U32 cachedPrice;
226
- U32 cachedLitLength;
227
- const BYTE* cachedLiterals;
228
- } seqStore_t;
229
-
230
- const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
231
- void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
232
- int ZSTD_isSkipFrame(ZSTD_DCtx* dctx);
233
-
234
- /* custom memory allocation functions */
235
- void* ZSTD_defaultAllocFunction(void* opaque, size_t size);
236
- void ZSTD_defaultFreeFunction(void* opaque, void* address);
237
- static const ZSTD_customMem defaultCustomMem = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
238
- void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
239
- void ZSTD_free(void* ptr, ZSTD_customMem customMem);
240
-
241
-
242
- /*====== common function ======*/
243
-
244
- MEM_STATIC U32 ZSTD_highbit32(U32 val)
245
- {
246
- # if defined(_MSC_VER) /* Visual */
247
- unsigned long r=0;
248
- _BitScanReverse(&r, val);
249
- return (unsigned)r;
250
- # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
251
- return 31 - __builtin_clz(val);
252
- # else /* Software version */
253
- static const int DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
254
- U32 v = val;
255
- int r;
256
- v |= v >> 1;
257
- v |= v >> 2;
258
- v |= v >> 4;
259
- v |= v >> 8;
260
- v |= v >> 16;
261
- r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27];
262
- return r;
263
- # endif
264
- }
265
-
266
-
267
- #endif /* ZSTD_CCOMMON_H_MODULE */