extzstd 0.1.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
 
@@ -12,62 +13,74 @@
12
13
  /*-*************************************
13
14
  * Dependencies
14
15
  ***************************************/
15
- #include <stdlib.h> /* malloc */
16
+ #include <stdlib.h> /* malloc, calloc, free */
17
+ #include <string.h> /* memset */
16
18
  #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 "zstd_internal.h"
19
20
 
20
21
 
21
22
  /*-****************************************
22
23
  * Version
23
24
  ******************************************/
24
- unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
25
+ unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
26
+
27
+ const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
25
28
 
26
29
 
27
30
  /*-****************************************
28
31
  * ZSTD Error Management
29
32
  ******************************************/
30
33
  /*! ZSTD_isError() :
31
- * tells if a return value is an error code */
34
+ * tells if a return value is an error code */
32
35
  unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
33
36
 
34
37
  /*! ZSTD_getErrorName() :
35
- * provides error code string from function result (useful for debugging) */
38
+ * provides error code string from function result (useful for debugging) */
36
39
  const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
37
40
 
38
41
  /*! ZSTD_getError() :
39
- * convert a `size_t` function result into a proper ZSTD_errorCode enum */
42
+ * convert a `size_t` function result into a proper ZSTD_errorCode enum */
40
43
  ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
41
44
 
42
45
  /*! ZSTD_getErrorString() :
43
- * provides error code string from enum */
46
+ * provides error code string from enum */
44
47
  const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
45
48
 
49
+ /*! g_debuglog_enable :
50
+ * turn on/off debug traces (global switch) */
51
+ #if defined(ZSTD_DEBUG) && (ZSTD_DEBUG >= 2)
52
+ int g_debuglog_enable = 1;
53
+ #endif
54
+
46
55
 
47
56
  /*=**************************************************************
48
57
  * Custom allocator
49
58
  ****************************************************************/
50
- /* default uses stdlib */
51
- void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
52
- {
53
- void* address = malloc(size);
54
- (void)opaque;
55
- return address;
56
- }
57
-
58
- void ZSTD_defaultFreeFunction(void* opaque, void* address)
59
+ void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
59
60
  {
60
- (void)opaque;
61
- free(address);
61
+ if (customMem.customAlloc)
62
+ return customMem.customAlloc(customMem.opaque, size);
63
+ return malloc(size);
62
64
  }
63
65
 
64
- void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
66
+ void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
65
67
  {
66
- return customMem.customAlloc(customMem.opaque, size);
68
+ if (customMem.customAlloc) {
69
+ /* calloc implemented as malloc+memset;
70
+ * not as efficient as calloc, but next best guess for custom malloc */
71
+ void* const ptr = customMem.customAlloc(customMem.opaque, size);
72
+ memset(ptr, 0, size);
73
+ return ptr;
74
+ }
75
+ return calloc(1, size);
67
76
  }
68
77
 
69
78
  void ZSTD_free(void* ptr, ZSTD_customMem customMem)
70
79
  {
71
- if (ptr!=NULL)
72
- customMem.customFree(customMem.opaque, ptr);
80
+ if (ptr!=NULL) {
81
+ if (customMem.customFree)
82
+ customMem.customFree(customMem.opaque, ptr);
83
+ else
84
+ free(ptr);
85
+ }
73
86
  }
