zstd 1.1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +64 -0
  7. data/Rakefile +19 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/exe/zstd +3 -0
  11. data/ext/zstd/extconf.rb +20 -0
  12. data/ext/zstd/libzstd/.gitignore +2 -0
  13. data/ext/zstd/libzstd/LICENSE +1262 -0
  14. data/ext/zstd/libzstd/Makefile +133 -0
  15. data/ext/zstd/libzstd/PATENTS +1272 -0
  16. data/ext/zstd/libzstd/README.md +77 -0
  17. data/ext/zstd/libzstd/common/bitstream.h +414 -0
  18. data/ext/zstd/libzstd/common/entropy_common.c +227 -0
  19. data/ext/zstd/libzstd/common/error_private.c +43 -0
  20. data/ext/zstd/libzstd/common/error_private.h +76 -0
  21. data/ext/zstd/libzstd/common/fse.h +668 -0
  22. data/ext/zstd/libzstd/common/fse_decompress.c +329 -0
  23. data/ext/zstd/libzstd/common/huf.h +238 -0
  24. data/ext/zstd/libzstd/common/mem.h +372 -0
  25. data/ext/zstd/libzstd/common/xxhash.c +867 -0
  26. data/ext/zstd/libzstd/common/xxhash.h +309 -0
  27. data/ext/zstd/libzstd/common/zstd_common.c +77 -0
  28. data/ext/zstd/libzstd/common/zstd_errors.h +60 -0
  29. data/ext/zstd/libzstd/common/zstd_internal.h +270 -0
  30. data/ext/zstd/libzstd/compress/fse_compress.c +850 -0
  31. data/ext/zstd/libzstd/compress/huf_compress.c +609 -0
  32. data/ext/zstd/libzstd/compress/zstd_compress.c +3291 -0
  33. data/ext/zstd/libzstd/compress/zstd_opt.h +919 -0
  34. data/ext/zstd/libzstd/decompress/huf_decompress.c +885 -0
  35. data/ext/zstd/libzstd/decompress/zstd_decompress.c +2154 -0
  36. data/ext/zstd/libzstd/deprecated/zbuff.h +210 -0
  37. data/ext/zstd/libzstd/deprecated/zbuff_compress.c +145 -0
  38. data/ext/zstd/libzstd/deprecated/zbuff_decompress.c +74 -0
  39. data/ext/zstd/libzstd/dictBuilder/divsufsort.c +1913 -0
  40. data/ext/zstd/libzstd/dictBuilder/divsufsort.h +67 -0
  41. data/ext/zstd/libzstd/dictBuilder/zdict.c +1012 -0
  42. data/ext/zstd/libzstd/dictBuilder/zdict.h +111 -0
  43. data/ext/zstd/libzstd/dll/example/Makefile +47 -0
  44. data/ext/zstd/libzstd/dll/example/README.md +69 -0
  45. data/ext/zstd/libzstd/dll/example/build_package.bat +17 -0
  46. data/ext/zstd/libzstd/dll/example/fullbench-dll.sln +25 -0
  47. data/ext/zstd/libzstd/dll/example/fullbench-dll.vcxproj +179 -0
  48. data/ext/zstd/libzstd/dll/libzstd.def +86 -0
  49. data/ext/zstd/libzstd/legacy/zstd_legacy.h +259 -0
  50. data/ext/zstd/libzstd/legacy/zstd_v01.c +2095 -0
  51. data/ext/zstd/libzstd/legacy/zstd_v01.h +80 -0
  52. data/ext/zstd/libzstd/legacy/zstd_v02.c +3518 -0
  53. data/ext/zstd/libzstd/legacy/zstd_v02.h +79 -0
  54. data/ext/zstd/libzstd/legacy/zstd_v03.c +3159 -0
  55. data/ext/zstd/libzstd/legacy/zstd_v03.h +79 -0
  56. data/ext/zstd/libzstd/legacy/zstd_v04.c +3795 -0
  57. data/ext/zstd/libzstd/legacy/zstd_v04.h +128 -0
  58. data/ext/zstd/libzstd/legacy/zstd_v05.c +4056 -0
  59. data/ext/zstd/libzstd/legacy/zstd_v05.h +149 -0
  60. data/ext/zstd/libzstd/legacy/zstd_v06.c +4167 -0
  61. data/ext/zstd/libzstd/legacy/zstd_v06.h +159 -0
  62. data/ext/zstd/libzstd/legacy/zstd_v07.c +4540 -0
  63. data/ext/zstd/libzstd/legacy/zstd_v07.h +173 -0
  64. data/ext/zstd/libzstd/libzstd.pc.in +14 -0
  65. data/ext/zstd/libzstd/zstd.h +673 -0
  66. data/ext/zstd/zstd.c +185 -0
  67. data/ext/zstd/zstd.h +7 -0
  68. data/lib/zstd/version.rb +3 -0
  69. data/lib/zstd.rb +6 -0
  70. data/zstd.gemspec +38 -0
  71. metadata +172 -0
