extzstd 0.0.3.CONCEPT → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/LICENSE +6 -6
  4. data/README.md +35 -22
  5. data/contrib/zstd/LICENSE +13 -9
  6. data/contrib/zstd/README.md +37 -44
  7. data/contrib/zstd/common/entropy_common.c +33 -39
  8. data/contrib/zstd/common/error_private.c +43 -0
  9. data/contrib/zstd/common/error_private.h +11 -60
  10. data/contrib/zstd/common/fse.h +11 -5
  11. data/contrib/zstd/common/fse_decompress.c +14 -16
  12. data/contrib/zstd/common/huf.h +1 -1
  13. data/contrib/zstd/common/mem.h +36 -43
  14. data/contrib/zstd/common/xxhash.c +31 -18
  15. data/contrib/zstd/common/xxhash.h +71 -35
  16. data/contrib/zstd/common/zbuff.h +29 -35
  17. data/contrib/zstd/common/zstd_common.c +24 -32
  18. data/contrib/zstd/common/zstd_errors.h +60 -0
  19. data/contrib/zstd/common/zstd_internal.h +109 -80
  20. data/contrib/zstd/compress/fse_compress.c +9 -6
  21. data/contrib/zstd/compress/huf_compress.c +30 -74
  22. data/contrib/zstd/compress/zbuff_compress.c +43 -51
  23. data/contrib/zstd/compress/zstd_compress.c +953 -763
  24. data/contrib/zstd/compress/zstd_opt.h +115 -261
  25. data/contrib/zstd/decompress/huf_decompress.c +29 -40
  26. data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
  27. data/contrib/zstd/decompress/zstd_decompress.c +976 -496
  28. data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
  29. data/contrib/zstd/dictBuilder/zdict.c +194 -229
  30. data/contrib/zstd/dictBuilder/zdict.h +66 -68
  31. data/contrib/zstd/legacy/zstd_legacy.h +168 -49
  32. data/contrib/zstd/legacy/zstd_v01.c +95 -178
  33. data/contrib/zstd/legacy/zstd_v01.h +12 -32
  34. data/contrib/zstd/legacy/zstd_v02.c +48 -274
  35. data/contrib/zstd/legacy/zstd_v02.h +12 -32
  36. data/contrib/zstd/legacy/zstd_v03.c +48 -274
  37. data/contrib/zstd/legacy/zstd_v03.h +12 -32
  38. data/contrib/zstd/legacy/zstd_v04.c +63 -320
  39. data/contrib/zstd/legacy/zstd_v04.h +13 -33
  40. data/contrib/zstd/legacy/zstd_v05.c +80 -345
  41. data/contrib/zstd/legacy/zstd_v05.h +9 -31
  42. data/contrib/zstd/legacy/zstd_v06.c +48 -458
  43. data/contrib/zstd/legacy/zstd_v06.h +41 -67
  44. data/contrib/zstd/legacy/zstd_v07.c +4544 -0
  45. data/contrib/zstd/legacy/zstd_v07.h +173 -0
  46. data/contrib/zstd/zstd.h +640 -0
  47. data/ext/extconf.rb +7 -3
  48. data/ext/extzstd.c +263 -106
  49. data/ext/extzstd.h +8 -6
  50. data/ext/extzstd_nogvls.h +0 -117
  51. data/ext/extzstd_stream.c +347 -0
  52. data/ext/zstd_common.c +8 -0
  53. data/ext/zstd_compress.c +6 -0
  54. data/ext/zstd_decompress.c +5 -0
  55. data/ext/zstd_dictbuilder.c +5 -0
  56. data/ext/zstd_legacy_v07.c +1 -0
  57. data/gemstub.rb +18 -16
  58. data/lib/extzstd/version.rb +1 -1
  59. data/lib/extzstd.rb +77 -43
  60. data/test/test_basic.rb +11 -6
  61. metadata +23 -10
  62. data/contrib/zstd/common/error_public.h +0 -77
  63. data/contrib/zstd/common/zstd.h +0 -475
  64. data/ext/extzstd_buffered.c +0 -265
  65. data/ext/zstd_amalgam.c +0 -18
