extzstd 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +18 -0
  3. data/README.md +15 -50
  4. data/contrib/zstd/CONTRIBUTING.md +1 -1
  5. data/contrib/zstd/COPYING +339 -0
  6. data/contrib/zstd/Makefile +82 -51
  7. data/contrib/zstd/NEWS +92 -5
  8. data/contrib/zstd/README.md +50 -41
  9. data/contrib/zstd/appveyor.yml +164 -102
  10. data/contrib/zstd/circle.yml +10 -22
  11. data/contrib/zstd/lib/BUCK +31 -10
  12. data/contrib/zstd/lib/Makefile +57 -31
  13. data/contrib/zstd/lib/README.md +68 -37
  14. data/contrib/zstd/lib/common/bitstream.h +130 -76
  15. data/contrib/zstd/lib/common/compiler.h +86 -0
  16. data/contrib/zstd/lib/common/error_private.c +15 -11
  17. data/contrib/zstd/lib/common/error_private.h +8 -8
  18. data/contrib/zstd/lib/common/fse.h +19 -9
  19. data/contrib/zstd/lib/common/fse_decompress.c +3 -22
  20. data/contrib/zstd/lib/common/huf.h +68 -26
  21. data/contrib/zstd/lib/common/mem.h +23 -35
  22. data/contrib/zstd/lib/common/pool.c +123 -63
  23. data/contrib/zstd/lib/common/pool.h +19 -10
  24. data/contrib/zstd/lib/common/threading.c +11 -16
  25. data/contrib/zstd/lib/common/threading.h +52 -33
  26. data/contrib/zstd/lib/common/xxhash.c +28 -22
  27. data/contrib/zstd/lib/common/zstd_common.c +40 -27
  28. data/contrib/zstd/lib/common/zstd_errors.h +43 -34
  29. data/contrib/zstd/lib/common/zstd_internal.h +131 -123
  30. data/contrib/zstd/lib/compress/fse_compress.c +17 -33
  31. data/contrib/zstd/lib/compress/huf_compress.c +15 -9
  32. data/contrib/zstd/lib/compress/zstd_compress.c +2096 -2363
  33. data/contrib/zstd/lib/compress/zstd_compress_internal.h +462 -0
  34. data/contrib/zstd/lib/compress/zstd_double_fast.c +309 -0
  35. data/contrib/zstd/lib/compress/zstd_double_fast.h +29 -0
  36. data/contrib/zstd/lib/compress/zstd_fast.c +243 -0
  37. data/contrib/zstd/lib/compress/zstd_fast.h +31 -0
  38. data/contrib/zstd/lib/compress/zstd_lazy.c +765 -0
  39. data/contrib/zstd/lib/compress/zstd_lazy.h +39 -0
  40. data/contrib/zstd/lib/compress/zstd_ldm.c +707 -0
  41. data/contrib/zstd/lib/compress/zstd_ldm.h +68 -0
  42. data/contrib/zstd/lib/compress/zstd_opt.c +785 -0
  43. data/contrib/zstd/lib/compress/zstd_opt.h +19 -908
  44. data/contrib/zstd/lib/compress/zstdmt_compress.c +737 -327
  45. data/contrib/zstd/lib/compress/zstdmt_compress.h +88 -26
  46. data/contrib/zstd/lib/decompress/huf_decompress.c +158 -50
  47. data/contrib/zstd/lib/decompress/zstd_decompress.c +884 -699
  48. data/contrib/zstd/lib/deprecated/zbuff.h +5 -4
  49. data/contrib/zstd/lib/deprecated/zbuff_common.c +5 -5
  50. data/contrib/zstd/lib/deprecated/zbuff_compress.c +6 -4
  51. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +5 -4
  52. data/contrib/zstd/lib/dictBuilder/cover.c +93 -77
  53. data/contrib/zstd/lib/dictBuilder/zdict.c +107 -92
  54. data/contrib/zstd/lib/dictBuilder/zdict.h +112 -102
  55. data/contrib/zstd/lib/legacy/zstd_legacy.h +9 -4
  56. data/contrib/zstd/lib/legacy/zstd_v01.c +7 -6
  57. data/contrib/zstd/lib/legacy/zstd_v01.h +5 -4
  58. data/contrib/zstd/lib/legacy/zstd_v02.c +27 -99
  59. data/contrib/zstd/lib/legacy/zstd_v02.h +5 -4
  60. data/contrib/zstd/lib/legacy/zstd_v03.c +26 -98
  61. data/contrib/zstd/lib/legacy/zstd_v03.h +5 -4
  62. data/contrib/zstd/lib/legacy/zstd_v04.c +22 -91
  63. data/contrib/zstd/lib/legacy/zstd_v04.h +5 -4
  64. data/contrib/zstd/lib/legacy/zstd_v05.c +23 -99
  65. data/contrib/zstd/lib/legacy/zstd_v05.h +5 -4
  66. data/contrib/zstd/lib/legacy/zstd_v06.c +22 -96
  67. data/contrib/zstd/lib/legacy/zstd_v06.h +5 -4
  68. data/contrib/zstd/lib/legacy/zstd_v07.c +19 -95
  69. data/contrib/zstd/lib/legacy/zstd_v07.h +5 -4
  70. data/contrib/zstd/lib/zstd.h +895 -271
  71. data/ext/extconf.rb +11 -2
  72. data/ext/extzstd.c +45 -128
  73. data/ext/extzstd.h +74 -31
  74. data/ext/extzstd_stream.c +401 -142
  75. data/ext/zstd_common.c +5 -0
  76. data/ext/zstd_compress.c +8 -0
  77. data/ext/zstd_decompress.c +1 -0
  78. data/ext/zstd_dictbuilder.c +2 -0
  79. data/lib/extzstd/version.rb +1 -1
  80. data/lib/extzstd.rb +48 -1
  81. data/test/test_basic.rb +9 -1
  82. metadata +17 -7
  83. data/HISTORY.ja +0 -10
  84. data/contrib/zstd/LICENSE-examples +0 -11
  85. data/contrib/zstd/PATENTS +0 -33
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef DICTBUILDER_H_001
@@ -20,10 +21,12 @@ extern "C" {
20
21
 
21
22
 
22
23
  /* ===== ZDICTLIB_API : control library symbols visibility ===== */
23
- #if defined(__GNUC__) && (__GNUC__ >= 4)
24
- # define ZDICTLIB_VISIBILITY __attribute__ ((visibility ("default")))
25
- #else
26
- # define ZDICTLIB_VISIBILITY
24
+ #ifndef ZDICTLIB_VISIBILITY
25
+ # if defined(__GNUC__) && (__GNUC__ >= 4)
26
+ # define ZDICTLIB_VISIBILITY __attribute__ ((visibility ("default")))
27
+ # else
28
+ # define ZDICTLIB_VISIBILITY
29
+ # endif
27
30
  #endif
28
31
  #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
29
32
  # define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBILITY
@@ -34,18 +37,20 @@ extern "C" {
34
37
  #endif
35
38
 
36
39
 
37
- /*! ZDICT_trainFromBuffer() :
38
- Train a dictionary from an array of samples.
39
- Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
40
- supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
41
- The resulting dictionary will be saved into `dictBuffer`.
42
- @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
43
- or an error code, which can be tested with ZDICT_isError().
44
- Tips : In general, a reasonable dictionary has a size of ~ 100 KB.
45
- It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`.
46
- In general, it's recommended to provide a few thousands samples, but this can vary a lot.
47
- It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
48
- */
40
+ /*! ZDICT_trainFromBuffer():
41
+ * Train a dictionary from an array of samples.
42
+ * Uses ZDICT_optimizeTrainFromBuffer_cover() single-threaded, with d=8 and steps=4.
43
+ * Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
44
+ * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
45
+ * The resulting dictionary will be saved into `dictBuffer`.
46
+ * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
47
+ * or an error code, which can be tested with ZDICT_isError().
48
+ * Note: ZDICT_trainFromBuffer() requires about 9 bytes of memory for each input byte.
49
+ * Tips: In general, a reasonable dictionary has a size of ~ 100 KB.
50
+ * It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`.
51
+ * In general, it's recommended to provide a few thousands samples, but this can vary a lot.
52
+ * It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
53
+ */
49
54
  ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
50
55
  const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
51
56
 
@@ -67,102 +72,107 @@ ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
67
72
  * ==================================================================================== */
68
73
 
69
74
  typedef struct {
70
- unsigned selectivityLevel; /* 0 means default; larger => select more => larger dictionary */
71
75
  int compressionLevel; /* 0 means default; target a specific zstd compression level */
72
76
  unsigned notificationLevel; /* Write to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
73
77
  unsigned dictID; /* 0 means auto mode (32-bits random value); other : force dictID value */
74
- unsigned reserved[2]; /* reserved space for future parameters */
75
78
  } ZDICT_params_t;
76
79
 
77
-
78
- /*! ZDICT_trainFromBuffer_advanced() :
79
- Same as ZDICT_trainFromBuffer() with control over more parameters.
80
- `parameters` is optional and can be provided with values set to 0 to mean "default".
81
- @return : size of dictionary stored into `dictBuffer` (<= `dictBufferSize`),
82
- or an error code, which can be tested by ZDICT_isError().
83
- note : ZDICT_trainFromBuffer_advanced() will send notifications into stderr if instructed to, using notificationLevel>0.
84
- */
85
- ZDICTLIB_API size_t ZDICT_trainFromBuffer_advanced(void* dictBuffer, size_t dictBufferCapacity,
86
- const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
87
- ZDICT_params_t parameters);
88
-
89
- /*! COVER_params_t :
90
- For all values 0 means default.
91
- kMin and d are the only required parameters.
92
- */
80
+ /*! ZDICT_cover_params_t:
81
+ * For all values 0 means default.
82
+ * k and d are the only required parameters.
83
+ */
93
84
  typedef struct {
94
85
  unsigned k; /* Segment size : constraint: 0 < k : Reasonable range [16, 2048+] */
95
86
  unsigned d; /* dmer size : constraint: 0 < d <= k : Reasonable range [6, 16] */
96
87
  unsigned steps; /* Number of steps : Only used for optimization : 0 means default (32) : Higher means more parameters checked */
97
-
98
88
  unsigned nbThreads; /* Number of threads : constraint: 0 < nbThreads : 1 means single-threaded : Only used for optimization : Ignored if ZSTD_MULTITHREAD is not defined */
99
- unsigned notificationLevel; /* Write to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
100
- unsigned dictID; /* 0 means auto mode (32-bits random value); other : force dictID value */
101
- int compressionLevel; /* 0 means default; target a specific zstd compression level */
102
- } COVER_params_t;
103
-
104
-
105
- /*! COVER_trainFromBuffer() :
106
- Train a dictionary from an array of samples using the COVER algorithm.
107
- Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
108
- supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
109
- The resulting dictionary will be saved into `dictBuffer`.
110
- @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
111
- or an error code, which can be tested with ZDICT_isError().
112
- Note : COVER_trainFromBuffer() requires about 9 bytes of memory for each input byte.
113
- Tips : In general, a reasonable dictionary has a size of ~ 100 KB.
114
- It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`.
115
- In general, it's recommended to provide a few thousands samples, but this can vary a lot.
116
- It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
117
- */
118
- ZDICTLIB_API size_t COVER_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
119
- const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
120
- COVER_params_t parameters);
121
-
122
- /*! COVER_optimizeTrainFromBuffer() :
123
- The same requirements as above hold for all the parameters except `parameters`.
124
- This function tries many parameter combinations and picks the best parameters.
125
- `*parameters` is filled with the best parameters found, and the dictionary
126
- constructed with those parameters is stored in `dictBuffer`.
127
-
128
- All of the parameters d, k, steps are optional.
129
- If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8, 10, 12, 14, 16}.
130
- if steps is zero it defaults to its default value.
131
- If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [16, 2048].
132
-
133
- @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
134
- or an error code, which can be tested with ZDICT_isError().
135
- On success `*parameters` contains the parameters selected.
136
- Note : COVER_optimizeTrainFromBuffer() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread.
137
- */
138
- ZDICTLIB_API size_t COVER_optimizeTrainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
139
- const void* samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
140
- COVER_params_t *parameters);
141
-
142
- /*! ZDICT_finalizeDictionary() :
143
-
144
- Given a custom content as a basis for dictionary, and a set of samples,
145
- finalize dictionary by adding headers and statistics.
146
-
147
- Samples must be stored concatenated in a flat buffer `samplesBuffer`,
148
- supplied with an array of sizes `samplesSizes`, providing the size of each sample in order.
149
-
150
- dictContentSize must be > ZDICT_CONTENTSIZE_MIN bytes.
151
- maxDictSize must be >= dictContentSize, and must be > ZDICT_DICTSIZE_MIN bytes.
152
-
153
- @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`),
154
- or an error code, which can be tested by ZDICT_isError().
155
- note : ZDICT_finalizeDictionary() will push notifications into stderr if instructed to, using notificationLevel>0.
156
- note 2 : dictBuffer and customDictContent can overlap
157
- */
158
- #define ZDICT_CONTENTSIZE_MIN 256
159
- #define ZDICT_DICTSIZE_MIN 512
89
+ ZDICT_params_t zParams;
90
+ } ZDICT_cover_params_t;
91
+
92
+
93
+ /*! ZDICT_trainFromBuffer_cover():
94
+ * Train a dictionary from an array of samples using the COVER algorithm.
95
+ * Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
96
+ * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
97
+ * The resulting dictionary will be saved into `dictBuffer`.
98
+ * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
99
+ * or an error code, which can be tested with ZDICT_isError().
100
+ * Note: ZDICT_trainFromBuffer_cover() requires about 9 bytes of memory for each input byte.
101
+ * Tips: In general, a reasonable dictionary has a size of ~ 100 KB.
102
+ * It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`.
103
+ * In general, it's recommended to provide a few thousands samples, but this can vary a lot.
104
+ * It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
105
+ */
106
+ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
107
+ void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
108
+ const size_t *samplesSizes, unsigned nbSamples,
109
+ ZDICT_cover_params_t parameters);
110
+
111
+ /*! ZDICT_optimizeTrainFromBuffer_cover():
112
+ * The same requirements as above hold for all the parameters except `parameters`.
113
+ * This function tries many parameter combinations and picks the best parameters.
114
+ * `*parameters` is filled with the best parameters found, and the dictionary
115
+ * constructed with those parameters is stored in `dictBuffer`.
116
+ *
117
+ * All of the parameters d, k, steps are optional.
118
+ * If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8, 10, 12, 14, 16}.
119
+ * if steps is zero it defaults to its default value.
120
+ * If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [16, 2048].
121
+ *
122
+ * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
123
+ * or an error code, which can be tested with ZDICT_isError().
124
+ * On success `*parameters` contains the parameters selected.
125
+ * Note: ZDICT_optimizeTrainFromBuffer_cover() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread.
126
+ */
127
+ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
128
+ void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
129
+ const size_t *samplesSizes, unsigned nbSamples,
130
+ ZDICT_cover_params_t *parameters);
131
+
132
+ /*! ZDICT_finalizeDictionary():
133
+ * Given a custom content as a basis for dictionary, and a set of samples,
134
+ * finalize dictionary by adding headers and statistics.
135
+ *
136
+ * Samples must be stored concatenated in a flat buffer `samplesBuffer`,
137
+ * supplied with an array of sizes `samplesSizes`, providing the size of each sample in order.
138
+ *
139
+ * dictContentSize must be >= ZDICT_CONTENTSIZE_MIN bytes.
140
+ * maxDictSize must be >= dictContentSize, and must be >= ZDICT_DICTSIZE_MIN bytes.
141
+ *
142
+ * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`),
143
+ * or an error code, which can be tested by ZDICT_isError().
144
+ * Note: ZDICT_finalizeDictionary() will push notifications into stderr if instructed to, using notificationLevel>0.
145
+ * Note 2: dictBuffer and dictContent can overlap
146
+ */
147
+ #define ZDICT_CONTENTSIZE_MIN 128
148
+ #define ZDICT_DICTSIZE_MIN 256
160
149
  ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