@@ -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_ERRORS_H_398273423
@@ -19,10 +20,12 @@ extern "C" {
19
20
 
20
21
 
21
22
  /* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
22
- #if defined(__GNUC__) && (__GNUC__ >= 4)
23
- # define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
24
- #else
25
- # define ZSTDERRORLIB_VISIBILITY
23
+ #ifndef ZSTDERRORLIB_VISIBILITY
24
+ # if defined(__GNUC__) && (__GNUC__ >= 4)
25
+ # define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
26
+ # else
27
+ # define ZSTDERRORLIB_VISIBILITY
28
+ # endif
26
29
  #endif
27
30
  #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
28
31
  # define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY
@@ -33,38 +36,44 @@ extern "C" {
33
36
  #endif
34
37
 
35
38
  /*-****************************************
36
- * error codes list
37
- ******************************************/
39
+ * error codes list
40
+ * note : this API is still considered unstable
41
+ * and shall not be used with a dynamic library.
42
+ * only static linking is allowed
43
+ ******************************************/
38
44
  typedef enum {
39
- ZSTD_error_no_error,
40
- ZSTD_error_GENERIC,
41
- ZSTD_error_prefix_unknown,
42
- ZSTD_error_version_unsupported,
43
- ZSTD_error_parameter_unknown,
44
- ZSTD_error_frameParameter_unsupported,
45
- ZSTD_error_frameParameter_unsupportedBy32bits,
46
- ZSTD_error_frameParameter_windowTooLarge,
47
- ZSTD_error_compressionParameter_unsupported,
48
- ZSTD_error_init_missing,
49
- ZSTD_error_memory_allocation,
50
- ZSTD_error_stage_wrong,
51
- ZSTD_error_dstSize_tooSmall,
52
- ZSTD_error_srcSize_wrong,
53
- ZSTD_error_corruption_detected,
54
- ZSTD_error_checksum_wrong,
55
- ZSTD_error_tableLog_tooLarge,
56
- ZSTD_error_maxSymbolValue_tooLarge,
57
- ZSTD_error_maxSymbolValue_tooSmall,
58
- ZSTD_error_dictionary_corrupted,
59
- ZSTD_error_dictionary_wrong,
60
- ZSTD_error_maxCode
45
+ ZSTD_error_no_error = 0,
46
+ ZSTD_error_GENERIC = 1,
47
+ ZSTD_error_prefix_unknown = 10,
48
+ ZSTD_error_version_unsupported = 12,
49
+ ZSTD_error_frameParameter_unsupported = 14,
50
+ ZSTD_error_frameParameter_windowTooLarge = 16,
51
+ ZSTD_error_corruption_detected = 20,
52
+ ZSTD_error_checksum_wrong = 22,
53
+ ZSTD_error_dictionary_corrupted = 30,
54
+ ZSTD_error_dictionary_wrong = 32,
55
+ ZSTD_error_dictionaryCreation_failed = 34,
56
+ ZSTD_error_parameter_unsupported = 40,
57
+ ZSTD_error_parameter_outOfBound = 42,
58
+ ZSTD_error_tableLog_tooLarge = 44,
59
+ ZSTD_error_maxSymbolValue_tooLarge = 46,
60
+ ZSTD_error_maxSymbolValue_tooSmall = 48,
61
+ ZSTD_error_stage_wrong = 60,
62
+ ZSTD_error_init_missing = 62,
63
+ ZSTD_error_memory_allocation = 64,
64
+ ZSTD_error_dstSize_tooSmall = 70,
65
+ ZSTD_error_srcSize_wrong = 72,
66
+ /* following error codes are not stable and may be removed or changed in a future version */
67
+ ZSTD_error_frameIndex_tooLarge = 100,
68
+ ZSTD_error_seekableIO = 102,
69
+ ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
61
70
  } ZSTD_ErrorCode;
62
71
 
63
72
  /*! ZSTD_getErrorCode() :
64
73
  convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
65
- which can be used to compare directly with enum list published into "error_public.h" */
74
+ which can be used to compare with enum list published above */
66
75
  ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
67
- ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code);
76
+ ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
68
77
 
69
78
 
70
79
  #if defined (__cplusplus)
@@ -1,63 +1,87 @@
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_CCOMMON_H_MODULE
11
12
  #define ZSTD_CCOMMON_H_MODULE
12
13
 
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
-
14
+ /* this module contains definitions which must be identical
15
+ * across compression, decompression and dictBuilder.
16
+ * It also contains a few functions useful to at least 2 of them
17
+ * and which benefit from being inlined */
44
18
 
45
19
  /*-*************************************
46
20
  * Dependencies
47
21
  ***************************************/
22
+ #include "compiler.h"
48
23
  #include "mem.h"
49
24
  #include "error_private.h"