@@ -1,33 +1,20 @@
1
- /*
2
- Buffered version of Zstd compression library
3
- Copyright (C) 2015-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
- * Redistributions of source code must retain the above copyright
11
- notice, this list of conditions and the following disclaimer.
12
- * Redistributions in binary form must reproduce the above
13
- copyright notice, this list of conditions and the following disclaimer
14
- in the documentation and/or other materials provided with the
15
- distribution.
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- You can contact the author at :
29
- - zstd homepage : http://www.zstd.net/
30
- */
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
+ * NOTES/WARNINGS
12
+ *****************************************************************/
13
+ /* The streaming API defined here will soon be deprecated by the
14
+ * new one in 'zstd.h'; consider migrating towards newer streaming
15
+ * API. See 'lib/README.md'.
16
+ *****************************************************************/
17
+
31
18
  #ifndef ZSTD_BUFFERED_H_23987
32
19
  #define ZSTD_BUFFERED_H_23987
33
20
 
@@ -56,6 +43,12 @@ extern "C" {
56
43
  /* *************************************
57
44
  * Streaming functions
58
45
  ***************************************/
46
+ /* This is the easier "buffered" streaming API,
47
+ * using an internal buffer to lift all restrictions on user-provided buffers
48
+ * which can be any size, any place, for both input and output.
49
+ * ZBUFF and ZSTD are 100% interoperable,
50
+ * frames created by one can be decoded by the other one */
51
+
59
52
  typedef struct ZBUFF_CCtx_s ZBUFF_CCtx;
60
53
  ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx(void);
61
54
  ZSTDLIB_API size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx);
@@ -133,8 +126,9 @@ ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
133
126
  * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
134
127
  * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
135
128
  * The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
136
- * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),
137
- * or 0 when a frame is completely decoded,
129
+ * @return : 0 when a frame is completely decoded and fully flushed,
130
+ * 1 when there is still some data left within internal buffer to flush,
131
+ * >1 when more data is expected, with value being a suggested next input size (it's just a hint, which helps latency),
138
132
  * or an error code, which can be tested using ZBUFF_isError().
139
133
  *
140
134
  * Hint : recommended buffer sizes (not compulsory) : ZBUFF_recommendedDInSize() and ZBUFF_recommendedDOutSize()
@@ -168,11 +162,11 @@ ZSTDLIB_API size_t ZBUFF_recommendedDOutSize(void);
168
162
  * ==================================================================================== */
169
163
 
170
164
  /*--- Dependency ---*/
171
- #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
165
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */
172
166
  #include "zstd.h"
173
167
 
174
168
 
175
- /*--- External memory ---*/
169
+ /*--- Custom memory allocator ---*/
176
170
  /*! ZBUFF_createCCtx_advanced() :
177
171
  * Create a ZBUFF compression context using external alloc and free functions */
178
172
  ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem);
@@ -182,7 +176,7 @@ ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem);
182
176
  ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem);
183
177
 
184
178
 
185
- /*--- Advanced Streaming function ---*/
179
+ /*--- Advanced Streaming Initialization ---*/
186
180
  ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
187
181
  const void* dict, size_t dictSize,
188
182
  ZSTD_parameters params, unsigned long long pledgedSrcSize);
@@ -1,33 +1,12 @@
1
- /*
2
- Common functions of Zstd compression library
3
- Copyright (C) 2015-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
- * Redistributions of source code must retain the above copyright
11
- notice, this list of conditions and the following disclaimer.
12
- * Redistributions in binary form must reproduce the above
13
- copyright notice, this list of conditions and the following disclaimer
14
- in the documentation and/or other materials provided with the
15
- distribution.
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- You can contact the author at :
29
- - zstd homepage : http://www.zstd.net/
30
- */
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
+
31
10
 
32
11
 
33
12
  /*-*************************************
@@ -75,17 +54,30 @@ const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(error
75
54
 
76
55
 
77
56
 
57
+ /*=**************************************************************
58
+ * Custom allocator
59
+ ****************************************************************/
60
+ /* default uses stdlib */
78
61
  void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
79
62
  {
80
63
  void* address = malloc(size);
81
64
  (void)opaque;
82
- /* printf("alloc %p, %d opaque=%p \n", address, (int)size, opaque); */
83
65
  return address;
84
66
  }
85
67
 
