zstd-ruby 1.1.4.0 → 1.2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/Makefile +11 -1
- data/ext/zstdruby/libzstd/README.md +8 -0
- data/ext/zstdruby/libzstd/common/bitstream.h +56 -27
- data/ext/zstdruby/libzstd/common/error_private.c +2 -1
- data/ext/zstdruby/libzstd/common/fse.h +7 -3
- data/ext/zstdruby/libzstd/common/huf.h +42 -19
- data/ext/zstdruby/libzstd/common/mem.h +2 -3
- data/ext/zstdruby/libzstd/common/zstd_errors.h +1 -0
- data/ext/zstdruby/libzstd/common/zstd_internal.h +3 -2
- data/ext/zstdruby/libzstd/compress/fse_compress.c +10 -10
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +455 -244
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +6 -4
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +40 -28
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +115 -219
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +34 -13
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +65 -43
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +7 -7
- data/ext/zstdruby/libzstd/dll/example/README.md +5 -5
- data/ext/zstdruby/libzstd/dll/example/build_package.bat +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +21 -21
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +20 -20
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +2 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +2 -2
- data/ext/zstdruby/libzstd/zstd.h +88 -68
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90c5ef25c36e660027688987e2c0d4c867aa33f6
|
4
|
+
data.tar.gz: 54806b961cf688772ac05d856d3d72359caa3dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c6df76d82bda82633e3e93971e77c42b721e766568a0993589c83494c887aa70363908d50d10372ba7a298deb5fa78a0f58662becd5186db440a7e6e90422a
|
7
|
+
data.tar.gz: 7cff0cfe30172d6c455b57e1785f0ddc2b612408cd5a83b98fabd7ff58399ae03e51c4dde244e36e736d7def3b16de788e33bd74450868826f0f6c293860d277
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -71,6 +71,9 @@ libzstd.a: $(ZSTD_OBJ)
|
|
71
71
|
@echo compiling static library
|
72
72
|
@$(AR) $(ARFLAGS) $@ $^
|
73
73
|
|
74
|
+
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTHREAD
|
75
|
+
libzstd.a-mt: libzstd.a
|
76
|
+
|
74
77
|
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
|
75
78
|
$(LIBZSTD): $(ZSTD_FILES)
|
76
79
|
@echo compiling dynamic library $(LIBVER)
|
@@ -86,10 +89,17 @@ endif
|
|
86
89
|
|
87
90
|
libzstd : $(LIBZSTD)
|
88
91
|
|
92
|
+
libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
|
93
|
+
libzstd-mt : libzstd
|
94
|
+
|
89
95
|
lib: libzstd.a libzstd
|
90
96
|
|
91
|
-
lib-
|
97
|
+
lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD
|
98
|
+
lib-mt: lib
|
99
|
+
|
100
|
+
lib-release lib-release-mt: DEBUGFLAGS :=
|
92
101
|
lib-release: lib
|
102
|
+
lib-release-mt: lib-mt
|
93
103
|
|
94
104
|
clean:
|
95
105
|
@$(RM) -r *.dSYM # Mac OS-X specific
|
@@ -22,6 +22,14 @@ Some additional API may be useful if you're looking into advanced features :
|
|
22
22
|
They are not "stable", their definition may change in the future.
|
23
23
|
Only static linking is allowed.
|
24
24
|
|
25
|
+
#### ZSTDMT API
|
26
|
+
|
27
|
+
To enable multithreaded compression within the library, invoke `make lib-mt` target.
|
28
|
+
Prototypes are defined in header file `compress/zstdmt_compress.h`.
|
29
|
+
When linking a program that uses ZSTDMT API against libzstd.a on a POSIX system,
|
30
|
+
`-pthread` flag must be provided to the compiler and linker.
|
31
|
+
Note : ZSTDMT prototypes can still be used with a library built without multithread support,
|
32
|
+
but in this case, they will be single threaded only.
|
25
33
|
|
26
34
|
#### Modular build
|
27
35
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
bitstream
|
3
3
|
Part of FSE library
|
4
4
|
header file (to include)
|
5
|
-
Copyright (C) 2013-
|
5
|
+
Copyright (C) 2013-2017, Yann Collet.
|
6
6
|
|
7
7
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
8
8
|
|
@@ -53,6 +53,16 @@ extern "C" {
|
|
53
53
|
#include "error_private.h" /* error codes and messages */
|
54
54
|
|
55
55
|
|
56
|
+
/*-*************************************
|
57
|
+
* Debug
|
58
|
+
***************************************/
|
59
|
+
#if defined(BIT_DEBUG) && (BIT_DEBUG>=1)
|
60
|
+
# include <assert.h>
|
61
|
+
#else
|
62
|
+
# define assert(condition) ((void)0)
|
63
|
+
#endif
|
64
|
+
|
65
|
+
|
56
66
|
/*=========================================
|
57
67
|
* Target specific
|
58
68
|
=========================================*/
|
@@ -74,7 +84,7 @@ extern "C" {
|
|
74
84
|
typedef struct
|
75
85
|
{
|
76
86
|
size_t bitContainer;
|
77
|
-
|
87
|
+
unsigned bitPos;
|
78
88
|
char* startPtr;
|
79
89
|
char* ptr;
|
80
90
|
char* endPtr;
|
@@ -112,6 +122,7 @@ typedef struct
|
|
112
122
|
unsigned bitsConsumed;
|
113
123
|
const char* ptr;
|
114
124
|
const char* start;
|
125
|
+
const char* limitPtr;
|
115
126
|
} BIT_DStream_t;
|
116
127
|
|
117
128
|
typedef enum { BIT_DStream_unfinished = 0,
|
@@ -163,7 +174,10 @@ MEM_STATIC unsigned BIT_highbit32 (register U32 val)
|
|
163
174
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
164
175
|
return 31 - __builtin_clz (val);
|
165
176
|
# else /* Software version */
|
166
|
-
static const unsigned DeBruijnClz[32] = { 0,
|
177
|
+
static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
|
178
|
+
11, 14, 16, 18, 22, 25, 3, 30,
|
179
|
+
8, 12, 20, 28, 15, 17, 24, 7,
|
180
|
+
19, 27, 23, 6, 26, 5, 4, 31 };
|
167
181
|
U32 v = val;
|
168
182
|
v |= v >> 1;
|
169
183
|
v |= v >> 2;
|
@@ -175,31 +189,36 @@ MEM_STATIC unsigned BIT_highbit32 (register U32 val)
|
|
175
189
|
}
|
176
190
|
|
177
191
|
/*===== Local Constants =====*/
|
178
|
-
static const unsigned BIT_mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F,
|
192
|
+
static const unsigned BIT_mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F,
|
193
|
+
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF,
|
194
|
+
0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF,
|
195
|
+
0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF }; /* up to 26 bits */
|
179
196
|
|
180
197
|
|
181
198
|
/*-**************************************************************
|
182
199
|
* bitStream encoding
|
183
200
|
****************************************************************/
|
184
201
|
/*! BIT_initCStream() :
|
185
|
-
* `dstCapacity` must be > sizeof(
|
202
|
+
* `dstCapacity` must be > sizeof(size_t)
|
186
203
|
* @return : 0 if success,
|
187
204
|
otherwise an error code (can be tested using ERR_isError() ) */
|
188
|
-
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
205
|
+
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
206
|
+
void* startPtr, size_t dstCapacity)
|
189
207
|
{
|
190
208
|
bitC->bitContainer = 0;
|
191
209
|
bitC->bitPos = 0;
|
192
210
|
bitC->startPtr = (char*)startPtr;
|
193
211
|
bitC->ptr = bitC->startPtr;
|
194
|
-
bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->
|
195
|
-
if (dstCapacity <= sizeof(bitC->
|
212
|
+
bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer);
|
213
|
+
if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall);
|
196
214
|
return 0;
|
197
215
|
}
|
198
216
|
|
199
217
|
/*! BIT_addBits() :
|
200
218
|
can add up to 26 bits into `bitC`.
|
201
219
|
Does not check for register overflow ! */
|
202
|
-
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
220
|
+
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
221
|
+
size_t value, unsigned nbBits)
|
203
222
|
{
|
204
223
|
bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
|
205
224
|
bitC->bitPos += nbBits;
|
@@ -207,34 +226,42 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits)
|
|
207
226
|
|
208
227
|
/*! BIT_addBitsFast() :
|
209
228
|
* works only if `value` is _clean_, meaning all high bits above nbBits are 0 */
|
210
|
-
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
229
|
+
MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC,
|
230
|
+
size_t value, unsigned nbBits)
|
211
231
|
{
|
232
|
+
assert((value>>nbBits) == 0);
|
212
233
|
bitC->bitContainer |= value << bitC->bitPos;
|
213
234
|
bitC->bitPos += nbBits;
|
214
235
|
}
|
215
236
|
|
216
237
|
/*! BIT_flushBitsFast() :
|
238
|
+
* assumption : bitContainer has not overflowed
|
217
239
|
* unsafe version; does not check buffer overflow */
|
218
240
|
MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
|
219
241
|
{
|
220
242
|
size_t const nbBytes = bitC->bitPos >> 3;
|
243
|
+
assert( bitC->bitPos <= (sizeof(bitC->bitContainer)*8) );
|
221
244
|
MEM_writeLEST(bitC->ptr, bitC->bitContainer);
|
222
245
|
bitC->ptr += nbBytes;
|
246
|
+
assert(bitC->ptr <= bitC->endPtr);
|
223
247
|
bitC->bitPos &= 7;
|
224
|
-
bitC->bitContainer >>= nbBytes*8;
|
248
|
+
bitC->bitContainer >>= nbBytes*8;
|
225
249
|
}
|
226
250
|
|
227
251
|
/*! BIT_flushBits() :
|
252
|
+
* assumption : bitContainer has not overflowed
|
228
253
|
* safe version; check for buffer overflow, and prevents it.
|
229
|
-
* note : does not signal buffer overflow.
|
254
|
+
* note : does not signal buffer overflow.
|
255
|
+
* overflow will be revealed later on using BIT_closeCStream() */
|
230
256
|
MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC)
|
231
257
|
{
|
232
258
|
size_t const nbBytes = bitC->bitPos >> 3;
|
259
|
+
assert( bitC->bitPos <= (sizeof(bitC->bitContainer)*8) );
|
233
260
|
MEM_writeLEST(bitC->ptr, bitC->bitContainer);
|
234
261
|
bitC->ptr += nbBytes;
|
235
262
|
if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
|
236
263
|
bitC->bitPos &= 7;
|
237
|
-
bitC->bitContainer >>= nbBytes*8;
|
264
|
+
bitC->bitContainer >>= nbBytes*8;
|
238
265
|
}
|
239
266
|
|
240
267
|
/*! BIT_closeCStream() :
|
@@ -244,9 +271,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
|
|
244
271
|
{
|
245
272
|
BIT_addBitsFast(bitC, 1, 1); /* endMark */
|
246
273
|
BIT_flushBits(bitC);
|
247
|
-
|
248
|
-
if (bitC->ptr >= bitC->endPtr) return 0; /* doesn't fit within authorized budget : cancel */
|
249
|
-
|
274
|
+
if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
|
250
275
|
return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0);
|
251
276
|
}
|
252
277
|
|
@@ -264,15 +289,16 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|
264
289
|
{
|
265
290
|
if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
|
266
291
|
|
292
|
+
bitD->start = (const char*)srcBuffer;
|
293
|
+
bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
|
294
|
+
|
267
295
|
if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */
|
268
|
-
bitD->start = (const char*)srcBuffer;
|
269
296
|
bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
|
270
297
|
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
271
298
|
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
272
299
|
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
|
273
300
|
if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
|
274
301
|
} else {
|
275
|
-
bitD->start = (const char*)srcBuffer;
|
276
302
|
bitD->ptr = bitD->start;
|
277
303
|
bitD->bitContainer = *(const BYTE*)(bitD->start);
|
278
304
|
switch(srcSize)
|
@@ -330,17 +356,18 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
|
330
356
|
#if defined(__BMI__) && defined(__GNUC__) /* experimental; fails if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8 */
|
331
357
|
return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits);
|
332
358
|
#else
|
333
|
-
U32 const
|
334
|
-
return ((bitD->bitContainer << (bitD->bitsConsumed &
|
359
|
+
U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
|
360
|
+
return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask);
|
335
361
|
#endif
|
336
362
|
}
|
337
363
|
|
338
364
|
/*! BIT_lookBitsFast() :
|
339
|
-
*
|
365
|
+
* unsafe version; only works if nbBits >= 1 */
|
340
366
|
MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
|
341
367
|
{
|
342
|
-
U32 const
|
343
|
-
|
368
|
+
U32 const regMask = sizeof(bitD->bitContainer)*8 - 1;
|
369
|
+
assert(nbBits >= 1);
|
370
|
+
return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
|
344
371
|
}
|
345
372
|
|
346
373
|
MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
@@ -365,6 +392,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
|
|
365
392
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
366
393
|
{
|
367
394
|
size_t const value = BIT_lookBitsFast(bitD, nbBits);
|
395
|
+
assert(nbBits >= 1);
|
368
396
|
BIT_skipBits(bitD, nbBits);
|
369
397
|
return value;
|
370
398
|
}
|
@@ -376,10 +404,10 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
|
376
404
|
if status == BIT_DStream_unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
|
377
405
|
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
378
406
|
{
|
379
|
-
|
380
|
-
|
407
|
+
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
|
408
|
+
return BIT_DStream_overflow;
|
381
409
|
|
382
|
-
if (bitD->ptr >= bitD->
|
410
|
+
if (bitD->ptr >= bitD->limitPtr) {
|
383
411
|
bitD->ptr -= bitD->bitsConsumed >> 3;
|
384
412
|
bitD->bitsConsumed &= 7;
|
385
413
|
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
@@ -389,6 +417,7 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
|
389
417
|
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
|
390
418
|
return BIT_DStream_completed;
|
391
419
|
}
|
420
|
+
/* start < ptr < limitPtr */
|
392
421
|
{ U32 nbBytes = bitD->bitsConsumed >> 3;
|
393
422
|
BIT_DStream_status result = BIT_DStream_unfinished;
|
394
423
|
if (bitD->ptr - nbBytes < bitD->start) {
|
@@ -397,7 +426,7 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
|
397
426
|
}
|
398
427
|
bitD->ptr -= nbBytes;
|
399
428
|
bitD->bitsConsumed -= nbBytes*8;
|
400
|
-
bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD) */
|
429
|
+
bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */
|
401
430
|
return result;
|
402
431
|
}
|
403
432
|
}
|
@@ -29,7 +29,7 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
29
29
|
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
30
30
|
case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
|
31
31
|
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
32
|
-
case PREFIX(srcSize_wrong): return "Src size incorrect";
|
32
|
+
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
33
33
|
case PREFIX(corruption_detected): return "Corrupted block detected";
|
34
34
|
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
35
35
|
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
@@ -37,6 +37,7 @@ const char* ERR_getErrorString(ERR_enum code)
|
|
37
37
|
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
38
38
|
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
39
39
|
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
40
|
+
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
40
41
|
case PREFIX(maxCode):
|
41
42
|
default: return notErrorCode;
|
42
43
|
}
|
@@ -316,6 +316,10 @@ If there is an error, the function will return an error code, which can be teste
|
|
316
316
|
#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
|
317
317
|
#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog))
|
318
318
|
|
319
|
+
/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */
|
320
|
+
#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable))
|
321
|
+
#define FSE_DTABLE_SIZE(maxTableLog) (FSE_DTABLE_SIZE_U32(maxTableLog) * sizeof(FSE_DTable))
|
322
|
+
|
319
323
|
|
320
324
|
/* *****************************************
|
321
325
|
* FSE advanced API
|
@@ -353,7 +357,7 @@ unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsi
|
|
353
357
|
* Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
|
354
358
|
* FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable.
|
355
359
|
*/
|
356
|
-
#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + (
|
360
|
+
#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) )
|
357
361
|
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
362
|
|
359
363
|
size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits);
|
@@ -550,9 +554,9 @@ MEM_STATIC void FSE_initCState2(FSE_CState_t* statePtr, const FSE_CTable* ct, U3
|
|
550
554
|
|
551
555
|
MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, U32 symbol)
|
552
556
|
{
|
553
|
-
const
|
557
|
+
FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
|
554
558
|
const U16* const stateTable = (const U16*)(statePtr->stateTable);
|
555
|
-
U32 nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
|
559
|
+
U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
|
556
560
|
BIT_addBits(bitC, statePtr->value, nbBitsOut);
|
557
561
|
statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
|
558
562
|
}
|
@@ -43,6 +43,21 @@ extern "C" {
|
|
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,32 +84,42 @@ 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
|
|
96
114
|
|
97
115
|
|
116
|
+
/* ******************************************************************
|
117
|
+
* WARNING !!
|
118
|
+
* The following section contains advanced and experimental definitions
|
119
|
+
* which shall never be used in the context of dll
|
120
|
+
* because they are not guaranteed to remain stable in the future.
|
121
|
+
* Only consider them in association with static linking.
|
122
|
+
*******************************************************************/
|
98
123
|
#ifdef HUF_STATIC_LINKING_ONLY
|
99
124
|
|
100
125
|
/* *** Dependencies *** */
|
@@ -117,12 +142,14 @@ size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t s
|
|
117
142
|
******************************************/
|
118
143
|
/* HUF buffer bounds */
|
119
144
|
#define HUF_CTABLEBOUND 129
|
120
|
-
#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true
|
145
|
+
#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */
|
121
146
|
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
122
147
|
|
123
148
|
/* static allocation of HUF's Compression Table */
|
149
|
+
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
150
|
+
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
124
151
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
125
|
-
U32 name##hb[maxSymbolValue
|
152
|
+
U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \
|
126
153
|
void* name##hv = &(name##hb); \
|
127
154
|
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
128
155
|
|
@@ -134,10 +161,6 @@ typedef U32 HUF_DTable;
|
|
134
161
|
#define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \
|
135
162
|
HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) }
|
136
163
|
|
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
164
|
|
142
165
|
/* ****************************************
|
143
166
|
* Advanced decompression functions
|