161
- const void* customDictContent, size_t dictContentSize,
150
+ const void* dictContent, size_t dictContentSize,
162
151
  const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
163
152
  ZDICT_params_t parameters);
164
153
 
165
-
154
+ typedef struct {
155
+ unsigned selectivityLevel; /* 0 means default; larger => select more => larger dictionary */
156
+ ZDICT_params_t zParams;
157
+ } ZDICT_legacy_params_t;
158
+
159
+ /*! ZDICT_trainFromBuffer_legacy():
160
+ * Train a dictionary from an array of samples.
161
+ * Samples must be stored concatenated in a single flat buffer `samplesBuffer`,
162
+ * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.
163
+ * The resulting dictionary will be saved into `dictBuffer`.
164
+ * `parameters` is optional and can be provided with values set to 0 to mean "default".
165
+ * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
166
+ * or an error code, which can be tested with ZDICT_isError().
167
+ * Tips: In general, a reasonable dictionary has a size of ~ 100 KB.
168
+ * It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`.
169
+ * In general, it's recommended to provide a few thousands samples, but this can vary a lot.
170
+ * It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
171
+ * Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0.
172
+ */
173
+ ZDICTLIB_API size_t ZDICT_trainFromBuffer_legacy(
174
+ void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
175
+ const size_t *samplesSizes, unsigned nbSamples, ZDICT_legacy_params_t parameters);
166
176
 