50
25
  #define ZSTD_STATIC_LINKING_ONLY
51
26
  #include "zstd.h"
27
+ #define FSE_STATIC_LINKING_ONLY
28
+ #include "fse.h"
29
+ #define HUF_STATIC_LINKING_ONLY
30
+ #include "huf.h"
52
31
  #ifndef XXH_STATIC_LINKING_ONLY
53
- # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
32
+ # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
33
+ #endif
34
+ #include "xxhash.h" /* XXH_reset, update, digest */
35
+
36
+
37
+ #if defined (__cplusplus)
38
+ extern "C" {
39
+ #endif
40
+
41
+
42
+ /*-*************************************
43
+ * Debug
44
+ ***************************************/
45
+ #if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1)
46
+ # include <assert.h>
47
+ #else
48
+ # ifndef assert
49
+ # define assert(condition) ((void)0)
50
+ # endif
51
+ #endif
52
+
53
+ #define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; }
54
+
55
+ #if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2)
56
+ # include <stdio.h>
57
+ extern int g_debuglog_enable;
58
+ /* recommended values for ZSTD_DEBUG display levels :
59
+ * 1 : no display, enables assert() only
60
+ * 2 : reserved for currently active debug path
61
+ * 3 : events once per object lifetime (CCtx, CDict, etc.)
62
+ * 4 : events once per frame
63
+ * 5 : events once per block
64
+ * 6 : events once per sequence (*very* verbose) */
65
+ # define RAWLOG(l, ...) { \
66
+ if ((g_debuglog_enable) & (l<=ZSTD_DEBUG)) { \
67
+ fprintf(stderr, __VA_ARGS__); \
68
+ } }
69
+ # define DEBUGLOG(l, ...) { \
70
+ if ((g_debuglog_enable) & (l<=ZSTD_DEBUG)) { \
71
+ fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
72
+ fprintf(stderr, " \n"); \
73
+ } }
74
+ #else
75
+ # define RAWLOG(l, ...) {} /* disabled */
76
+ # define DEBUGLOG(l, ...) {} /* disabled */
54
77
  #endif
55
- #include "xxhash.h" /* XXH_reset, update, digest */
56
78
 
57
79
 
58
80
  /*-*************************************
59
81
  * shared macros
60
82
  ***************************************/
83
+ #undef MIN
84
+ #undef MAX
61
85
  #define MIN(a,b) ((a)<(b) ? (a) : (b))
62
86
  #define MAX(a,b) ((a)>(b) ? (a) : (b))
63
87
  #define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
@@ -68,12 +92,9 @@
68
92
  * Common constants
69
93
  ***************************************/
70
94
  #define ZSTD_OPT_NUM (1<<12)
71
- #define ZSTD_DICT_MAGIC 0xEC30A437 /* v0.7+ */
72
95
 
73
96
  #define ZSTD_REP_NUM 3 /* number of repcodes */
74
- #define ZSTD_REP_CHECK (ZSTD_REP_NUM) /* number of repcodes to check by the optimal parser */
75
97
  #define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
76
- #define ZSTD_REP_MOVE_OPT (ZSTD_REP_NUM)
77
98
  static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
78
99
 
79
100
  #define KB *(1 <<10)
@@ -88,9 +109,13 @@ static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
88
109
  #define BIT0 1
89
110
 
90
111
  #define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
112
+ #define ZSTD_WINDOWLOG_DEFAULTMAX 27 /* Default maximum allowed window log */
91
113
  static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
92
114
  static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
93
115
 
116
+ #define ZSTD_FRAMEIDSIZE 4
117
+ static const size_t ZSTD_frameIdSize = ZSTD_FRAMEIDSIZE; /* magic number size */
118
+
94
119
  #define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
95
120
  static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
96
121
  typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
@@ -104,40 +129,52 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
104
129
  #define LONGNBSEQ 0x7F00
105
130
 
106
131
  #define MINMATCH 3
107
- #define EQUAL_READ32 4
108
132
 
109
133
  #define Litbits 8
110
134
  #define MaxLit ((1<<Litbits) - 1)
