multi_compress 0.6.1 → 0.7.0
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 +4 -4
- data/CHANGELOG.md +41 -0
- data/GET_STARTED.md +4 -2
- data/README.md +1 -1
- data/THIRD_PARTY_NOTICES.md +2 -2
- data/ext/multi_compress/exports.darwin +1 -0
- data/ext/multi_compress/exports.map +4 -0
- data/ext/multi_compress/extconf.rb +20 -0
- data/ext/multi_compress/multi_compress.c +123 -73
- data/ext/multi_compress/vendor/.vendored +1 -1
- data/ext/multi_compress/vendor/zstd/lib/BUCK +10 -5
- data/ext/multi_compress/vendor/zstd/lib/README.md +25 -5
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +6 -2
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +3 -3
- data/ext/multi_compress/vendor/zstd/lib/common/bmi2.h +40 -0
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +37 -11
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +7 -6
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +4 -3
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +16 -19
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +31 -0
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +16 -2
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +9 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +4 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +300 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +4 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +4 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +775 -214
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +35 -6
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +9 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +14 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +49 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +11 -11
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +16 -18
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +64 -39
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +30 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +78 -64
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +182 -18
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +59 -27
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +194 -93
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +225 -85
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +19 -2
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +136 -91
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +77 -77
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +48 -42
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +18 -14
- data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +66 -20
- data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +10 -6
- data/ext/multi_compress/vendor/zstd/lib/install_oses.mk +17 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +10 -8
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +5 -364
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +4 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +7 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +8 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +1 -0
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +8 -7
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +1 -0
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +0 -21
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +209 -112
- data/lib/multi_compress/reader/read_operations.rb +2 -0
- data/lib/multi_compress/version.rb +1 -1
- data/multi_compress.gemspec +2 -0
- data/mysql_udf/Makefile +12 -5
- data/mysql_udf/multi_compress_mysql.exports +6 -0
- data/postgres_extension/Makefile +2 -1
- data/postgres_extension/test/run_e2e.sh +28 -10
- metadata +6 -5
- data/ext/multi_compress/vendor/lz4/lib/Makefile +0 -244
- data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +0 -63
- data/ext/multi_compress/vendor/zstd/lib/Makefile +0 -389
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +0 -48
|
@@ -49,38 +49,30 @@
|
|
|
49
49
|
|
|
50
50
|
/*-*************************************
|
|
51
51
|
* Console display
|
|
52
|
+
*
|
|
53
|
+
* Captures the `displayLevel` variable in the local scope.
|
|
52
54
|
***************************************/
|
|
53
|
-
#ifndef LOCALDISPLAYLEVEL
|
|
54
|
-
static int g_displayLevel = 0;
|
|
55
|
-
#endif
|
|
56
55
|
#undef DISPLAY
|
|
57
56
|
#define DISPLAY(...) \
|
|
58
57
|
{ \
|
|
59
58
|
fprintf(stderr, __VA_ARGS__); \
|
|
60
59
|
fflush(stderr); \
|
|
61
60
|
}
|
|
62
|
-
#undef
|
|
63
|
-
#define
|
|
61
|
+
#undef DISPLAYLEVEL
|
|
62
|
+
#define DISPLAYLEVEL(l, ...) \
|
|
64
63
|
if (displayLevel >= l) { \
|
|
65
64
|
DISPLAY(__VA_ARGS__); \
|
|
66
65
|
} /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
|
67
|
-
#undef DISPLAYLEVEL
|
|
68
|
-
#define DISPLAYLEVEL(l, ...) LOCALDISPLAYLEVEL(g_displayLevel, l, __VA_ARGS__)
|
|
69
66
|
|
|
70
|
-
#
|
|
71
|
-
|
|
72
|
-
static clock_t g_time = 0;
|
|
73
|
-
#endif
|
|
74
|
-
#undef LOCALDISPLAYUPDATE
|
|
75
|
-
#define LOCALDISPLAYUPDATE(displayLevel, l, ...) \
|
|
67
|
+
#undef DISPLAYUPDATE
|
|
68
|
+
#define DISPLAYUPDATE(lastUpdateTime, l, ...) \
|
|
76
69
|
if (displayLevel >= l) { \
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100; \
|
|
71
|
+
if ((clock() - lastUpdateTime > refreshRate) || (displayLevel >= 4)) { \
|
|
72
|
+
lastUpdateTime = clock(); \
|
|
79
73
|
DISPLAY(__VA_ARGS__); \
|
|
80
74
|
} \
|
|
81
75
|
}
|
|
82
|
-
#undef DISPLAYUPDATE
|
|
83
|
-
#define DISPLAYUPDATE(l, ...) LOCALDISPLAYUPDATE(g_displayLevel, l, __VA_ARGS__)
|
|
84
76
|
|
|
85
77
|
|
|
86
78
|
/*-*************************************
|
|
@@ -136,6 +128,7 @@ typedef struct {
|
|
|
136
128
|
unsigned d;
|
|
137
129
|
unsigned f;
|
|
138
130
|
FASTCOVER_accel_t accelParams;
|
|
131
|
+
int displayLevel;
|
|
139
132
|
} FASTCOVER_ctx_t;
|
|
140
133
|
|
|
141
134
|
|
|
@@ -314,7 +307,8 @@ FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx,
|
|
|
314
307
|
const void* samplesBuffer,
|
|
315
308
|
const size_t* samplesSizes, unsigned nbSamples,
|
|
316
309
|
unsigned d, double splitPoint, unsigned f,
|
|
317
|
-
FASTCOVER_accel_t accelParams
|
|
310
|
+
FASTCOVER_accel_t accelParams,
|
|
311
|
+
int displayLevel)
|
|
318
312
|
{
|
|
319
313
|
const BYTE* const samples = (const BYTE*)samplesBuffer;
|
|
320
314
|
const size_t totalSamplesSize = COVER_sum(samplesSizes, nbSamples);
|
|
@@ -323,9 +317,11 @@ FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx,
|
|
|
323
317
|
const unsigned nbTestSamples = splitPoint < 1.0 ? nbSamples - nbTrainSamples : nbSamples;
|
|
324
318
|
const size_t trainingSamplesSize = splitPoint < 1.0 ? COVER_sum(samplesSizes, nbTrainSamples) : totalSamplesSize;
|
|
325
319
|
const size_t testSamplesSize = splitPoint < 1.0 ? COVER_sum(samplesSizes + nbTrainSamples, nbTestSamples) : totalSamplesSize;
|
|
320
|
+
const size_t readLength = MAX(d, sizeof(U64));
|
|
321
|
+
ctx->displayLevel = displayLevel;
|
|
326
322
|
|
|
327
323
|
/* Checks */
|
|
328
|
-
if (totalSamplesSize <
|
|
324
|
+
if (totalSamplesSize < readLength ||
|
|
329
325
|
totalSamplesSize >= (size_t)FASTCOVER_MAX_SAMPLES_SIZE) {
|
|
330
326
|
DISPLAYLEVEL(1, "Total samples size is too large (%u MB), maximum size is %u MB\n",
|
|
331
327
|
(unsigned)(totalSamplesSize >> 20), (FASTCOVER_MAX_SAMPLES_SIZE >> 20));
|
|
@@ -344,6 +340,12 @@ FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx,
|
|
|
344
340
|
return ERROR(srcSize_wrong);
|
|
345
341
|
}
|
|
346
342
|
|
|
343
|
+
/* Check the training set can hold at least one dmer, otherwise nbDmers underflows below */
|
|
344
|
+
if (trainingSamplesSize < readLength) {
|
|
345
|
+
DISPLAYLEVEL(1, "Total training samples size is %u and is invalid.\n", (unsigned)trainingSamplesSize);
|
|
346
|
+
return ERROR(srcSize_wrong);
|
|
347
|
+
}
|
|
348
|
+
|
|
347
349
|
/* Zero the context */
|
|
348
350
|
memset(ctx, 0, sizeof(*ctx));
|
|
349
351
|
DISPLAYLEVEL(2, "Training on %u samples of total size %u\n", nbTrainSamples,
|
|
@@ -356,7 +358,7 @@ FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx,
|
|
|
356
358
|
ctx->nbSamples = nbSamples;
|
|
357
359
|
ctx->nbTrainSamples = nbTrainSamples;
|
|
358
360
|
ctx->nbTestSamples = nbTestSamples;
|
|
359
|
-
ctx->nbDmers = trainingSamplesSize -
|
|
361
|
+
ctx->nbDmers = trainingSamplesSize - readLength + 1;
|
|
360
362
|
ctx->d = d;
|
|
361
363
|
ctx->f = f;
|
|
362
364
|
ctx->accelParams = accelParams;
|
|
@@ -409,7 +411,9 @@ FASTCOVER_buildDictionary(const FASTCOVER_ctx_t* ctx,
|
|
|
409
411
|
const COVER_epoch_info_t epochs = COVER_computeEpochs(
|
|
410
412
|
(U32)dictBufferCapacity, (U32)ctx->nbDmers, parameters.k, 1);
|
|
411
413
|
const size_t maxZeroScoreRun = 10;
|
|
414
|
+
const int displayLevel = ctx->displayLevel;
|
|
412
415
|
size_t zeroScoreRun = 0;
|
|
416
|
+
clock_t lastUpdateTime = 0;
|
|
413
417
|
size_t epoch;
|
|
414
418
|
DISPLAYLEVEL(2, "Breaking content into %u epochs of size %u\n",
|
|
415
419
|
(U32)epochs.num, (U32)epochs.size);
|
|
@@ -447,6 +451,7 @@ FASTCOVER_buildDictionary(const FASTCOVER_ctx_t* ctx,
|
|
|
447
451
|
tail -= segmentSize;
|
|
448
452
|
memcpy(dict + tail, ctx->samples + segment.begin, segmentSize);
|
|
449
453
|
DISPLAYUPDATE(
|
|
454
|
+
lastUpdateTime,
|
|
450
455
|
2, "\r%u%% ",
|
|
451
456
|
(unsigned)(((dictBufferCapacity - tail) * 100) / dictBufferCapacity));
|
|
452
457
|
}
|
|
@@ -484,6 +489,7 @@ static void FASTCOVER_tryParameters(void* opaque)
|
|
|
484
489
|
BYTE *const dict = (BYTE*)malloc(dictBufferCapacity);
|
|
485
490
|
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
|
|
486
491
|
U32* freqs = (U32*) malloc(((U64)1 << ctx->f) * sizeof(U32));
|
|
492
|
+
const int displayLevel = ctx->displayLevel;
|
|
487
493
|
if (!segmentFreqs || !dict || !freqs) {
|
|
488
494
|
DISPLAYLEVEL(1, "Failed to allocate buffers: out of memory\n");
|
|
489
495
|
goto _cleanup;
|
|
@@ -555,8 +561,7 @@ ZDICT_trainFromBuffer_fastCover(void* dictBuffer, size_t dictBufferCapacity,
|
|
|
555
561
|
FASTCOVER_ctx_t ctx;
|
|
556
562
|
ZDICT_cover_params_t coverParams;
|
|
557
563
|
FASTCOVER_accel_t accelParams;
|
|
558
|
-
|
|
559
|
-
g_displayLevel = (int)parameters.zParams.notificationLevel;
|
|
564
|
+
const int displayLevel = (int)parameters.zParams.notificationLevel;
|
|
560
565
|
/* Assign splitPoint and f if not provided */
|
|
561
566
|
parameters.splitPoint = 1.0;
|
|
562
567
|
parameters.f = parameters.f == 0 ? DEFAULT_F : parameters.f;
|
|
@@ -585,13 +590,13 @@ ZDICT_trainFromBuffer_fastCover(void* dictBuffer, size_t dictBufferCapacity,
|
|
|
585
590
|
{
|
|
586
591
|
size_t const initVal = FASTCOVER_ctx_init(&ctx, samplesBuffer, samplesSizes, nbSamples,
|
|
587
592
|
coverParams.d, parameters.splitPoint, parameters.f,
|
|
588
|
-
accelParams);
|
|
593
|
+
accelParams, displayLevel);
|
|
589
594
|
if (ZSTD_isError(initVal)) {
|
|
590
595
|
DISPLAYLEVEL(1, "Failed to initialize context\n");
|
|
591
596
|
return initVal;
|
|
592
597
|
}
|
|
593
598
|
}
|
|
594
|
-
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.nbDmers,
|
|
599
|
+
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.nbDmers, displayLevel);
|
|
595
600
|
/* Build the dictionary */
|
|
596
601
|
DISPLAYLEVEL(2, "Building dictionary\n");
|
|
597
602
|
{
|
|
@@ -646,25 +651,26 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|
|
646
651
|
COVER_best_t best;
|
|
647
652
|
POOL_ctx *pool = NULL;
|
|
648
653
|
int warned = 0;
|
|
654
|
+
clock_t lastUpdateTime = 0;
|
|
649
655
|
/* Checks */
|
|
650
656
|
if (splitPoint <= 0 || splitPoint > 1) {
|
|
651
|
-
|
|
657
|
+
DISPLAYLEVEL(1, "Incorrect splitPoint\n");
|
|
652
658
|
return ERROR(parameter_outOfBound);
|
|
653
659
|
}
|
|
654
660
|
if (accel == 0 || accel > FASTCOVER_MAX_ACCEL) {
|
|
655
|
-
|
|
661
|
+
DISPLAYLEVEL(1, "Incorrect accel\n");
|
|
656
662
|
return ERROR(parameter_outOfBound);
|
|
657
663
|
}
|
|
658
664
|
if (kMinK < kMaxD || kMaxK < kMinK) {
|
|
659
|
-
|
|
665
|
+
DISPLAYLEVEL(1, "Incorrect k\n");
|
|
660
666
|
return ERROR(parameter_outOfBound);
|
|
661
667
|
}
|
|
662
668
|
if (nbSamples == 0) {
|
|
663
|
-
|
|
669
|
+
DISPLAYLEVEL(1, "FASTCOVER must have at least one input file\n");
|
|
664
670
|
return ERROR(srcSize_wrong);
|
|
665
671
|
}
|
|
666
672
|
if (dictBufferCapacity < ZDICT_DICTSIZE_MIN) {
|
|
667
|
-
|
|
673
|
+
DISPLAYLEVEL(1, "dictBufferCapacity must be at least %u\n",
|
|
668
674
|
ZDICT_DICTSIZE_MIN);
|
|
669
675
|
return ERROR(dstSize_tooSmall);
|
|
670
676
|
}
|
|
@@ -679,19 +685,18 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|
|
679
685
|
memset(&coverParams, 0 , sizeof(coverParams));
|
|
680
686
|
FASTCOVER_convertToCoverParams(*parameters, &coverParams);
|
|
681
687
|
accelParams = FASTCOVER_defaultAccelParameters[accel];
|
|
682
|
-
/* Turn down global display level to clean up display at level 2 and below */
|
|
683
|
-
g_displayLevel = displayLevel == 0 ? 0 : displayLevel - 1;
|
|
684
688
|
/* Loop through d first because each new value needs a new context */
|
|
685
|
-
|
|
686
|
-
kIterations);
|
|
689
|
+
DISPLAYLEVEL(2, "Trying %u different sets of parameters\n", kIterations);
|
|
687
690
|
for (d = kMinD; d <= kMaxD; d += 2) {
|
|
688
691
|
/* Initialize the context for this value of d */
|
|
689
692
|
FASTCOVER_ctx_t ctx;
|
|
690
|
-
|
|
693
|
+
DISPLAYLEVEL(3, "d=%u\n", d);
|
|
691
694
|
{
|
|
692
|
-
|
|
695
|
+
/* Turn down global display level to clean up display at level 2 and below */
|
|
696
|
+
const int childDisplayLevel = displayLevel == 0 ? 0 : displayLevel - 1;
|
|
697
|
+
size_t const initVal = FASTCOVER_ctx_init(&ctx, samplesBuffer, samplesSizes, nbSamples, d, splitPoint, f, accelParams, childDisplayLevel);
|
|
693
698
|
if (ZSTD_isError(initVal)) {
|
|
694
|
-
|
|
699
|
+
DISPLAYLEVEL(1, "Failed to initialize context\n");
|
|
695
700
|
COVER_best_destroy(&best);
|
|
696
701
|
POOL_free(pool);
|
|
697
702
|
return initVal;
|
|
@@ -706,9 +711,9 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|
|
706
711
|
/* Prepare the arguments */
|
|
707
712
|
FASTCOVER_tryParameters_data_t *data = (FASTCOVER_tryParameters_data_t *)malloc(
|
|
708
713
|
sizeof(FASTCOVER_tryParameters_data_t));
|
|
709
|
-
|
|
714
|
+
DISPLAYLEVEL(3, "k=%u\n", k);
|
|
710
715
|
if (!data) {
|
|
711
|
-
|
|
716
|
+
DISPLAYLEVEL(1, "Failed to allocate parameters\n");
|
|
712
717
|
COVER_best_destroy(&best);
|
|
713
718
|
FASTCOVER_ctx_destroy(&ctx);
|
|
714
719
|
POOL_free(pool);
|
|
@@ -723,7 +728,7 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|
|
723
728
|
data->parameters.splitPoint = splitPoint;
|
|
724
729
|
data->parameters.steps = kSteps;
|
|
725
730
|
data->parameters.shrinkDict = shrinkDict;
|
|
726
|
-
data->parameters.zParams.notificationLevel = (unsigned)
|
|
731
|
+
data->parameters.zParams.notificationLevel = (unsigned)ctx.displayLevel;
|
|
727
732
|
/* Check the parameters */
|
|
728
733
|
if (!FASTCOVER_checkParameters(data->parameters, dictBufferCapacity,
|
|
729
734
|
data->ctx->f, accel)) {
|
|
@@ -739,14 +744,15 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|
|
739
744
|
FASTCOVER_tryParameters(data);
|
|
740
745
|
}
|
|
741
746
|
/* Print status */
|
|
742
|
-
|
|
743
|
-
|
|
747
|
+
DISPLAYUPDATE(lastUpdateTime,
|
|
748
|
+
2, "\r%u%% ",
|
|
749
|
+
(unsigned)((iteration * 100) / kIterations));
|
|
744
750
|
++iteration;
|
|
745
751
|
}
|
|
746
752
|
COVER_best_wait(&best);
|
|
747
753
|
FASTCOVER_ctx_destroy(&ctx);
|
|
748
754
|
}
|
|
749
|
-
|
|
755
|
+
DISPLAYLEVEL(2, "\r%79s\r", "");
|
|
750
756
|
/* Fill the output buffer and parameters with output of the best parameters */
|
|
751
757
|
{
|
|
752
758
|
const size_t dictSize = best.dictSize;
|
|
@@ -168,7 +168,7 @@ static void ZDICT_initDictItem(dictItem* d)
|
|
|
168
168
|
#define MINMATCHLENGTH 7 /* heuristic determined experimentally */
|
|
169
169
|
static dictItem ZDICT_analyzePos(
|
|
170
170
|
BYTE* doneMarks,
|
|
171
|
-
const
|
|
171
|
+
const unsigned* suffix, U32 start,
|
|
172
172
|
const void* buffer, U32 minRatio, U32 notificationLevel)
|
|
173
173
|
{
|
|
174
174
|
U32 lengthList[LLIMIT] = {0};
|
|
@@ -293,8 +293,10 @@ static dictItem ZDICT_analyzePos(
|
|
|
293
293
|
for (i=(int)(maxLength-2); i>=0; i--)
|
|
294
294
|
cumulLength[i] = cumulLength[i+1] + lengthList[i];
|
|
295
295
|
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
{ unsigned u;
|
|
297
|
+
for (u=LLIMIT-1; u>=MINMATCHLENGTH; u--) if (cumulLength[u]>=minRatio) break;
|
|
298
|
+
maxLength = u;
|
|
299
|
+
}
|
|
298
300
|
|
|
299
301
|
/* reduce maxLength in case of final into repetitive data */
|
|
300
302
|
{ U32 l = (U32)maxLength;
|
|
@@ -306,8 +308,10 @@ static dictItem ZDICT_analyzePos(
|
|
|
306
308
|
|
|
307
309
|
/* calculate savings */
|
|
308
310
|
savings[5] = 0;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
+
{ unsigned u;
|
|
312
|
+
for (u=MINMATCHLENGTH; u<=maxLength; u++)
|
|
313
|
+
savings[u] = savings[u-1] + (lengthList[u] * (u-3));
|
|
314
|
+
}
|
|
311
315
|
|
|
312
316
|
DISPLAYLEVEL(4, "Selected dict at position %u, of length %u : saves %u (ratio: %.2f) \n",
|
|
313
317
|
(unsigned)pos, (unsigned)maxLength, (unsigned)savings[maxLength], (double)savings[maxLength] / (double)maxLength);
|
|
@@ -383,11 +387,11 @@ static U32 ZDICT_tryMerge(dictItem* table, dictItem elt, U32 eltNbToSkip, const
|
|
|
383
387
|
|
|
384
388
|
if ((table[u].pos + table[u].length >= elt.pos) && (table[u].pos < elt.pos)) { /* overlap, existing < new */
|
|
385
389
|
/* append */
|
|
386
|
-
int const addedLength = (int)eltEnd - (int)(table[u].pos + table[u].length);
|
|
390
|
+
int const addedLength = (int)eltEnd - (int)(table[u].pos + table[u].length); /* note: can be negative */
|
|
387
391
|
table[u].savings += elt.length / 8; /* rough approx bonus */
|
|
388
392
|
if (addedLength > 0) { /* otherwise, elt fully included into existing */
|
|
389
|
-
table[u].length += addedLength;
|
|
390
|
-
table[u].savings += elt.savings * addedLength / elt.length; /* rough approx */
|
|
393
|
+
table[u].length += (unsigned)addedLength;
|
|
394
|
+
table[u].savings += elt.savings * (unsigned)addedLength / elt.length; /* rough approx */
|
|
391
395
|
}
|
|
392
396
|
/* sort : improve rank */
|
|
393
397
|
elt = table[u];
|
|
@@ -399,7 +403,7 @@ static U32 ZDICT_tryMerge(dictItem* table, dictItem elt, U32 eltNbToSkip, const
|
|
|
399
403
|
|
|
400
404
|
if (MEM_read64(buf + table[u].pos) == MEM_read64(buf + elt.pos + 1)) {
|
|
401
405
|
if (isIncluded(buf + table[u].pos, buf + elt.pos + 1, table[u].length)) {
|
|
402
|
-
size_t const addedLength = MAX(
|
|
406
|
+
size_t const addedLength = MAX( elt.length - table[u].length , 1 );
|
|
403
407
|
table[u].pos = elt.pos;
|
|
404
408
|
table[u].savings += (U32)(elt.savings * addedLength / elt.length);
|
|
405
409
|
table[u].length = MIN(elt.length, table[u].length + 1);
|
|
@@ -467,8 +471,8 @@ static size_t ZDICT_trainBuffer_legacy(dictItem* dictList, U32 dictListSize,
|
|
|
467
471
|
const size_t* fileSizes, unsigned nbFiles,
|
|
468
472
|
unsigned minRatio, U32 notificationLevel)
|
|
469
473
|
{
|
|
470
|
-
|
|
471
|
-
|
|
474
|
+
unsigned* const suffix0 = (unsigned*)malloc((bufferSize+2)*sizeof(*suffix0));
|
|
475
|
+
unsigned* const suffix = suffix0+1;
|
|
472
476
|
U32* reverseSuffix = (U32*)malloc((bufferSize)*sizeof(*reverseSuffix));
|
|
473
477
|
BYTE* doneMarks = (BYTE*)malloc((bufferSize+16)*sizeof(*doneMarks)); /* +16 for overflow security */
|
|
474
478
|
U32* filePos = (U32*)malloc(nbFiles * sizeof(*filePos));
|
|
@@ -503,11 +507,11 @@ static size_t ZDICT_trainBuffer_legacy(dictItem* dictList, U32 dictListSize,
|
|
|
503
507
|
|
|
504
508
|
/* sort */
|
|
505
509
|
DISPLAYLEVEL(2, "sorting %u files of total size %u MB ...\n", nbFiles, (unsigned)(bufferSize>>20));
|
|
506
|
-
{ int const divSuftSortResult = divsufsort((const unsigned char*)buffer, suffix, (int)bufferSize, 0);
|
|
510
|
+
{ int const divSuftSortResult = divsufsort((const unsigned char*)buffer, (int*)suffix, (int)bufferSize, 0);
|
|
507
511
|
if (divSuftSortResult != 0) { result = ERROR(GENERIC); goto _cleanup; }
|
|
508
512
|
}
|
|
509
|
-
suffix[bufferSize] = (
|
|
510
|
-
suffix0[0] = (
|
|
513
|
+
suffix[bufferSize] = (unsigned)bufferSize; /* leads into noise */
|
|
514
|
+
suffix0[0] = (unsigned)bufferSize; /* leads into noise */
|
|
511
515
|
/* build reverse suffix sort */
|
|
512
516
|
{ size_t pos;
|
|
513
517
|
for (pos=0; pos < bufferSize; pos++)
|
|
@@ -1,20 +1,66 @@
|
|
|
1
|
-
@
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
|
|
4
|
+
rem Detect build type based on available files
|
|
5
|
+
set BUILD_TYPE=make
|
|
6
|
+
if exist "build\cmake\build\lib\Release\zstd_static.lib" set BUILD_TYPE=cmake
|
|
7
|
+
|
|
8
|
+
echo Detected build type: %BUILD_TYPE%
|
|
9
|
+
|
|
10
|
+
rem Create required directories
|
|
11
|
+
mkdir bin\dll bin\static bin\example bin\include bin\example\tests bin\example\programs bin\example\lib\common
|
|
12
|
+
|
|
13
|
+
rem Copy common files using a subroutine. Exits immediately on failure.
|
|
14
|
+
call :copyFile "tests\fullbench.c" "bin\example\tests\"
|
|
15
|
+
call :copyFile "programs\datagen.c" "bin\example\programs\"
|
|
16
|
+
call :copyFile "programs\datagen.h" "bin\example\programs\"
|
|
17
|
+
call :copyFile "programs\lorem.c" "bin\example\programs\"
|
|
18
|
+
call :copyFile "programs\lorem.h" "bin\example\programs\"
|
|
19
|
+
call :copyFile "programs\util.c" "bin\example\programs\"
|
|
20
|
+
call :copyFile "programs\util.h" "bin\example\programs\"
|
|
21
|
+
call :copyFile "programs\timefn.c" "bin\example\programs\"
|
|
22
|
+
call :copyFile "programs\timefn.h" "bin\example\programs\"
|
|
23
|
+
call :copyFile "programs\benchfn.c" "bin\example\programs\"
|
|
24
|
+
call :copyFile "programs\benchfn.h" "bin\example\programs\"
|
|
25
|
+
call :copyFile "programs\benchzstd.h" "bin\example\programs\"
|
|
26
|
+
call :copyFile "programs\platform.h" "bin\example\programs\"
|
|
27
|
+
call :copyFile "lib\zstd.h" "bin\example\lib\"
|
|
28
|
+
call :copyFile "lib\common\mem.h" "bin\example\lib\common\"
|
|
29
|
+
call :copyFile "lib\common\compiler.h" "bin\example\lib\common\"
|
|
30
|
+
call :copyFile "lib\common\debug.h" "bin\example\lib\common\"
|
|
31
|
+
call :copyFile "lib\common\portability_macros.h" "bin\example\lib\common\"
|
|
32
|
+
call :copyFile "lib\common\zstd_deps.h" "bin\example\lib\common\"
|
|
33
|
+
call :copyFile "lib\dll\example\Makefile" "bin\example\"
|
|
34
|
+
call :copyFile "lib\dll\example\fullbench-dll.*" "bin\example\"
|
|
35
|
+
call :copyFile "lib\zstd.h" "bin\include\"
|
|
36
|
+
call :copyFile "lib\zstd_errors.h" "bin\include\"
|
|
37
|
+
call :copyFile "lib\zdict.h" "bin\include\"
|
|
38
|
+
|
|
39
|
+
rem Copy build-specific files
|
|
40
|
+
if "%BUILD_TYPE%"=="cmake" (
|
|
41
|
+
echo Copying CMake build artifacts...
|
|
42
|
+
call :copyFile "build\cmake\build\lib\Release\zstd_static.lib" "bin\static\libzstd_static.lib"
|
|
43
|
+
call :copyFile "build\cmake\build\lib\Release\zstd.dll" "bin\dll\libzstd.dll"
|
|
44
|
+
call :copyFile "build\cmake\build\lib\Release\zstd.lib" "bin\dll\zstd.lib"
|
|
45
|
+
call :copyFile "build\cmake\build\programs\Release\zstd.exe" "bin\zstd.exe"
|
|
46
|
+
call :copyFile "lib\dll\example\README.md" "bin\README.md"
|
|
47
|
+
) else (
|
|
48
|
+
echo Copying Make build artifacts...
|
|
49
|
+
call :copyFile "lib\libzstd.a" "bin\static\libzstd_static.lib"
|
|
50
|
+
call :copyFile "lib\dll\libzstd.*" "bin\dll\"
|
|
51
|
+
call :copyFile "lib\dll\libzstd.dll.a" "bin\dll\libzstd.lib"
|
|
52
|
+
call :copyFile "programs\zstd.exe" "bin\zstd.exe"
|
|
53
|
+
call :copyFile "lib\dll\example\README.md" "bin\"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
echo Build package created successfully for %BUILD_TYPE% build!
|
|
57
|
+
endlocal
|
|
58
|
+
exit /b 0
|
|
59
|
+
|
|
60
|
+
:copyFile
|
|
61
|
+
copy "%~1" "%~2"
|
|
62
|
+
if errorlevel 1 (
|
|
63
|
+
echo Failed to copy "%~1"
|
|
64
|
+
exit 1
|
|
65
|
+
)
|
|
66
|
+
exit /b
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
94
94
|
<TreatWarningAsError>true</TreatWarningAsError>
|
|
95
95
|
<EnablePREfast>false</EnablePREfast>
|
|
96
|
-
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
|
96
|
+
<AdditionalIncludeDirectories>..\include;lib\common;programs</AdditionalIncludeDirectories>
|
|
97
97
|
</ClCompile>
|
|
98
98
|
<Link>
|
|
99
99
|
<SubSystem>Console</SubSystem>
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
113
113
|
<TreatWarningAsError>true</TreatWarningAsError>
|
|
114
114
|
<EnablePREfast>false</EnablePREfast>
|
|
115
|
-
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
|
115
|
+
<AdditionalIncludeDirectories>..\include;lib\common;programs</AdditionalIncludeDirectories>
|
|
116
116
|
</ClCompile>
|
|
117
117
|
<Link>
|
|
118
118
|
<SubSystem>Console</SubSystem>
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
132
132
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
133
133
|
<EnablePREfast>false</EnablePREfast>
|
|
134
|
-
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
|
134
|
+
<AdditionalIncludeDirectories>..\include;lib\common;programs</AdditionalIncludeDirectories>
|
|
135
135
|
<TreatWarningAsError>false</TreatWarningAsError>
|
|
136
136
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
|
137
137
|
</ClCompile>
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ZSTD_DLL_IMPORT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
157
157
|
<TreatWarningAsError>false</TreatWarningAsError>
|
|
158
158
|
<EnablePREfast>false</EnablePREfast>
|
|
159
|
-
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
|
|
159
|
+
<AdditionalIncludeDirectories>..\include;lib\common;programs</AdditionalIncludeDirectories>
|
|
160
160
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
|
161
161
|
</ClCompile>
|
|
162
162
|
<Link>
|
|
@@ -169,8 +169,12 @@
|
|
|
169
169
|
</Link>
|
|
170
170
|
</ItemDefinitionGroup>
|
|
171
171
|
<ItemGroup>
|
|
172
|
-
<ClCompile Include="
|
|
173
|
-
<ClCompile Include="
|
|
172
|
+
<ClCompile Include="programs\benchfn.c" />
|
|
173
|
+
<ClCompile Include="programs\datagen.c" />
|
|
174
|
+
<ClCompile Include="programs\lorem.c" />
|
|
175
|
+
<ClCompile Include="programs\timefn.c" />
|
|
176
|
+
<ClCompile Include="programs\util.c" />
|
|
177
|
+
<ClCompile Include="tests\fullbench.c" />
|
|
174
178
|
</ItemGroup>
|
|
175
179
|
<ItemGroup>
|
|
176
180
|
<ClInclude Include="..\include\zstd.h" />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# ################################################################
|
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
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.
|
|
9
|
+
# ################################################################
|
|
10
|
+
|
|
11
|
+
# This included Makefile provides the following variables :
|
|
12
|
+
# UNAME, INSTALL_OS_LIST
|
|
13
|
+
|
|
14
|
+
UNAME := $(shell sh -c 'MSYSTEM="MSYS" uname')
|
|
15
|
+
|
|
16
|
+
# List of OSes for which target install is supported
|
|
17
|
+
INSTALL_OS_LIST ?= Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%
|
|
@@ -430,7 +430,7 @@ static unsigned FSE_isError(size_t code) { return (code > (size_t)(-FSE_ERROR_ma
|
|
|
430
430
|
|
|
431
431
|
static short FSE_abs(short a)
|
|
432
432
|
{
|
|
433
|
-
return a<0? -a : a;
|
|
433
|
+
return a<0? (short)-a : a;
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
|
|
@@ -1437,6 +1437,7 @@ static size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProper
|
|
|
1437
1437
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
1438
1438
|
|
|
1439
1439
|
if (bpPtr->blockType == bt_end) return 0;
|
|
1440
|
+
if (cSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
1440
1441
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
1441
1442
|
return cSize;
|
|
1442
1443
|
}
|
|
@@ -1729,10 +1730,11 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
1729
1730
|
/* checks */
|
|
1730
1731
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
|
1731
1732
|
|
|
1733
|
+
if (sequence.offset == 0) return ERROR(corruption_detected);
|
|
1732
1734
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
|
1733
1735
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
|
1734
1736
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
|
1735
|
-
if (sequence.offset > (
|
|
1737
|
+
if (sequence.offset > (size_t)(oLitEnd - base)) return ERROR(corruption_detected);
|
|
1736
1738
|
|
|
1737
1739
|
if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
|
1738
1740
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
|
@@ -1750,13 +1752,12 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
1750
1752
|
/* copy Match */
|
|
1751
1753
|
{
|
|
1752
1754
|
const U32 overlapRisk = (((size_t)(litEnd - endMatch)) < 12);
|
|
1753
|
-
const BYTE* match = op - sequence.offset; /*
|
|
1755
|
+
const BYTE* match = op - sequence.offset; /* >= base : see the offset check above */
|
|
1754
1756
|
size_t qutt = 12;
|
|
1755
1757
|
U64 saved[2];
|
|
1756
1758
|
|
|
1757
1759
|
/* check */
|
|
1758
1760
|
if (match < base) return ERROR(corruption_detected);
|
|
1759
|
-
if (sequence.offset > (size_t)base) return ERROR(corruption_detected);
|
|
1760
1761
|
|
|
1761
1762
|
/* save beginning of literal sequence, in case of write overlap */
|
|
1762
1763
|
if (overlapRisk)
|
|
@@ -1823,11 +1824,12 @@ static size_t ZSTD_decompressSequences(
|
|
|
1823
1824
|
BYTE* const ostart = (BYTE* const)dst;
|
|
1824
1825
|
BYTE* op = ostart;
|
|
1825
1826
|
BYTE* const oend = ostart + maxDstSize;
|
|
1826
|
-
size_t errorCode
|
|
1827
|
+
size_t errorCode = 0;
|
|
1828
|
+
size_t dumpsLength = 0;
|
|
1827
1829
|
const BYTE* litPtr = litStart;
|
|
1828
1830
|
const BYTE* const litEnd = litStart + litSize;
|
|
1829
|
-
int nbSeq;
|
|
1830
|
-
const BYTE* dumps;
|
|
1831
|
+
int nbSeq = 0;
|
|
1832
|
+
const BYTE* dumps = NULL;
|
|
1831
1833
|
U32* DTableLL = dctx->LLTable;
|
|
1832
1834
|
U32* DTableML = dctx->MLTable;
|
|
1833
1835
|
U32* DTableOffb = dctx->OffTable;
|
|
@@ -1915,7 +1917,7 @@ size_t ZSTDv01_decompressDCtx(void* ctx, void* dst, size_t maxDstSize, const voi
|
|
|
1915
1917
|
size_t remainingSize = srcSize;
|
|
1916
1918
|
U32 magicNumber;
|
|
1917
1919
|
size_t errorCode=0;
|
|
1918
|
-
blockProperties_t blockProperties;
|
|
1920
|
+
blockProperties_t blockProperties = { 0 };
|
|
1919
1921
|
|
|
1920
1922
|
/* Frame Header */
|
|
1921
1923
|
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
|