extzstd 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY.ja.md +18 -0
- data/README.md +15 -50
- data/contrib/zstd/CONTRIBUTING.md +1 -1
- data/contrib/zstd/COPYING +339 -0
- data/contrib/zstd/Makefile +82 -51
- data/contrib/zstd/NEWS +92 -5
- data/contrib/zstd/README.md +50 -41
- data/contrib/zstd/appveyor.yml +164 -102
- data/contrib/zstd/circle.yml +10 -22
- data/contrib/zstd/lib/BUCK +31 -10
- data/contrib/zstd/lib/Makefile +57 -31
- data/contrib/zstd/lib/README.md +68 -37
- data/contrib/zstd/lib/common/bitstream.h +130 -76
- data/contrib/zstd/lib/common/compiler.h +86 -0
- data/contrib/zstd/lib/common/error_private.c +15 -11
- data/contrib/zstd/lib/common/error_private.h +8 -8
- data/contrib/zstd/lib/common/fse.h +19 -9
- data/contrib/zstd/lib/common/fse_decompress.c +3 -22
- data/contrib/zstd/lib/common/huf.h +68 -26
- data/contrib/zstd/lib/common/mem.h +23 -35
- data/contrib/zstd/lib/common/pool.c +123 -63
- data/contrib/zstd/lib/common/pool.h +19 -10
- data/contrib/zstd/lib/common/threading.c +11 -16
- data/contrib/zstd/lib/common/threading.h +52 -33
- data/contrib/zstd/lib/common/xxhash.c +28 -22
- data/contrib/zstd/lib/common/zstd_common.c +40 -27
- data/contrib/zstd/lib/common/zstd_errors.h +43 -34
- data/contrib/zstd/lib/common/zstd_internal.h +131 -123
- data/contrib/zstd/lib/compress/fse_compress.c +17 -33
- data/contrib/zstd/lib/compress/huf_compress.c +15 -9
- data/contrib/zstd/lib/compress/zstd_compress.c +2096 -2363
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +462 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.c +309 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.h +29 -0
- data/contrib/zstd/lib/compress/zstd_fast.c +243 -0
- data/contrib/zstd/lib/compress/zstd_fast.h +31 -0
- data/contrib/zstd/lib/compress/zstd_lazy.c +765 -0
- data/contrib/zstd/lib/compress/zstd_lazy.h +39 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +707 -0
- data/contrib/zstd/lib/compress/zstd_ldm.h +68 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +785 -0
- data/contrib/zstd/lib/compress/zstd_opt.h +19 -908
- data/contrib/zstd/lib/compress/zstdmt_compress.c +737 -327
- data/contrib/zstd/lib/compress/zstdmt_compress.h +88 -26
- data/contrib/zstd/lib/decompress/huf_decompress.c +158 -50
- data/contrib/zstd/lib/decompress/zstd_decompress.c +884 -699
- data/contrib/zstd/lib/deprecated/zbuff.h +5 -4
- data/contrib/zstd/lib/deprecated/zbuff_common.c +5 -5
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +6 -4
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +5 -4
- data/contrib/zstd/lib/dictBuilder/cover.c +93 -77
- data/contrib/zstd/lib/dictBuilder/zdict.c +107 -92
- data/contrib/zstd/lib/dictBuilder/zdict.h +112 -102
- data/contrib/zstd/lib/legacy/zstd_legacy.h +9 -4
- data/contrib/zstd/lib/legacy/zstd_v01.c +7 -6
- data/contrib/zstd/lib/legacy/zstd_v01.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v02.c +27 -99
- data/contrib/zstd/lib/legacy/zstd_v02.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v03.c +26 -98
- data/contrib/zstd/lib/legacy/zstd_v03.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v04.c +22 -91
- data/contrib/zstd/lib/legacy/zstd_v04.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v05.c +23 -99
- data/contrib/zstd/lib/legacy/zstd_v05.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v06.c +22 -96
- data/contrib/zstd/lib/legacy/zstd_v06.h +5 -4
- data/contrib/zstd/lib/legacy/zstd_v07.c +19 -95
- data/contrib/zstd/lib/legacy/zstd_v07.h +5 -4
- data/contrib/zstd/lib/zstd.h +895 -271
- data/ext/extconf.rb +11 -2
- data/ext/extzstd.c +45 -128
- data/ext/extzstd.h +74 -31
- data/ext/extzstd_stream.c +401 -142
- data/ext/zstd_common.c +5 -0
- data/ext/zstd_compress.c +8 -0
- data/ext/zstd_decompress.c +1 -0
- data/ext/zstd_dictbuilder.c +2 -0
- data/lib/extzstd/version.rb +1 -1
- data/lib/extzstd.rb +48 -1
- data/test/test_basic.rb +9 -1
- metadata +17 -7
- data/HISTORY.ja +0 -10
- data/contrib/zstd/LICENSE-examples +0 -11
- 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
|
7
|
-
*
|
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
|
/* The purpose of this file is to have a single list of error strings embedded in binary */
|
@@ -20,23 +21,26 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
20
21
|
case PREFIX(GENERIC): return "Error (generic)";
|
21
22
|
case PREFIX(prefix_unknown): return "Unknown frame descriptor";
|
22
23
|
case PREFIX(version_unsupported): return "Version not supported";
|
23
|
-
case PREFIX(parameter_unknown): return "Unknown parameter type";
|
24
24
|
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
25
|
-
case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
|
26
25
|
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
27
|
-
case PREFIX(
|
26
|
+
case PREFIX(corruption_detected): return "Corrupted block detected";
|
27
|
+
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
28
|
+
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
29
|
+
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
28
30
|
case PREFIX(init_missing): return "Context should be init first";
|
29
31
|
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
30
32
|
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
33
|
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
36
34
|
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
|
37
35
|
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
38
36
|
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
39
37
|
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
38
|
+
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
39
|
+
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
40
|
+
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
41
|
+
/* following error codes are not stable and may be removed or changed in a future version */
|
42
|
+
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
43
|
+
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
40
44
|
case PREFIX(maxCode):
|
41
45
|
default: return notErrorCode;
|
42
46
|
}
|
@@ -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
|
7
|
-
*
|
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
|
/* Note : this module is expected to remain private, do not expose it */
|
@@ -48,10 +49,9 @@ typedef ZSTD_ErrorCode ERR_enum;
|
|
48
49
|
/*-****************************************
|
49
50
|
* Error codes handling
|
50
51
|
******************************************/
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#define ERROR(name) ((size_t)-PREFIX(name))
|
52
|
+
#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
|
53
|
+
#define ERROR(name) ZSTD_ERROR(name)
|
54
|
+
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
55
55
|
|
56
56
|
ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
57
57
|
|
@@ -31,13 +31,14 @@
|
|
31
31
|
You can contact the author at :
|
32
32
|
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
33
|
****************************************************************** */
|
34
|
-
#ifndef FSE_H
|
35
|
-
#define FSE_H
|
36
34
|
|
37
35
|
#if defined (__cplusplus)
|
38
36
|
extern "C" {
|
39
37
|
#endif
|
40
38
|
|
39
|
+
#ifndef FSE_H
|
40
|
+
#define FSE_H
|
41
|
+
|
41
42
|
|
42
43
|
/*-*****************************************
|
43
44
|
* Dependencies
|
@@ -183,7 +184,7 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const sh
|
|
183
184
|
/*! Constructor and Destructor of FSE_CTable.
|
184
185
|
Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
|
185
186
|
typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
|
186
|
-
FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned
|
187
|
+
FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog);
|
187
188
|
FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct);
|
188
189
|
|
189
190
|
/*! FSE_buildCTable():
|
@@ -297,8 +298,10 @@ FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<
|
|
297
298
|
If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small)
|
298
299
|
*/
|
299
300
|
|
301
|
+
#endif /* FSE_H */
|
300
302
|
|
301
|
-
#
|
303
|
+
#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY)
|
304
|
+
#define FSE_H_FSE_STATIC_LINKING_ONLY
|
302
305
|
|
303
306
|
/* *** Dependency *** */
|
304
307
|
#include "bitstream.h"
|
@@ -316,6 +319,10 @@ If there is an error, the function will return an error code, which can be teste
|
|
316
319
|
#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
|
317
320
|
#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog))
|
318
321
|
|
322
|
+
/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */
|
323
|
+
#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable))
|
324
|
+
#define FSE_DTABLE_SIZE(maxTableLog) (FSE_DTABLE_SIZE_U32(maxTableLog) * sizeof(FSE_DTable))
|
325
|
+
|
319
326
|
|
320
327
|
/* *****************************************
|
321
328
|
* FSE advanced API
|
@@ -353,7 +360,7 @@ unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsi
|
|
353
360
|
* Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
|
354
361
|
* FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable.
|
355
362
|
*/
|
356
|
-
#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + (
|
363
|
+
#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) )
|
357
364
|
size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
358
365
|
|
359
366
|
size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits);
|
@@ -377,6 +384,11 @@ size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
|
|
377
384
|
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog);
|
378
385
|
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */
|
379
386
|
|
387
|
+
typedef enum {
|
388
|
+
FSE_repeat_none, /**< Cannot use the previous table */
|
389
|
+
FSE_repeat_check, /**< Can use the previous table but it must be checked */
|
390
|
+
FSE_repeat_valid /**< Can use the previous table and it is asumed to be valid */
|
391
|
+
} FSE_repeat;
|
380
392
|
|
381
393
|
/* *****************************************
|
382
394
|
* FSE symbol compression API
|
@@ -550,9 +562,9 @@ MEM_STATIC void FSE_initCState2(FSE_CState_t* statePtr, const FSE_CTable* ct, U3
|
|
550
562
|
|
551
563
|
MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, U32 symbol)
|
552
564
|
{
|
553
|
-
const
|
565
|
+
FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
|
554
566
|
const U16* const stateTable = (const U16*)(statePtr->stateTable);
|
555
|
-
U32 nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
|
567
|
+
U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
|
556
568
|
BIT_addBits(bitC, statePtr->value, nbBitsOut);
|
557
569
|
statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
|
558
570
|
}
|
@@ -690,5 +702,3 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|
690
702
|
#if defined (__cplusplus)
|
691
703
|
}
|
692
704
|
#endif
|
693
|
-
|
694
|
-
#endif /* FSE_H */
|
@@ -33,35 +33,16 @@
|
|
33
33
|
****************************************************************** */
|
34
34
|
|
35
35
|
|
36
|
-
/* **************************************************************
|
37
|
-
* Compiler specifics
|
38
|
-
****************************************************************/
|
39
|
-
#ifdef _MSC_VER /* Visual Studio */
|
40
|
-
# define FORCE_INLINE static __forceinline
|
41
|
-
# include <intrin.h> /* For Visual 2005 */
|
42
|
-
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
43
|
-
# pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
|
44
|
-
#else
|
45
|
-
# if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
46
|
-
# ifdef __GNUC__
|
47
|
-
# define FORCE_INLINE static inline __attribute__((always_inline))
|
48
|
-
# else
|
49
|
-
# define FORCE_INLINE static inline
|
50
|
-
# endif
|
51
|
-
# else
|
52
|
-
# define FORCE_INLINE static
|
53
|
-
# endif /* __STDC_VERSION__ */
|
54
|
-
#endif
|
55
|
-
|
56
|
-
|
57
36
|
/* **************************************************************
|
58
37
|
* Includes
|
59
38
|
****************************************************************/
|
60
39
|
#include <stdlib.h> /* malloc, free, qsort */
|
61
40
|
#include <string.h> /* memcpy, memset */
|
62
41
|
#include "bitstream.h"
|
42
|
+
#include "compiler.h"
|
63
43
|
#define FSE_STATIC_LINKING_ONLY
|
64
44
|
#include "fse.h"
|
45
|
+
#include "error_private.h"
|
65
46
|
|
66
47
|
|
67
48
|
/* **************************************************************
|
@@ -216,7 +197,7 @@ size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits)
|
|
216
197
|
return 0;
|
217
198
|
}
|
218
199
|
|
219
|
-
|
200
|
+
FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
|
220
201
|
void* dst, size_t maxDstSize,
|
221
202
|
const void* cSrc, size_t cSrcSize,
|
222
203
|
const FSE_DTable* dt, const unsigned fast)
|
@@ -31,18 +31,33 @@
|
|
31
31
|
You can contact the author at :
|
32
32
|
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
33
|
****************************************************************** */
|
34
|
-
#ifndef HUF_H_298734234
|
35
|
-
#define HUF_H_298734234
|
36
34
|
|
37
35
|
#if defined (__cplusplus)
|
38
36
|
extern "C" {
|
39
37
|
#endif
|
40
38
|
|
39
|
+
#ifndef HUF_H_298734234
|
40
|
+
#define HUF_H_298734234
|
41
41
|
|
42
42
|
/* *** Dependencies *** */
|
43
43
|
#include <stddef.h> /* size_t */
|
44
44
|
|
45
45
|
|
46
|
+
/* *** library symbols visibility *** */
|
47
|
+
/* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual,
|
48
|
+
* HUF symbols remain "private" (internal symbols for library only).
|
49
|
+
* Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */
|
50
|
+
#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4)
|
51
|
+
# define HUF_PUBLIC_API __attribute__ ((visibility ("default")))
|
52
|
+
#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */
|
53
|
+
# define HUF_PUBLIC_API __declspec(dllexport)
|
54
|
+
#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1)
|
55
|
+
# define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */
|
56
|
+
#else
|
57
|
+
# define HUF_PUBLIC_API
|
58
|
+
#endif
|
59
|
+
|
60
|
+
|
46
61
|
/* *** simple functions *** */
|
47
62
|
/**
|
48
63
|
HUF_compress() :
|
@@ -55,8 +70,8 @@ HUF_compress() :
|
|
55
70
|
if return == 1, srcData is a single repeated byte symbol (RLE compression).
|
56
71
|
if HUF_isError(return), compression failed (more details using HUF_getErrorName())
|
57
72
|
*/
|
58
|
-
size_t HUF_compress(void* dst, size_t dstCapacity,
|
59
|
-
|
73
|
+
HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity,
|
74
|
+
const void* src, size_t srcSize);
|
60
75
|
|
61
76
|
/**
|
62
77
|
HUF_decompress() :
|
@@ -69,33 +84,57 @@ HUF_decompress() :
|
|
69
84
|
@return : size of regenerated data (== originalSize),
|
70
85
|
or an error code, which can be tested using HUF_isError()
|
71
86
|
*/
|
72
|
-
size_t HUF_decompress(void* dst, size_t originalSize,
|
73
|
-
|
87
|
+
HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize,
|
88
|
+
const void* cSrc, size_t cSrcSize);
|
74
89
|
|
75
90
|
|
76
91
|
/* *** Tool functions *** */
|
77
|
-
#define HUF_BLOCKSIZE_MAX (128 * 1024)
|
78
|
-
size_t HUF_compressBound(size_t size);
|
92
|
+
#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */
|
93
|
+
HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
|
79
94
|
|
80
95
|
/* Error Management */
|
81
|
-
unsigned HUF_isError(size_t code);
|
82
|
-
const char* HUF_getErrorName(size_t code);
|
96
|
+
HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
|
97
|
+
HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
|
83
98
|
|
84
99
|
|
85
100
|
/* *** Advanced function *** */
|
86
101
|
|
87
102
|
/** HUF_compress2() :
|
88
|
-
*
|
89
|
-
*
|
90
|
-
size_t HUF_compress2 (void* dst, size_t
|
103
|
+
* Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog`.
|
104
|
+
* `tableLog` must be `<= HUF_TABLELOG_MAX` . */
|
105
|
+
HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
91
106
|
|
92
107
|
/** HUF_compress4X_wksp() :
|
93
|
-
*
|
94
|
-
|
108
|
+
* Same as HUF_compress2(), but uses externally allocated `workSpace`.
|
109
|
+
* `workspace` must have minimum alignment of 4, and be at least as large as following macro */
|
110
|
+
#define HUF_WORKSPACE_SIZE (6 << 10)
|
111
|
+
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
|
112
|
+
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
95
113
|
|
114
|
+
/**
|
115
|
+
* The minimum workspace size for the `workSpace` used in
|
116
|
+
* HUF_readDTableX2_wksp() and HUF_readDTableX4_wksp().
|
117
|
+
*
|
118
|
+
* The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when
|
119
|
+
* HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15.
|
120
|
+
* Buffer overflow errors may potentially occur if code modifications result in
|
121
|
+
* a required workspace size greater than that specified in the following
|
122
|
+
* macro.
|
123
|
+
*/
|
124
|
+
#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
|
125
|
+
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
|
96
126
|
|
127
|
+
#endif /* HUF_H_298734234 */
|
97
128
|
|
98
|
-
|
129
|
+
/* ******************************************************************
|
130
|
+
* WARNING !!
|
131
|
+
* The following section contains advanced and experimental definitions
|
132
|
+
* which shall never be used in the context of dll
|
133
|
+
* because they are not guaranteed to remain stable in the future.
|
134
|
+
* Only consider them in association with static linking.
|
135
|
+
*******************************************************************/
|
136
|
+
#if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY)
|
137
|
+
#define HUF_H_HUF_STATIC_LINKING_ONLY
|
99
138
|
|
100
139
|
/* *** Dependencies *** */
|
101
140
|
#include "mem.h" /* U32 */
|
@@ -117,12 +156,14 @@ size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t s
|
|
117
156
|
******************************************/
|
118
157
|
/* HUF buffer bounds */
|
119
158
|
#define HUF_CTABLEBOUND 129
|
120
|
-
#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true
|
159
|
+
#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */
|
121
160
|
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
122
161
|
|
123
162
|
/* static allocation of HUF's Compression Table */
|
163
|
+
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
164
|
+
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
124
165
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
125
|
-
U32 name##hb[maxSymbolValue
|
166
|
+
U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \
|
126
167
|
void* name##hv = &(name##hb); \
|
127
168
|
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
128
169
|
|
@@ -134,10 +175,6 @@ typedef U32 HUF_DTable;
|
|
134
175
|
#define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \
|
135
176
|
HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) }
|
136
177
|
|
137
|
-
/* The workspace must have alignment at least 4 and be at least this large */
|
138
|
-
#define HUF_WORKSPACE_SIZE (6 << 10)
|
139
|
-
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
|
140
|
-
|
141
178
|
|
142
179
|
/* ****************************************
|
143
180
|
* Advanced decompression functions
|
@@ -147,8 +184,11 @@ size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cS
|
|
147
184
|
|
148
185
|
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
|
149
186
|
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
|
187
|
+
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */
|
150
188
|
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
189
|
+
size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
|
151
190
|
size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
191
|
+
size_t HUF_decompress4X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
|
152
192
|
|
153
193
|
|
154
194
|
/* ****************************************
|
@@ -202,7 +242,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|
202
242
|
|
203
243
|
/** HUF_readCTable() :
|
204
244
|
* Loading a CTable saved with HUF_writeCTable() */
|
205
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned
|
245
|
+
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
206
246
|
|
207
247
|
|
208
248
|
/*
|
@@ -220,7 +260,9 @@ HUF_decompress() does the following:
|
|
220
260
|
U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
|
221
261
|
|
222
262
|
size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
263
|
+
size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
|
223
264
|
size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
265
|
+
size_t HUF_readDTableX4_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
|
224
266
|
|
225
267
|
size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
226
268
|
size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
@@ -243,8 +285,11 @@ size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cS
|
|
243
285
|
size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
|
244
286
|
|
245
287
|
size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
|
288
|
+
size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize);
|
246
289
|
size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
290
|
+
size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
|
247
291
|
size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
292
|
+
size_t HUF_decompress1X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
|
248
293
|
|
249
294
|
size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */
|
250
295
|
size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
@@ -252,9 +297,6 @@ size_t HUF_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void* c
|
|
252
297
|
|
253
298
|
#endif /* HUF_STATIC_LINKING_ONLY */
|
254
299
|
|
255
|
-
|
256
300
|
#if defined (__cplusplus)
|
257
301
|
}
|
258
302
|
#endif
|
259
|
-
|
260
|
-
#endif /* HUF_H_298734234 */
|
@@ -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
|
7
|
-
*
|
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 MEM_H_MODULE
|
@@ -55,8 +56,6 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
55
56
|
typedef int32_t S32;
|
56
57
|
typedef uint64_t U64;
|
57
58
|
typedef int64_t S64;
|
58
|
-
typedef intptr_t iPtrDiff;
|
59
|
-
typedef uintptr_t uPtrDiff;
|
60
59
|
#else
|
61
60
|
typedef unsigned char BYTE;
|
62
61
|
typedef unsigned short U16;
|
@@ -65,8 +64,6 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
65
64
|
typedef signed int S32;
|
66
65
|
typedef unsigned long long U64;
|
67
66
|
typedef signed long long S64;
|
68
|
-
typedef ptrdiff_t iPtrDiff;
|
69
|
-
typedef size_t uPtrDiff;
|
70
67
|
#endif
|
71
68
|
|
72
69
|
|
@@ -89,8 +86,7 @@ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (size
|
|
89
86
|
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
90
87
|
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
91
88
|
# define MEM_FORCE_MEMORY_ACCESS 2
|
92
|
-
# elif defined(__INTEL_COMPILER)
|
93
|
-
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
89
|
+
# elif defined(__INTEL_COMPILER) || defined(__GNUC__)
|
94
90
|
# define MEM_FORCE_MEMORY_ACCESS 1
|
95
91
|
# endif
|
96
92
|
#endif
|
@@ -111,7 +107,7 @@ Only use if no other choice to achieve best performance on target platform */
|
|
111
107
|
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
112
108
|
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
113
109
|
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
114
|
-
MEM_STATIC
|
110
|
+
MEM_STATIC size_t MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; }
|
115
111
|
|
116
112
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
117
113
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
|
@@ -122,21 +118,27 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
|
|
122
118
|
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
123
119
|
/* currently only defined for gcc and icc */
|
124
120
|
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
|
125
|
-
|
126
|
-
typedef
|
121
|
+
__pragma( pack(push, 1) )
|
122
|
+
typedef struct { U16 v; } unalign16;
|
123
|
+
typedef struct { U32 v; } unalign32;
|
124
|
+
typedef struct { U64 v; } unalign64;
|
125
|
+
typedef struct { size_t v; } unalignArch;
|
127
126
|
__pragma( pack(pop) )
|
128
127
|
#else
|
129
|
-
typedef
|
128
|
+
typedef struct { U16 v; } __attribute__((packed)) unalign16;
|
129
|
+
typedef struct { U32 v; } __attribute__((packed)) unalign32;
|
130
|
+
typedef struct { U64 v; } __attribute__((packed)) unalign64;
|
131
|
+
typedef struct { size_t v; } __attribute__((packed)) unalignArch;
|
130
132
|
#endif
|
131
133
|
|
132
|
-
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const
|
133
|
-
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const
|
134
|
-
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const
|
135
|
-
MEM_STATIC
|
134
|
+
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign16*)ptr)->v; }
|
135
|
+
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign32*)ptr)->v; }
|
136
|
+
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign64*)ptr)->v; }
|
137
|
+
MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalignArch*)ptr)->v; }
|
136
138
|
|
137
|
-
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((
|
138
|
-
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((
|
139
|
-
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((
|
139
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign16*)memPtr)->v = value; }
|
140
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign32*)memPtr)->v = value; }
|
141
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v = value; }
|
140
142
|
|
141
143
|
#else
|
142
144
|
|
@@ -353,20 +355,6 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
|
|
353
355
|
}
|
354
356
|
|
355
357
|
|
356
|
-
/* function safe only for comparisons */
|
357
|
-
MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
|
358
|
-
{
|
359
|
-
switch (length)
|
360
|
-
{
|
361
|
-
default :
|
362
|
-
case 4 : return MEM_read32(memPtr);
|
363
|
-
case 3 : if (MEM_isLittleEndian())
|
364
|
-
return MEM_read32(memPtr)<<8;
|
365
|
-
else
|
366
|
-
return MEM_read32(memPtr)>>8;
|
367
|
-
}
|
368
|
-
}
|
369
|
-
|
370
358
|
#if defined (__cplusplus)
|
371
359
|
}
|
372
360
|
#endif
|