167
177
  /* Deprecation warnings */
168
178
  /* It is generally possible to disable deprecation warnings from compiler,
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_LEGACY_H
@@ -123,6 +124,7 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
123
124
  const void* dict,size_t dictSize)
124
125
  {
125
126
  U32 const version = ZSTD_isLegacy(src, compressedSize);
127
+ (void)dst; (void)dstCapacity; (void)dict; (void)dictSize; /* unused when ZSTD_LEGACY_SUPPORT >= 8 */
126
128
  switch(version)
127
129
  {
128
130
  #if (ZSTD_LEGACY_SUPPORT <= 1)
@@ -223,6 +225,7 @@ MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
223
225
  case 1 :
224
226
  case 2 :
225
227
  case 3 :
228
+ (void)legacyContext;
226
229
  return ERROR(version_unsupported);
227
230
  #if (ZSTD_LEGACY_SUPPORT <= 4)
228
231
  case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
@@ -250,6 +253,7 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U
250
253
  case 1 :
251
254
  case 2 :
252
255
  case 3 :
256
+ (void)dict; (void)dictSize;
253
257
  return 0;
254
258
  #if (ZSTD_LEGACY_SUPPORT <= 4)
255
259
  case 4 :
@@ -306,6 +310,7 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
306
310
  case 1 :
307
311
  case 2 :
308
312
  case 3 :
313
+ (void)legacyContext; (void)output; (void)input;
309
314
  return ERROR(version_unsupported);
310
315
  #if (ZSTD_LEGACY_SUPPORT <= 4)
311
316
  case 4 :
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
 
@@ -338,7 +339,7 @@ typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
338
339
  /****************************************************************
339
340
  * Internal functions
340
341
  ****************************************************************/
341
- FORCE_INLINE unsigned FSE_highbit32 (register U32 val)
342
+ FORCE_INLINE unsigned FSE_highbit32 (U32 val)
342
343
  {
343
344
  # if defined(_MSC_VER) /* Visual */
344
345
  unsigned long r;
@@ -1432,7 +1433,7 @@ typedef struct ZSTD_Cctx_s
1432
1433
  #else
1433
1434
  U32 hashTable[HASH_TABLESIZE];
1434
1435
  #endif
1435
- BYTE buffer[WORKPLACESIZE];
1436
+ BYTE buffer[WORKPLACESIZE];
1436
1437
  } cctxi_t;
1437
1438
 
1438
1439
 
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_V01_H_28739879432
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
 
@@ -329,18 +330,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
329
330
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
330
331
 
331
332
 
332
- /*
333
- * Start by invoking BIT_initDStream().
334
- * A chunk of the bitStream is then stored into a local register.
335
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
336
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
337
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
338
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
339
- * Otherwise, it can be less than that, so proceed accordingly.
340
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
341
- */
342
-
343
-
344
333
  /******************************************
345
334
  * unsafe API
346
335
  ******************************************/
@@ -352,7 +341,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
352
341
  /****************************************************************
353
342
  * Helper functions
354
343
  ****************************************************************/
355
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
344
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
356
345
  {
357
346
  # if defined(_MSC_VER) /* Visual */
358
347
  unsigned long r=0;
@@ -426,13 +415,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
426
415
  return srcSize;
427
416
  }
428
417
 
429
- /*!BIT_lookBits
430
- * Provides next n bits from local register
431
- * local register is not modified (bits are still present for next read/look)
432
- * On 32-bits, maxNbBits==25
433
- * On 64-bits, maxNbBits==57
434
- * @return : value extracted
435
- */
436
418
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
437
419
  {
438
420
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -452,11 +434,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
452
434
  bitD->bitsConsumed += nbBits;
453
435
  }
454
436
 
455
- /*!BIT_readBits
456
- * Read next n bits from local register.
457
- * pay attention to not read more than nbBits contained into local register.
458
- * @return : extracted value.
459
- */
460
437
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
461
438
  {
462
439
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -475,8 +452,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
475
452
 
476
453
  MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
477
454
  {
478
- if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
479
- return BIT_DStream_overflow;
455
+ if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
456
+ return BIT_DStream_overflow;
480
457
 
481
458
  if (bitD->ptr >= bitD->start + sizeof(bitD->bitContainer))
482
459
  {
@@ -694,55 +671,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
694
671
 
695
672
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
696
673
 
697
- /*
698
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
699
- You will decode FSE-encoded symbols from the bitStream,
700
- and also any other bitFields you put in, **in reverse order**.
701
-
702
- You will need a few variables to track your bitStream. They are :
703
-
704
- BIT_DStream_t DStream; // Stream context
705
- FSE_DState_t DState; // State context. Multiple ones are possible
706
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
707
-
708
- The first thing to do is to init the bitStream.
709
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
710
-
711
- You should then retrieve your initial state(s)
712
- (in reverse flushing order if you have several ones) :
713
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
714
-
715
- You can then decode your data, symbol after symbol.
716
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
717
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
718
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
719
-
720
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
721
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
722
- size_t bitField = BIT_readBits(&DStream, nbBits);
723
-
724
- All above operations only read from local register (which size depends on size_t).
725
- Refueling the register from memory is manually performed by the reload method.
726
- endSignal = FSE_reloadDStream(&DStream);
727
-
728
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
729
- BIT_DStream_unfinished : there is still some data left into the DStream.
730
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
731
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
732
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
733
-
734
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
735
- to properly detect the exact end of stream.
736
- After each decoded symbol, check if DStream is fully consumed using this simple test :
737
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
738
-
739
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
740
- Checking if DStream has reached its end is performed by :
741
- BIT_endOfDStream(&DStream);
742
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
743
- FSE_endOfDState(&DState);
744
- */
745
-
746
674
 
747
675
  /******************************************
748
676
  * FSE unsafe API
@@ -1334,8 +1262,8 @@ static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsi
1334
1262
  else
1335
1263
  {
1336
1264
  bitCount -= (int)(8 * (iend - 4 - ip));
1337
- ip = iend - 4;
1338
- }
1265
+ ip = iend - 4;
1266
+ }
1339
1267
  bitStream = MEM_readLE32(ip) >> (bitCount & 31);
1340
1268
  }
1341
1269
  }
@@ -2040,7 +1968,7 @@ static size_t HUF_readDTableX4 (U32* DTable, const void* src, size_t srcSize)
2040
1968
  rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
2041
1969
  }
2042
1970
 
2043
- /* Build rankVal */
1971
+ /* Build rankVal */
2044
1972
  {
2045
1973
  const U32 minBits = tableLog+1 - maxW;
2046
1974
  U32 nextRankVal = 0;
@@ -2374,7 +2302,7 @@ static size_t HUF_readDTableX6 (U32* DTable, const void* src, size_t srcSize)
2374
2302
  rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
2375
2303
  }
2376
2304
 
2377
- /* Build rankVal */
2305
+ /* Build rankVal */
2378
2306
  {
2379
2307
  const U32 minBits = tableLog+1 - maxW;
2380
2308
  U32 nextRankVal = 0;
@@ -2948,14 +2876,14 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
2948
2876
  const size_t litSize = (MEM_readLE32(istart) & 0xFFFFFF) >> 2; /* no buffer issue : srcSize >= MIN_CBLOCK_SIZE */
2949
2877
  if (litSize > srcSize-11) /* risk of reading too far with wildcopy */
2950
2878
  {
2951
- if (litSize > srcSize-3) return ERROR(corruption_detected);
2952
- memcpy(dctx->litBuffer, istart, litSize);
2953
- dctx->litPtr = dctx->litBuffer;
2954
- dctx->litSize = litSize;
2955
- memset(dctx->litBuffer + dctx->litSize, 0, 8);
2956
- return litSize+3;
2957
- }
2958
- /* direct reference into compressed stream */
2879
+ if (litSize > srcSize-3) return ERROR(corruption_detected);
2880
+ memcpy(dctx->litBuffer, istart, litSize);
2881
+ dctx->litPtr = dctx->litBuffer;
2882
+ dctx->litSize = litSize;
2883
+ memset(dctx->litBuffer + dctx->litSize, 0, 8);
2884
+ return litSize+3;
2885
+ }
2886
+ /* direct reference into compressed stream */
2959
2887
  dctx->litPtr = istart+3;
2960
2888
  dctx->litSize = litSize;
2961
2889
  return litSize+3;
@@ -3515,13 +3443,13 @@ static size_t ZSTD_decompressContinue(ZSTD_DCtx* ctx, void* dst, size_t maxDstSi
3515
3443
 
3516
3444
  unsigned ZSTDv02_isError(size_t code)
3517
3445
  {
3518
- return ZSTD_isError(code);
3446
+ return ZSTD_isError(code);
3519
3447
  }
3520
3448
 
3521
3449
  size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
3522
3450
  const void* src, size_t compressedSize)
3523
3451
  {
3524
- return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
3452
+ return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
3525
3453
  }
3526
3454
 
3527
3455
  size_t ZSTDv02_findFrameCompressedSize(const void *src, size_t compressedSize)
@@ -3531,25 +3459,25 @@ size_t ZSTDv02_findFrameCompressedSize(const void *src, size_t compressedSize)
3531
3459
 
3532
3460
  ZSTDv02_Dctx* ZSTDv02_createDCtx(void)
3533
3461
  {
3534
- return (ZSTDv02_Dctx*)ZSTD_createDCtx();
3462
+ return (ZSTDv02_Dctx*)ZSTD_createDCtx();
3535
3463
  }
3536
3464
 
3537
3465
  size_t ZSTDv02_freeDCtx(ZSTDv02_Dctx* dctx)
3538
3466
  {
3539
- return ZSTD_freeDCtx((ZSTD_DCtx*)dctx);
3467
+ return ZSTD_freeDCtx((ZSTD_DCtx*)dctx);
3540
3468
  }
3541
3469
 
3542
3470
  size_t ZSTDv02_resetDCtx(ZSTDv02_Dctx* dctx)
3543
3471
  {
3544
- return ZSTD_resetDCtx((ZSTD_DCtx*)dctx);
3472
+ return ZSTD_resetDCtx((ZSTD_DCtx*)dctx);
3545
3473
  }
3546
3474
 
3547
3475
  size_t ZSTDv02_nextSrcSizeToDecompress(ZSTDv02_Dctx* dctx)
3548
3476
  {
3549
- return ZSTD_nextSrcSizeToDecompress((ZSTD_DCtx*)dctx);
3477
+ return ZSTD_nextSrcSizeToDecompress((ZSTD_DCtx*)dctx);
3550
3478
  }
3551
3479
 
3552
3480
  size_t ZSTDv02_decompressContinue(ZSTDv02_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
3553
3481
  {
3554
- return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
3482
+ return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
3555
3483
  }
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_V02_H_4174539423