@@ -0,0 +1,227 @@
1
+ /*
2
+ Common functions of New Generation Entropy library
3
+ Copyright (C) 2016, Yann Collet.
4
+
5
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ * Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the following disclaimer
15
+ in the documentation and/or other materials provided with the
16
+ distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ You can contact the author at :
31
+ - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
32
+ - Public forum : https://groups.google.com/forum/#!forum/lz4c
33
+ *************************************************************************** */
34
+
35
+ /* *************************************
36
+ * Dependencies
37
+ ***************************************/
38
+ #include "mem.h"
39
+ #include "error_private.h" /* ERR_*, ERROR */
40
+ #define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
41
+ #include "fse.h"
42
+ #define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
43
+ #include "huf.h"
44
+
45
+
46
+ /*-****************************************
47
+ * FSE Error Management
48
+ ******************************************/
49
+ unsigned FSE_isError(size_t code) { return ERR_isError(code); }
50
+
51
+ const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
52
+
53
+
54
+ /* **************************************************************
55
+ * HUF Error Management
56
+ ****************************************************************/
57
+ unsigned HUF_isError(size_t code) { return ERR_isError(code); }
58
+
59
+ const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
60
+
61
+
62
+ /*-**************************************************************
63
+ * FSE NCount encoding-decoding
64
+ ****************************************************************/
65
+ static short FSE_abs(short a) { return (short)(a<0 ? -a : a); }
66
+
67
+ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
68
+ const void* headerBuffer, size_t hbSize)
69
+ {
70
+ const BYTE* const istart = (const BYTE*) headerBuffer;
71
+ const BYTE* const iend = istart + hbSize;
72
+ const BYTE* ip = istart;
73
+ int nbBits;
74
+ int remaining;
75
+ int threshold;
76
+ U32 bitStream;
77
+ int bitCount;
78
+ unsigned charnum = 0;
79
+ int previous0 = 0;
80
+
81
+ if (hbSize < 4) return ERROR(srcSize_wrong);
82
+ bitStream = MEM_readLE32(ip);
83
+ nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
84
+ if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
85
+ bitStream >>= 4;
86
+ bitCount = 4;
87
+ *tableLogPtr = nbBits;
88
+ remaining = (1<<nbBits)+1;
89
+ threshold = 1<<nbBits;
90
+ nbBits++;
91
+
92
+ while ((remaining>1) & (charnum<=*maxSVPtr)) {
93
+ if (previous0) {
94
+ unsigned n0 = charnum;
95
+ while ((bitStream & 0xFFFF) == 0xFFFF) {
96
+ n0 += 24;
97
+ if (ip < iend-5) {
98
+ ip += 2;
99
+ bitStream = MEM_readLE32(ip) >> bitCount;
100
+ } else {
101
+ bitStream >>= 16;
102
+ bitCount += 16;
103
+ } }
104
+ while ((bitStream & 3) == 3) {
105
+ n0 += 3;
106
+ bitStream >>= 2;
107
+ bitCount += 2;
108
+ }
109
+ n0 += bitStream & 3;
110
+ bitCount += 2;
111
+ if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall);
112
+ while (charnum < n0) normalizedCounter[charnum++] = 0;
113
+ if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
114
+ ip += bitCount>>3;
115
+ bitCount &= 7;
116
+ bitStream = MEM_readLE32(ip) >> bitCount;
117
+ } else {
118
+ bitStream >>= 2;
119
+ } }
120
+ { short const max = (short)((2*threshold-1)-remaining);
121
+ short count;
122
+
123
+ if ((bitStream & (threshold-1)) < (U32)max) {
124
+ count = (short)(bitStream & (threshold-1));
125
+ bitCount += nbBits-1;
126
+ } else {
127
+ count = (short)(bitStream & (2*threshold-1));
128
+ if (count >= threshold) count -= max;
129
+ bitCount += nbBits;
130
+ }
131
+
132
+ count--; /* extra accuracy */
133
+ remaining -= FSE_abs(count);
134
+ normalizedCounter[charnum++] = count;
135
+ previous0 = !count;
136
+ while (remaining < threshold) {
137
+ nbBits--;
138
+ threshold >>= 1;
139
+ }
140
+
141
+ if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
142
+ ip += bitCount>>3;
143
+ bitCount &= 7;
144
+ } else {
145
+ bitCount -= (int)(8 * (iend - 4 - ip));
146
+ ip = iend - 4;
147
+ }
148
+ bitStream = MEM_readLE32(ip) >> (bitCount & 31);
149
+ } } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
150
+ if (remaining != 1) return ERROR(corruption_detected);
151
+ if (bitCount > 32) return ERROR(corruption_detected);
152
+ *maxSVPtr = charnum-1;
153
+
154
+ ip += (bitCount+7)>>3;
155
+ return ip-istart;
156
+ }
157
+
158
+
159
+ /*! HUF_readStats() :
160
+ Read compact Huffman tree, saved by HUF_writeCTable().
161
+ `huffWeight` is destination buffer.
162
+ `rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
163
+ @return : size read from `src` , or an error Code .
164
+ Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
165
+ */
166
+ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
167
+ U32* nbSymbolsPtr, U32* tableLogPtr,
168
+ const void* src, size_t srcSize)
169
+ {
170
+ U32 weightTotal;
171
+ const BYTE* ip = (const BYTE*) src;
172
+ size_t iSize;
173
+ size_t oSize;
174
+
175
+ if (!srcSize) return ERROR(srcSize_wrong);
176
+ iSize = ip[0];
177
+ /* memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
178
+
179
+ if (iSize >= 128) { /* special header */
180
+ oSize = iSize - 127;
181
+ iSize = ((oSize+1)/2);
182
+ if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
183
+ if (oSize >= hwSize) return ERROR(corruption_detected);
184
+ ip += 1;
185
+ { U32 n;
186
+ for (n=0; n<oSize; n+=2) {
187
+ huffWeight[n] = ip[n/2] >> 4;
188
+ huffWeight[n+1] = ip[n/2] & 15;
189
+ } } }
190
+ else { /* header compressed with FSE (normal case) */
191
+ FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
192
+ if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
193
+ oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
194
+ if (FSE_isError(oSize)) return oSize;
195
+ }
196
+
197
+ /* collect weight stats */
198
+ memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
199
+ weightTotal = 0;
200
+ { U32 n; for (n=0; n<oSize; n++) {
201
+ if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
202
+ rankStats[huffWeight[n]]++;
203
+ weightTotal += (1 << huffWeight[n]) >> 1;
204
+ } }
205
+ if (weightTotal == 0) return ERROR(corruption_detected);
206
+
207
+ /* get last non-null symbol weight (implied, total must be 2^n) */
208
+ { U32 const tableLog = BIT_highbit32(weightTotal) + 1;
209
+ if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
210
+ *tableLogPtr = tableLog;
211
+ /* determine last weight */
212
+ { U32 const total = 1 << tableLog;
213
+ U32 const rest = total - weightTotal;
214
+ U32 const verif = 1 << BIT_highbit32(rest);
215
+ U32 const lastWeight = BIT_highbit32(rest) + 1;
216
+ if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
217
+ huffWeight[oSize] = (BYTE)lastWeight;
218
+ rankStats[lastWeight]++;
219
+ } }
220
+
221
+ /* check tree construction validity */
222
+ if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */
223
+
224
+ /* results */
225
+ *nbSymbolsPtr = (U32)(oSize+1);
226
+ return iSize+1;
227
+ }
@@ -0,0 +1,43 @@
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
+ /* The purpose of this file is to have a single list of error strings embedded in binary */
11
+
12
+ #include "error_private.h"
13
+
14
+ const char* ERR_getErrorString(ERR_enum code)
15
+ {
16
+ static const char* const notErrorCode = "Unspecified error code";
17
+ switch( code )
18
+ {
19
+ case PREFIX(no_error): return "No error detected";
20
+ case PREFIX(GENERIC): return "Error (generic)";
21
+ case PREFIX(prefix_unknown): return "Unknown frame descriptor";
22
+ case PREFIX(version_unsupported): return "Version not supported";
23
+ case PREFIX(parameter_unknown): return "Unknown parameter type";
24
+ case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
25
+ case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
26
+ case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
27
+ case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound";
28
+ case PREFIX(init_missing): return "Context should be init first";
29
+ case PREFIX(memory_allocation): return "Allocation error : not enough memory";
30
+ case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
31
+ case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
32
+ case PREFIX(srcSize_wrong): return "Src size incorrect";
33
+ case PREFIX(corruption_detected): return "Corrupted block detected";
34
+ case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
35
+ case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
36
+ case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
37
+ case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
38
+ case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
39
+ case PREFIX(dictionary_wrong): return "Dictionary mismatch";
40
+ case PREFIX(maxCode):
41
+ default: return notErrorCode;
42
+ }
43
+ }
@@ -0,0 +1,76 @@
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
+ /* Note : this module is expected to remain private, do not expose it */
11
+
12
+ #ifndef ERROR_H_MODULE
13
+ #define ERROR_H_MODULE
14
+
15
+ #if defined (__cplusplus)
16
+ extern "C" {
17
+ #endif
18
+
19
+
20
+ /* ****************************************
21
+ * Dependencies
22
+ ******************************************/
23
+ #include <stddef.h> /* size_t */
24
+ #include "zstd_errors.h" /* enum list */
25
+
26
+
27
+ /* ****************************************
28
+ * Compiler-specific
29
+ ******************************************/
30
+ #if defined(__GNUC__)
31
+ # define ERR_STATIC static __attribute__((unused))
32
+ #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
33
+ # define ERR_STATIC static inline
34
+ #elif defined(_MSC_VER)
35
+ # define ERR_STATIC static __inline
36
+ #else
37
+ # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
38
+ #endif
39
+
40
+
41
+ /*-****************************************
42
+ * Customization (error_public.h)
43
+ ******************************************/
44
+ typedef ZSTD_ErrorCode ERR_enum;
45
+ #define PREFIX(name) ZSTD_error_##name
46
+
47
+
48
+ /*-****************************************
49
+ * Error codes handling
50
+ ******************************************/
51
+ #ifdef ERROR
52
+ # undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
53
+ #endif
54
+ #define ERROR(name) ((size_t)-PREFIX(name))
55
+
56
+ ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
57
+
58
+ ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
59
+
60
+
61
+ /*-****************************************
62
+ * Error Strings
63
+ ******************************************/
64
+
65
+ const char* ERR_getErrorString(ERR_enum code); /* error_private.c */
66
+
67
+ ERR_STATIC const char* ERR_getErrorName(size_t code)
68
+ {
69
+ return ERR_getErrorString(ERR_getErrorCode(code));
70
+ }
71
+
72
+ #if defined (__cplusplus)
73
+ }
74
+ #endif
75
+
76
+ #endif /* ERROR_H_MODULE */