111
135
  #define MaxML 52
112
136
  #define MaxLL 35
113
- #define MaxOff 28
137
+ #define DefaultMaxOff 28
138
+ #define MaxOff 31
114
139
  #define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
115
140
  #define MLFSELog 9
116
141
  #define LLFSELog 9
117
142
  #define OffFSELog 8
118
143
 
119
- static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120
- 1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
144
+ static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0,
145
+ 0, 0, 0, 0, 0, 0, 0, 0,
146
+ 1, 1, 1, 1, 2, 2, 3, 3,
147
+ 4, 6, 7, 8, 9,10,11,12,
121
148
  13,14,15,16 };
122
- static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
123
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
149
+ static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2,
150
+ 2, 2, 2, 2, 2, 1, 1, 1,
151
+ 2, 2, 2, 2, 2, 2, 2, 2,
152
+ 2, 3, 2, 1, 1, 1, 1, 1,
124
153
  -1,-1,-1,-1 };
125
154
  #define LL_DEFAULTNORMLOG 6 /* for static allocation */
126
155
  static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
127
156
 
128
- static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130
- 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9,10,11,
157
+ static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0,
158
+ 0, 0, 0, 0, 0, 0, 0, 0,
159
+ 0, 0, 0, 0, 0, 0, 0, 0,
160
+ 0, 0, 0, 0, 0, 0, 0, 0,
161
+ 1, 1, 1, 1, 2, 2, 3, 3,
162
+ 4, 4, 5, 7, 8, 9,10,11,
131
163
  12,13,14,15,16 };
132
- static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
133
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
134
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
164
+ static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2,
165
+ 2, 1, 1, 1, 1, 1, 1, 1,
166
+ 1, 1, 1, 1, 1, 1, 1, 1,
167
+ 1, 1, 1, 1, 1, 1, 1, 1,
168
+ 1, 1, 1, 1, 1, 1, 1, 1,
169
+ 1, 1, 1, 1, 1, 1,-1,-1,
135
170
  -1,-1,-1,-1,-1 };
136
171
  #define ML_DEFAULTNORMLOG 6 /* for static allocation */
137
172
  static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
138
173
 
