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.
- 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
|
@@ -32,27 +32,6 @@
|
|
|
32
32
|
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
33
33
|
****************************************************************** */
|
|
34
34
|
|
|
35
|
-
/* **************************************************************
|
|
36
|
-
* Compiler specifics
|
|
37
|
-
****************************************************************/
|
|
38
|
-
#ifdef _MSC_VER /* Visual Studio */
|
|
39
|
-
# define FORCE_INLINE static __forceinline
|
|
40
|
-
# include <intrin.h> /* For Visual 2005 */
|
|
41
|
-
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
|
42
|
-
# pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
|
|
43
|
-
#else
|
|
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
|
|
50
|
-
# else
|
|
51
|
-
# define FORCE_INLINE static
|
|
52
|
-
# endif /* __STDC_VERSION__ */
|
|
53
|
-
#endif
|
|
54
|
-
|
|
55
|
-
|
|
56
35
|
/* **************************************************************
|
|
57
36
|
* Includes
|
|
58
37
|
****************************************************************/
|
|
@@ -60,13 +39,16 @@
|
|
|
60
39
|
#include <string.h> /* memcpy, memset */
|
|
61
40
|
#include <stdio.h> /* printf (debug) */
|
|
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
|
/* **************************************************************
|
|
68
49
|
* Error Management
|
|
69
50
|
****************************************************************/
|
|
51
|
+
#define FSE_isError ERR_isError
|
|
70
52
|
#define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
|
71
53
|
|
|
72
54
|
|
|
@@ -291,7 +273,7 @@ static size_t FSE_writeNCount_generic (void* header, size_t headerBufferSize,
|
|
|
291
273
|
|
|
292
274
|
size_t FSE_writeNCount (void* buffer, size_t bufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
|
|
293
275
|
{
|
|
294
|
-
if (tableLog > FSE_MAX_TABLELOG) return ERROR(
|
|
276
|
+
if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); /* Unsupported */
|
|
295
277
|
if (tableLog < FSE_MIN_TABLELOG) return ERROR(GENERIC); /* Unsupported */
|
|
296
278
|
|
|
297
279
|
if (bufferSize < FSE_NCountWriteBound(maxSymbolValue, tableLog))
|
|
@@ -476,20 +458,22 @@ void FSE_freeCTable (FSE_CTable* ct) { free(ct); }
|
|
|
476
458
|
/* provides the minimum logSize to safely represent a distribution */
|
|
477
459
|
static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
|
|
478
460
|
{
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
461
|
+
U32 minBitsSrc = BIT_highbit32((U32)(srcSize - 1)) + 1;
|
|
462
|
+
U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2;
|
|
463
|
+
U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
|
|
464
|
+
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
|
465
|
+
return minBits;
|
|
483
466
|
}
|
|
484
467
|
|
|
485
468
|
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
|
|
486
469
|
{
|
|
487
|
-
|
|
470
|
+
U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
|
|
488
471
|
U32 tableLog = maxTableLog;
|
|
489
|
-
|
|
472
|
+
U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
|
|
473
|
+
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
|
490
474
|
if (tableLog==0) tableLog = FSE_DEFAULT_TABLELOG;
|
|
491
|
-
|
|
492
|
-
|
|
475
|
+
if (maxBitsSrc < tableLog) tableLog = maxBitsSrc; /* Accuracy can be reduced */
|
|
476
|
+
if (minBits > tableLog) tableLog = minBits; /* Need a minimum to safely represent all symbol values */
|
|
493
477
|
if (tableLog < FSE_MIN_TABLELOG) tableLog = FSE_MIN_TABLELOG;
|
|
494
478
|
if (tableLog > FSE_MAX_TABLELOG) tableLog = FSE_MAX_TABLELOG;
|
|
495
479
|
return tableLog;
|
|
@@ -598,7 +582,7 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
|
|
598
582
|
if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); /* Unsupported size */
|
|
599
583
|
if (tableLog < FSE_minTableLog(total, maxSymbolValue)) return ERROR(GENERIC); /* Too small tableLog, compression potentially impossible */
|
|
600
584
|
|
|
601
|
-
{ U32 const rtbTable[] = { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
|
|
585
|
+
{ static U32 const rtbTable[] = { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
|
|
602
586
|
U64 const scale = 62 - tableLog;
|
|
603
587
|
U64 const step = ((U64)1<<62) / total; /* <== here, one division ! */
|
|
604
588
|
U64 const vStep = 1ULL<<(scale-20);
|
|
@@ -781,7 +765,7 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
|
|
|
781
765
|
|
|
782
766
|
size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
|
|
783
767
|
|
|
784
|
-
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return
|
|
768
|
+
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
|
785
769
|
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
|
786
770
|
|
|
787
771
|
/* FSE_compress_wksp() :
|
|
@@ -808,7 +792,7 @@ size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t src
|
|
|
808
792
|
if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
|
|
809
793
|
|
|
810
794
|
/* Scan input and build symbol stats */
|
|
811
|
-
{ CHECK_V_F(maxCount,
|
|
795
|
+
{ CHECK_V_F(maxCount, FSE_count_wksp(count, &maxSymbolValue, src, srcSize, (unsigned*)scratchBuffer) );
|
|
812
796
|
if (maxCount == srcSize) return 1; /* only a single symbol in src : rle */
|
|
813
797
|
if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */
|
|
814
798
|
if (maxCount < (srcSize >> 7)) return 0; /* Heuristic : not compressible enough */
|
|
@@ -50,13 +50,15 @@
|
|
|
50
50
|
#include "fse.h" /* header compression */
|
|
51
51
|
#define HUF_STATIC_LINKING_ONLY
|
|
52
52
|
#include "huf.h"
|
|
53
|
+
#include "error_private.h"
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
/* **************************************************************
|
|
56
57
|
* Error Management
|
|
57
58
|
****************************************************************/
|
|
59
|
+
#define HUF_isError ERR_isError
|
|
58
60
|
#define HUF_STATIC_ASSERT(c) { enum { HUF_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
|
59
|
-
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return
|
|
61
|
+
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
|
60
62
|
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
|
61
63
|
|
|
62
64
|
|
|
@@ -165,7 +167,7 @@ size_t HUF_writeCTable (void* dst, size_t maxDstSize,
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
|
|
168
|
-
size_t HUF_readCTable (HUF_CElt* CTable, U32
|
|
170
|
+
size_t HUF_readCTable (HUF_CElt* CTable, U32* maxSymbolValuePtr, const void* src, size_t srcSize)
|
|
169
171
|
{
|
|
170
172
|
BYTE huffWeight[HUF_SYMBOLVALUE_MAX + 1]; /* init not required, even though some static analyzer may complain */
|
|
171
173
|
U32 rankVal[HUF_TABLELOG_ABSOLUTEMAX + 1]; /* large enough for values from 0 to 16 */
|
|
@@ -177,7 +179,7 @@ size_t HUF_readCTable (HUF_CElt* CTable, U32 maxSymbolValue, const void* src, si
|
|
|
177
179
|
|
|
178
180
|
/* check result */
|
|
179
181
|
if (tableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
|
|
180
|
-
if (nbSymbols >
|
|
182
|
+
if (nbSymbols > *maxSymbolValuePtr+1) return ERROR(maxSymbolValue_tooSmall);
|
|
181
183
|
|
|
182
184
|
/* Prepare base value per rank */
|
|
183
185
|
{ U32 n, nextRankStart = 0;
|
|
@@ -206,9 +208,10 @@ size_t HUF_readCTable (HUF_CElt* CTable, U32 maxSymbolValue, const void* src, si
|
|
|
206
208
|
min >>= 1;
|
|
207
209
|
} }
|
|
208
210
|
/* assign value within rank, symbol order */
|
|
209
|
-
{ U32 n; for (n=0; n
|
|
211
|
+
{ U32 n; for (n=0; n<nbSymbols; n++) CTable[n].val = valPerRank[CTable[n].nbBits]++; }
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
*maxSymbolValuePtr = nbSymbols - 1;
|
|
212
215
|
return readSize;
|
|
213
216
|
}
|
|
214
217
|
|
|
@@ -266,7 +269,8 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|
|
266
269
|
if (highTotal <= lowTotal) break;
|
|
267
270
|
} }
|
|
268
271
|
/* only triggered when no more rank 1 symbol left => find closest one (note : there is necessarily at least one !) */
|
|
269
|
-
|
|
272
|
+
/* HUF_MAX_TABLELOG test just to please gcc 5+; but it should not be necessary */
|
|
273
|
+
while ((nBitsToDecrease<=HUF_TABLELOG_MAX) && (rankLast[nBitsToDecrease] == noSymbol))
|
|
270
274
|
nBitsToDecrease ++;
|
|
271
275
|
totalCost -= 1 << (nBitsToDecrease-1);
|
|
272
276
|
if (rankLast[nBitsToDecrease-1] == noSymbol)
|
|
@@ -435,7 +439,7 @@ static void HUF_encodeSymbol(BIT_CStream_t* bitCPtr, U32 symbol, const HUF_CElt*
|
|
|
435
439
|
|
|
436
440
|
size_t HUF_compressBound(size_t size) { return HUF_COMPRESSBOUND(size); }
|
|
437
441
|
|
|
438
|
-
#define HUF_FLUSHBITS(s)
|
|
442
|
+
#define HUF_FLUSHBITS(s) BIT_flushBits(s)
|
|
439
443
|
|
|
440
444
|
#define HUF_FLUSHBITS_1(stream) \
|
|
441
445
|
if (sizeof((stream)->bitContainer)*8 < HUF_TABLELOG_MAX*2+7) HUF_FLUSHBITS(stream)
|
|
@@ -450,7 +454,6 @@ size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, si
|
|
|
450
454
|
BYTE* const oend = ostart + dstSize;
|
|
451
455
|
BYTE* op = ostart;
|
|
452
456
|
size_t n;
|
|
453
|
-
const unsigned fast = (dstSize >= HUF_BLOCKBOUND(srcSize));
|
|
454
457
|
BIT_CStream_t bitC;
|
|
455
458
|
|
|
456
459
|
/* init */
|
|
@@ -463,12 +466,15 @@ size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, si
|
|
|
463
466
|
{
|
|
464
467
|
case 3 : HUF_encodeSymbol(&bitC, ip[n+ 2], CTable);
|
|
465
468
|
HUF_FLUSHBITS_2(&bitC);
|
|
469
|
+
/* fall-through */
|
|
466
470
|
case 2 : HUF_encodeSymbol(&bitC, ip[n+ 1], CTable);
|
|
467
471
|
HUF_FLUSHBITS_1(&bitC);
|
|
472
|
+
/* fall-through */
|
|
468
473
|
case 1 : HUF_encodeSymbol(&bitC, ip[n+ 0], CTable);
|
|
469
474
|
HUF_FLUSHBITS(&bitC);
|
|
470
|
-
|
|
471
|
-
|
|
475
|
+
/* fall-through */
|
|
476
|
+
case 0 : /* fall-through */
|
|
477
|
+
default: break;
|
|
472
478
|
}
|
|
473
479
|
|
|
474
480
|
for (; n>0; n-=4) { /* note : n&3==0 at this stage */
|