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
@@ -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(GENERIC); /* Unsupported */
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
- U32 minBitsSrc = BIT_highbit32((U32)(srcSize - 1)) + 1;
480
- U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2;
481
- U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
482
- return minBits;
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
- U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
470
+ U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
488
471
  U32 tableLog = maxTableLog;
489
- U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
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
- if (maxBitsSrc < tableLog) tableLog = maxBitsSrc; /* Accuracy can be reduced */
492
- if (minBits > tableLog) tableLog = minBits; /* Need a minimum to safely represent all symbol values */
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 f
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, FSE_count(count, &maxSymbolValue, src, srcSize) );
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 f
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 maxSymbolValue, const void* src, size_t srcSize)
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 > maxSymbolValue+1) return ERROR(maxSymbolValue_tooSmall);
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<=maxSymbolValue; n++) CTable[n].val = valPerRank[CTable[n].nbBits]++; }
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
- while ((nBitsToDecrease<=HUF_TABLELOG_MAX) && (rankLast[nBitsToDecrease] == noSymbol)) /* HUF_MAX_TABLELOG test just to please gcc 5+; but it should not be necessary */
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) (fast ? BIT_flushBitsFast(s) : BIT_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
- case 0 :
471
- default: ;
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 */