139
- static const S16 OF_defaultNorm[MaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
140
- 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
174
+ static const S16 OF_defaultNorm[DefaultMaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2,
175
+ 2, 1, 1, 1, 1, 1, 1, 1,
176
+ 1, 1, 1, 1, 1, 1, 1, 1,
177
+ -1,-1,-1,-1,-1 };
141
178
  #define OF_DEFAULTNORMLOG 5 /* for static allocation */
142
179
  static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
143
180
 
@@ -149,7 +186,7 @@ static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
149
186
  #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
150
187
 
151
188
  /*! ZSTD_wildcopy() :
152
- * custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
189
+ * custom version of memcpy(), can overwrite up to WILDCOPY_OVERLENGTH bytes (if length==0) */
153
190
  #define WILDCOPY_OVERLENGTH 8
154
191
  MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
155
192
  {
@@ -173,31 +210,14 @@ MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* s
173
210
 
174
211
 
175
212
  /*-*******************************************
176
- * Private interfaces
213
+ * Private declarations
177
214
  *********************************************/
178
- typedef struct ZSTD_stats_s ZSTD_stats_t;
179
-
180
- typedef struct {
181
- U32 off;
182
- U32 len;
183
- } ZSTD_match_t;
184
-
185
- typedef struct {
186
- U32 price;
187
- U32 off;
188
- U32 mlen;
189
- U32 litlen;
190
- U32 rep[ZSTD_REP_NUM];
191
- } ZSTD_optimal_t;
192
-
193
-
194
215
  typedef struct seqDef_s {
195
216
  U32 offset;
196
217
  U16 litLength;
197
218
  U16 matchLength;
198
219
  } seqDef;
199
220
 
200
-
201
221
  typedef struct {
202
222
  seqDef* sequencesStart;
203
223
  seqDef* sequences;
@@ -208,76 +228,64 @@ typedef struct {
208
228
  BYTE* ofCode;
209
229
  U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
210
230
  U32 longLengthPos;
211
- /* opt */
212
- ZSTD_optimal_t* priceTable;
213
- ZSTD_match_t* matchTable;
214
- U32* matchLengthFreq;
215
- U32* litLengthFreq;
216
- U32* litFreq;
217
- U32* offCodeFreq;
218
- U32 matchLengthSum;
219
- U32 matchSum;
220
- U32 litLengthSum;
221
- U32 litSum;
222
- U32 offCodeSum;
223
- U32 log2matchLengthSum;
224
- U32 log2matchSum;
225
- U32 log2litLengthSum;
226
- U32 log2litSum;
227
- U32 log2offCodeSum;
228
- U32 factor;
229
- U32 staticPrices;
230
- U32 cachedPrice;
231
- U32 cachedLitLength;
232
- const BYTE* cachedLiterals;
231
+ U32 rep[ZSTD_REP_NUM];
232
+ U32 repToConfirm[ZSTD_REP_NUM];
233
233
  } seqStore_t;
234
234
 
235
- const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
236
- void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
237
- int ZSTD_isSkipFrame(ZSTD_DCtx* dctx);
235
+ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
236
+ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
238
237
 
239
238
  /* custom memory allocation functions */
240
- void* ZSTD_defaultAllocFunction(void* opaque, size_t size);
241
- void ZSTD_defaultFreeFunction(void* opaque, void* address);
242
- #ifndef ZSTD_DLL_IMPORT
243
- static const ZSTD_customMem defaultCustomMem = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
244
- #endif
245
239
  void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
240
+ void* ZSTD_calloc(size_t size, ZSTD_customMem customMem);
246
241
  void ZSTD_free(void* ptr, ZSTD_customMem customMem);
247
242
 
248
243
 
249
- /*====== common function ======*/
250
-
251
- MEM_STATIC U32 ZSTD_highbit32(U32 val)
244
+ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
252
245
  {
246
+ assert(val != 0);
247
+ {
253
248
  # if defined(_MSC_VER) /* Visual */
254
- unsigned long r=0;
255
- _BitScanReverse(&r, val);
256
- return (unsigned)r;
249
+ unsigned long r=0;
250
+ _BitScanReverse(&r, val);
251
+ return (unsigned)r;
257
252
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
258
- return 31 - __builtin_clz(val);
253
+ return 31 - __builtin_clz(val);
259
254
  # else /* Software version */
260
- 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 };
261
- U32 v = val;
262
- int r;
263
- v |= v >> 1;
264
- v |= v >> 2;
265
- v |= v >> 4;
266
- v |= v >> 8;
267
- v |= v >> 16;
268
- r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27];
269
- return r;
255
+ static const U32 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 };
256
+ U32 v = val;
257
+ v |= v >> 1;
258
+ v |= v >> 2;
259
+ v |= v >> 4;
260
+ v |= v >> 8;
261
+ v |= v >> 16;
262
+ return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
270
263
  # endif
264
+ }
271
265
  }
272
266
 
273
267
 
274
- /* hidden functions */
275
-
276
268
  /* ZSTD_invalidateRepCodes() :
277
269
  * ensures next compression will not use repcodes from previous block.
278
270
  * Note : only works with regular variant;
279
271
  * do not use with extDict variant ! */
280
- void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx);
272
+ void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); /* zstdmt, adaptive_compression (shouldn't get this definition from here) */
281
273
 
282
274
 
275
+ typedef struct {
276
+ blockType_e blockType;
277
+ U32 lastBlock;
278
+ U32 origSize;
279
+ } blockProperties_t;
280
+
281
+ /*! ZSTD_getcBlockSize() :
282
+ * Provides the size of compressed block from block header `src` */
283
+ /* Used by: decompress, fullbench (does not get its definition from here) */
284
+ size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
285
+ blockProperties_t* bpPtr);
286
+
287
+ #if defined (__cplusplus)
288
+ }
289
+ #endif
290
+
283
291
  #endif /* ZSTD_CCOMMON_H_MODULE */