86
68
  void ZSTD_defaultFreeFunction(void* opaque, void* address)
87
69
  {
88
70
  (void)opaque;
89
- /* if (address) printf("free %p opaque=%p \n", address, opaque); */
90
71
  free(address);
91
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
+ }
@@ -0,0 +1,60 @@
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,37 +1,47 @@
1
- /*
2
- zstd_internal - common functions to include
3
- Header File for include
4
- Copyright (C) 2014-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
- * 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
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
- You can contact the author at :
30
- - zstd homepage : https://www.zstd.net
31
- */
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
+
32
10
  #ifndef ZSTD_CCOMMON_H_MODULE
33
11
  #define ZSTD_CCOMMON_H_MODULE
34
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
+
35
45
  /*-*************************************
36
46
  * Dependencies
37
47
  ***************************************/
@@ -42,33 +52,24 @@
42
52
 
43
53
 
44
54
  /*-*************************************
45
- * Common macros
55
+ * shared macros
46
56
  ***************************************/
47
57
  #define MIN(a,b) ((a)<(b) ? (a) : (b))
48
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 */
49
61
 
50
62
 
51
63
  /*-*************************************
52
64
  * Common constants
53
65
  ***************************************/
54
- #define ZSTD_OPT_DEBUG 0 /* 3 = compression stats; 5 = check encoded sequences; 9 = full logs */
55
- #include <stdio.h>
56
- #if defined(ZSTD_OPT_DEBUG) && ZSTD_OPT_DEBUG>=9
57
- #define ZSTD_LOG_PARSER(...) printf(__VA_ARGS__)
58
- #define ZSTD_LOG_ENCODE(...) printf(__VA_ARGS__)
59
- #define ZSTD_LOG_BLOCK(...) printf(__VA_ARGS__)
60
- #else
61
- #define ZSTD_LOG_PARSER(...)
62
- #define ZSTD_LOG_ENCODE(...)
63
- #define ZSTD_LOG_BLOCK(...)
64
- #endif
65
-
66
66
  #define ZSTD_OPT_NUM (1<<12)
67
- #define ZSTD_DICT_MAGIC 0xEC30A437 /* v0.7 */
67
+ #define ZSTD_DICT_MAGIC 0xEC30A437 /* v0.7+ */
68
68
 
69
- #define ZSTD_REP_NUM 3
70
- #define ZSTD_REP_INIT ZSTD_REP_NUM
71
- #define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
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)
72
73
  static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
73
74
 
74
75
  #define KB *(1 <<10)
@@ -88,13 +89,13 @@ static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
88
89
 
89
90
  #define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
90
91
  static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
91
- typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
92
+ typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
92
93
 
93
94
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
94
95
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
95
96
 
96
97
  #define HufLog 12
97
- typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t;
98
+ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
98
99
 
99
100
  #define LONGNBSEQ 0x7F00
100
101
 
@@ -111,18 +112,14 @@ typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t;
111
112
  #define LLFSELog 9
112
113
  #define OffFSELog 8
113
114
 
114
- #define FSE_ENCODING_RAW 0
115
- #define FSE_ENCODING_RLE 1
116
- #define FSE_ENCODING_STATIC 2
117
- #define FSE_ENCODING_DYNAMIC 3
118
-
119
115
  static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120
116
  1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
121
117
  13,14,15,16 };
122
118
  static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
123
119
  2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
124
120
  -1,-1,-1,-1 };
125
- static const U32 LL_defaultNormLog = 6;
121
+ #define LL_DEFAULTNORMLOG 6 /* for static allocation */
122
+ static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
126
123
 
127
124
  static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128
125
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -132,11 +129,13 @@ static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1,
132
129
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
133
130
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
134
131
  -1,-1,-1,-1,-1 };
135
- static const U32 ML_defaultNormLog = 6;
132
+ #define ML_DEFAULTNORMLOG 6 /* for static allocation */
133
+ static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
136
134
 
137
135
  static const S16 OF_defaultNorm[MaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
138
136
  1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
139
- static const U32 OF_defaultNormLog = 5;
137
+ #define OF_DEFAULTNORMLOG 5 /* for static allocation */
138
+ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
140
139
 
141
140
 
142
141
  /*-*******************************************
@@ -158,6 +157,16 @@ MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, size_t length)
158
157
  while (op < oend);
159
158
  }
160
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
+
161
170
 
162
171
  /*-*******************************************
163
172
  * Private interfaces
@@ -174,32 +183,25 @@ typedef struct {
174
183
  U32 off;
175
184
  U32 mlen;
176
185
  U32 litlen;
177
- U32 rep[ZSTD_REP_INIT];
186
+ U32 rep[ZSTD_REP_NUM];
178
187
  } ZSTD_optimal_t;
179
188
 
180
- #if ZSTD_OPT_DEBUG == 3
181
- #include ".debug/zstd_stats.h"
182
- #else
183
- struct ZSTD_stats_s { U32 unused; };
184
- MEM_STATIC void ZSTD_statsPrint(ZSTD_stats_t* stats, U32 searchLength) { (void)stats; (void)searchLength; }
185
- MEM_STATIC void ZSTD_statsInit(ZSTD_stats_t* stats) { (void)stats; }
186
- MEM_STATIC void ZSTD_statsResetFreqs(ZSTD_stats_t* stats) { (void)stats; }
187
- MEM_STATIC void ZSTD_statsUpdatePrices(ZSTD_stats_t* stats, size_t litLength, const BYTE* literals, size_t offset, size_t matchLength) { (void)stats; (void)litLength; (void)literals; (void)offset; (void)matchLength; }
188
- #endif /* #if ZSTD_OPT_DEBUG == 3 */
189
+
190
+ typedef struct seqDef_s {
191
+ U32 offset;
192
+ U16 litLength;
193
+ U16 matchLength;
194
+ } seqDef;
195
+
189
196
 
190
197
  typedef struct {
191
- void* buffer;
192
- U32* offsetStart;
193
- U32* offset;
194
- BYTE* offCodeStart;
198
+ seqDef* sequencesStart;
199
+ seqDef* sequences;
195
200
  BYTE* litStart;
196
201
  BYTE* lit;
197
- U16* litLengthStart;
198
- U16* litLength;
199
- BYTE* llCodeStart;
200
- U16* matchLengthStart;
201
- U16* matchLength;
202
- BYTE* mlCodeStart;
202
+ BYTE* llCode;
203
+ BYTE* mlCode;
204
+ BYTE* ofCode;
203
205
  U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
204
206
  U32 longLengthPos;
205
207
  /* opt */
@@ -223,16 +225,43 @@ typedef struct {
223
225
  U32 cachedPrice;
224
226
  U32 cachedLitLength;
225
227
  const BYTE* cachedLiterals;
226
- ZSTD_stats_t stats;
227
228
  } seqStore_t;
228
229
 
229
230
  const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
230
- void ZSTD_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq);
231
+ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
231
232
  int ZSTD_isSkipFrame(ZSTD_DCtx* dctx);
232
233
 
233
234
  /* custom memory allocation functions */
234
235
  void* ZSTD_defaultAllocFunction(void* opaque, size_t size);
235
236
  void ZSTD_defaultFreeFunction(void* opaque, void* address);
236
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
+
237
266
 
238
267
  #endif /* ZSTD_CCOMMON_H_MODULE */
@@ -41,12 +41,15 @@
41
41
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
42
42
  # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
43
43
  #else
44
- # ifdef __GNUC__
45
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
46
- # define FORCE_INLINE static inline __attribute__((always_inline))
44
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
45
+ # ifdef __GNUC__
46
+ # define FORCE_INLINE static inline __attribute__((always_inline))
47
+ # else
48
+ # define FORCE_INLINE static inline
49
+ # endif
47
50
  # else
48
- # define FORCE_INLINE static inline
49
- # endif
51
+ # define FORCE_INLINE static
52
+ # endif /* __STDC_VERSION__ */
50
53
  #endif
51
54
 
52
55
 
@@ -190,7 +193,7 @@ size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
190
193
  return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
191
194
  }
192
195
 
193
- static short FSE_abs(short a) { return a<0 ? -a : a; }
196
+ static short FSE_abs(short a) { return (short)(a<0 ? -a : a); }
194
197
 
195
198
  static size_t FSE_writeNCount_generic (void* header, size_t headerBufferSize,
196
199
  const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog,