Skip to content

Commit d42b227

Browse files
committed
change "external matchfinder" to "external sequence producer"
1 parent 488f7c0 commit d42b227

12 files changed

+193
-184
lines changed

contrib/externalMatchfinder/main.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define ZSTD_STATIC_LINKING_ONLY
1717
#include "zstd.h"
1818
#include "zstd_errors.h"
19-
#include "matchfinder.h" // simpleExternalMatchFinder
19+
#include "matchfinder.h" // simpleSequenceProducer
2020

2121
#define CHECK(res) \
2222
do { \
@@ -34,17 +34,17 @@ int main(int argc, char *argv[]) {
3434

3535
ZSTD_CCtx* const zc = ZSTD_createCCtx();
3636

37-
int simpleExternalMatchState = 0xdeadbeef;
37+
int simpleSequenceProducerState = 0xdeadbeef;
3838

3939
// Here is the crucial bit of code!
40-
ZSTD_registerExternalMatchFinder(
40+
ZSTD_registerSequenceProducer(
4141
zc,
42-
&simpleExternalMatchState,
43-
simpleExternalMatchFinder
42+
&simpleSequenceProducerState,
43+
simpleSequenceProducer
4444
);
4545

4646
{
47-
size_t const res = ZSTD_CCtx_setParameter(zc, ZSTD_c_enableMatchFinderFallback, 1);
47+
size_t const res = ZSTD_CCtx_setParameter(zc, ZSTD_c_enableSeqProducerFallback, 1);
4848
CHECK(res);
4949
}
5050

contrib/externalMatchfinder/matchfinder.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static U32 const HLOG = 10;
1616
static U32 const MLS = 4;
1717
static U32 const BADIDX = 0xffffffff;
1818

19-
size_t simpleExternalMatchFinder(
20-
void* externalMatchState,
19+
size_t simpleSequenceProducer(
20+
void* sequenceProducerState,
2121
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
2222
const void* src, size_t srcSize,
2323
const void* dict, size_t dictSize,
@@ -31,7 +31,7 @@ size_t simpleExternalMatchFinder(
3131
size_t seqCount = 0;
3232
U32 hashTable[HSIZE];
3333

34-
(void)externalMatchState;
34+
(void)sequenceProducerState;
3535
(void)dict;
3636
(void)dictSize;
3737
(void)outSeqsCapacity;

contrib/externalMatchfinder/matchfinder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define ZSTD_STATIC_LINKING_ONLY
1515
#include "zstd.h"
1616

17-
size_t simpleExternalMatchFinder(
18-
void* externalMatchState,
17+
size_t simpleSequenceProducer(
18+
void* sequenceProducerState,
1919
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
2020
const void* src, size_t srcSize,
2121
const void* dict, size_t dictSize,

lib/common/error_private.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const char* ERR_getErrorString(ERR_enum code)
5454
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
5555
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
5656
case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
57-
case PREFIX(externalMatchFinder_failed): return "External matchfinder returned an error code";
57+
case PREFIX(sequenceProducer_failed): return "External matchfinder returned an error code";
5858
case PREFIX(externalSequences_invalid): return "External sequences are not valid";
5959
case PREFIX(maxCode):
6060
default: return notErrorCode;

lib/compress/zstd_compress.c

+34-34
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter param)
615615
bounds.upperBound = (int)ZSTD_ps_disable;
616616
return bounds;
617617

618-
case ZSTD_c_enableMatchFinderFallback:
618+
case ZSTD_c_enableSeqProducerFallback:
619619
bounds.lowerBound = 0;
620620
bounds.upperBound = 1;
621621
return bounds;
@@ -695,7 +695,7 @@ static int ZSTD_isUpdateAuthorized(ZSTD_cParameter param)
695695
case ZSTD_c_useRowMatchFinder:
696696
case ZSTD_c_deterministicRefPrefix:
697697
case ZSTD_c_prefetchCDictTables:
698-
case ZSTD_c_enableMatchFinderFallback:
698+
case ZSTD_c_enableSeqProducerFallback:
699699
case ZSTD_c_maxBlockSize:
700700
case ZSTD_c_searchForExternalRepcodes:
701701
default:
@@ -754,7 +754,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value)
754754
case ZSTD_c_useRowMatchFinder:
755755
case ZSTD_c_deterministicRefPrefix:
756756
case ZSTD_c_prefetchCDictTables:
757-
case ZSTD_c_enableMatchFinderFallback:
757+
case ZSTD_c_enableSeqProducerFallback:
758758
case ZSTD_c_maxBlockSize:
759759
case ZSTD_c_searchForExternalRepcodes:
760760
break;
@@ -989,8 +989,8 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
989989
CCtxParams->prefetchCDictTables = (ZSTD_paramSwitch_e)value;
990990
return CCtxParams->prefetchCDictTables;
991991

992-
case ZSTD_c_enableMatchFinderFallback:
993-
BOUNDCHECK(ZSTD_c_enableMatchFinderFallback, value);
992+
case ZSTD_c_enableSeqProducerFallback:
993+
BOUNDCHECK(ZSTD_c_enableSeqProducerFallback, value);
994994
CCtxParams->enableMatchFinderFallback = value;
995995
return CCtxParams->enableMatchFinderFallback;
996996

@@ -1140,7 +1140,7 @@ size_t ZSTD_CCtxParams_getParameter(
11401140
case ZSTD_c_prefetchCDictTables:
11411141
*value = (int)CCtxParams->prefetchCDictTables;
11421142
break;
1143-
case ZSTD_c_enableMatchFinderFallback:
1143+
case ZSTD_c_enableSeqProducerFallback:
11441144
*value = CCtxParams->enableMatchFinderFallback;
11451145
break;
11461146
case ZSTD_c_maxBlockSize:
@@ -1610,8 +1610,8 @@ ZSTD_sizeof_matchState(const ZSTD_compressionParameters* const cParams,
16101610

16111611
/* Helper function for calculating memory requirements.
16121612
* Gives a tighter bound than ZSTD_sequenceBound() by taking minMatch into account. */
1613-
static size_t ZSTD_maxNbSeq(size_t blockSize, unsigned minMatch, int useExternalMatchFinder) {
1614-
U32 const divider = (minMatch==3 || useExternalMatchFinder) ? 3 : 4;
1613+
static size_t ZSTD_maxNbSeq(size_t blockSize, unsigned minMatch, int useSequenceProducer) {
1614+
U32 const divider = (minMatch==3 || useSequenceProducer) ? 3 : 4;
16151615
return blockSize / divider;
16161616
}
16171617

@@ -1623,12 +1623,12 @@ static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal(
16231623
const size_t buffInSize,
16241624
const size_t buffOutSize,
16251625
const U64 pledgedSrcSize,
1626-
int useExternalMatchFinder,
1626+
int useSequenceProducer,
16271627
size_t maxBlockSize)
16281628
{
16291629
size_t const windowSize = (size_t) BOUNDED(1ULL, 1ULL << cParams->windowLog, pledgedSrcSize);
16301630
size_t const blockSize = MIN(ZSTD_resolveMaxBlockSize(maxBlockSize), windowSize);
1631-
size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, cParams->minMatch, useExternalMatchFinder);
1631+
size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, cParams->minMatch, useSequenceProducer);
16321632
size_t const tokenSpace = ZSTD_cwksp_alloc_size(WILDCOPY_OVERLENGTH + blockSize)
16331633
+ ZSTD_cwksp_aligned_alloc_size(maxNbSeq * sizeof(seqDef))
16341634
+ 3 * ZSTD_cwksp_alloc_size(maxNbSeq * sizeof(BYTE));
@@ -1648,7 +1648,7 @@ static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal(
16481648
size_t const cctxSpace = isStatic ? ZSTD_cwksp_alloc_size(sizeof(ZSTD_CCtx)) : 0;
16491649

16501650
size_t const maxNbExternalSeq = ZSTD_sequenceBound(blockSize);
1651-
size_t const externalSeqSpace = useExternalMatchFinder
1651+
size_t const externalSeqSpace = useSequenceProducer
16521652
? ZSTD_cwksp_aligned_alloc_size(maxNbExternalSeq * sizeof(ZSTD_Sequence))
16531653
: 0;
16541654

@@ -1679,7 +1679,7 @@ size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params)
16791679
* be needed. However, we still allocate two 0-sized buffers, which can
16801680
* take space under ASAN. */
16811681
return ZSTD_estimateCCtxSize_usingCCtxParams_internal(
1682-
&cParams, &params->ldmParams, 1, useRowMatchFinder, 0, 0, ZSTD_CONTENTSIZE_UNKNOWN, params->useExternalMatchFinder, params->maxBlockSize);
1682+
&cParams, &params->ldmParams, 1, useRowMatchFinder, 0, 0, ZSTD_CONTENTSIZE_UNKNOWN, params->useSequenceProducer, params->maxBlockSize);
16831683
}
16841684

16851685
size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams)
@@ -1740,7 +1740,7 @@ size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params)
17401740

17411741
return ZSTD_estimateCCtxSize_usingCCtxParams_internal(
17421742
&cParams, &params->ldmParams, 1, useRowMatchFinder, inBuffSize, outBuffSize,
1743-
ZSTD_CONTENTSIZE_UNKNOWN, params->useExternalMatchFinder, params->maxBlockSize);
1743+
ZSTD_CONTENTSIZE_UNKNOWN, params->useSequenceProducer, params->maxBlockSize);
17441744
}
17451745
}
17461746

@@ -2024,7 +2024,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
20242024

20252025
{ size_t const windowSize = MAX(1, (size_t)MIN(((U64)1 << params->cParams.windowLog), pledgedSrcSize));
20262026
size_t const blockSize = MIN(params->maxBlockSize, windowSize);
2027-
size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, params->cParams.minMatch, params->useExternalMatchFinder);
2027+
size_t const maxNbSeq = ZSTD_maxNbSeq(blockSize, params->cParams.minMatch, params->useSequenceProducer);
20282028
size_t const buffOutSize = (zbuff == ZSTDb_buffered && params->outBufferMode == ZSTD_bm_buffered)
20292029
? ZSTD_compressBound(blockSize) + 1
20302030
: 0;
@@ -2041,7 +2041,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
20412041
size_t const neededSpace =
20422042
ZSTD_estimateCCtxSize_usingCCtxParams_internal(
20432043
&params->cParams, &params->ldmParams, zc->staticSize != 0, params->useRowMatchFinder,
2044-
buffInSize, buffOutSize, pledgedSrcSize, params->useExternalMatchFinder, params->maxBlockSize);
2044+
buffInSize, buffOutSize, pledgedSrcSize, params->useSequenceProducer, params->maxBlockSize);
20452045
int resizeWorkspace;
20462046

20472047
FORWARD_IF_ERROR(neededSpace, "cctx size estimate failed!");
@@ -2155,7 +2155,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
21552155
}
21562156

21572157
/* reserve space for block-level external sequences */
2158-
if (params->useExternalMatchFinder) {
2158+
if (params->useSequenceProducer) {
21592159
size_t const maxNbExternalSeq = ZSTD_sequenceBound(blockSize);
21602160
zc->externalMatchCtx.seqBufferCapacity = maxNbExternalSeq;
21612161
zc->externalMatchCtx.seqBuffer =
@@ -3022,25 +3022,25 @@ void ZSTD_resetSeqStore(seqStore_t* ssPtr)
30223022
ssPtr->longLengthType = ZSTD_llt_none;
30233023
}
30243024

3025-
/* ZSTD_postProcessExternalMatchFinderResult() :
3025+
/* ZSTD_postProcessSequenceProducerResult() :
30263026
* Validates and post-processes sequences obtained through the external matchfinder API:
30273027
* - Checks whether nbExternalSeqs represents an error condition.
30283028
* - Appends a block delimiter to outSeqs if one is not already present.
30293029
* See zstd.h for context regarding block delimiters.
30303030
* Returns the number of sequences after post-processing, or an error code. */
3031-
static size_t ZSTD_postProcessExternalMatchFinderResult(
3031+
static size_t ZSTD_postProcessSequenceProducerResult(
30323032
ZSTD_Sequence* outSeqs, size_t nbExternalSeqs, size_t outSeqsCapacity, size_t srcSize
30333033
) {
30343034
RETURN_ERROR_IF(
30353035
nbExternalSeqs > outSeqsCapacity,
3036-
externalMatchFinder_failed,
3036+
sequenceProducer_failed,
30373037
"External matchfinder returned error code %lu",
30383038
(unsigned long)nbExternalSeqs
30393039
);
30403040

30413041
RETURN_ERROR_IF(
30423042
nbExternalSeqs == 0 && srcSize > 0,
3043-
externalMatchFinder_failed,
3043+
sequenceProducer_failed,
30443044
"External matchfinder produced zero sequences for a non-empty src buffer!"
30453045
);
30463046

@@ -3061,7 +3061,7 @@ static size_t ZSTD_postProcessExternalMatchFinderResult(
30613061
* produced an invalid parse, by definition of ZSTD_sequenceBound(). */
30623062
RETURN_ERROR_IF(
30633063
nbExternalSeqs == outSeqsCapacity,
3064-
externalMatchFinder_failed,
3064+
sequenceProducer_failed,
30653065
"nbExternalSeqs == outSeqsCapacity but lastSeq is not a block delimiter!"
30663066
);
30673067

@@ -3139,7 +3139,7 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
31393139
/* External matchfinder + LDM is technically possible, just not implemented yet.
31403140
* We need to revisit soon and implement it. */
31413141
RETURN_ERROR_IF(
3142-
zc->appliedParams.useExternalMatchFinder,
3142+
zc->appliedParams.useSequenceProducer,
31433143
parameter_combination_unsupported,
31443144
"Long-distance matching with external matchfinder enabled is not currently supported."
31453145
);
@@ -3158,7 +3158,7 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
31583158
/* External matchfinder + LDM is technically possible, just not implemented yet.
31593159
* We need to revisit soon and implement it. */
31603160
RETURN_ERROR_IF(
3161-
zc->appliedParams.useExternalMatchFinder,
3161+
zc->appliedParams.useSequenceProducer,
31623162
parameter_combination_unsupported,
31633163
"Long-distance matching with external matchfinder enabled is not currently supported."
31643164
);
@@ -3177,7 +3177,7 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
31773177
zc->appliedParams.useRowMatchFinder,
31783178
src, srcSize);
31793179
assert(ldmSeqStore.pos == ldmSeqStore.size);
3180-
} else if (zc->appliedParams.useExternalMatchFinder) {
3180+
} else if (zc->appliedParams.useSequenceProducer) {
31813181
assert(
31823182
zc->externalMatchCtx.seqBufferCapacity >= ZSTD_sequenceBound(srcSize)
31833183
);
@@ -3195,7 +3195,7 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
31953195
windowSize
31963196
);
31973197

3198-
size_t const nbPostProcessedSeqs = ZSTD_postProcessExternalMatchFinderResult(
3198+
size_t const nbPostProcessedSeqs = ZSTD_postProcessSequenceProducerResult(
31993199
zc->externalMatchCtx.seqBuffer,
32003200
nbExternalSeqs,
32013201
zc->externalMatchCtx.seqBufferCapacity,
@@ -6033,7 +6033,7 @@ static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx,
60336033
#ifdef ZSTD_MULTITHREAD
60346034
/* If external matchfinder is enabled, make sure to fail before checking job size (for consistency) */
60356035
RETURN_ERROR_IF(
6036-
params.useExternalMatchFinder == 1 && params.nbWorkers >= 1,
6036+
params.useSequenceProducer == 1 && params.nbWorkers >= 1,
60376037
parameter_combination_unsupported,
60386038
"External matchfinder isn't supported with nbWorkers >= 1"
60396039
);
@@ -6251,7 +6251,7 @@ size_t ZSTD_compress2(ZSTD_CCtx* cctx,
62516251
*/
62526252
static size_t
62536253
ZSTD_validateSequence(U32 offCode, U32 matchLength, U32 minMatch,
6254-
size_t posInSrc, U32 windowLog, size_t dictSize, int useExternalMatchFinder)
6254+
size_t posInSrc, U32 windowLog, size_t dictSize, int useSequenceProducer)
62556255
{
62566256
U32 const windowSize = 1u << windowLog;
62576257
/* posInSrc represents the amount of data the decoder would decode up to this point.
@@ -6260,7 +6260,7 @@ ZSTD_validateSequence(U32 offCode, U32 matchLength, U32 minMatch,
62606260
* window size. After output surpasses windowSize, we're limited to windowSize offsets again.
62616261
*/
62626262
size_t const offsetBound = posInSrc > windowSize ? (size_t)windowSize : posInSrc + (size_t)dictSize;
6263-
size_t const matchLenLowerBound = (minMatch == 3 || useExternalMatchFinder) ? 3 : 4;
6263+
size_t const matchLenLowerBound = (minMatch == 3 || useSequenceProducer) ? 3 : 4;
62646264
RETURN_ERROR_IF(offCode > OFFSET_TO_OFFBASE(offsetBound), externalSequences_invalid, "Offset too large!");
62656265
/* Validate maxNbSeq is large enough for the given matchLength and minMatch */
62666266
RETURN_ERROR_IF(matchLength < matchLenLowerBound, externalSequences_invalid, "Matchlength too small for the minMatch");
@@ -6325,7 +6325,7 @@ ZSTD_copySequencesToSeqStoreExplicitBlockDelim(ZSTD_CCtx* cctx,
63256325
if (cctx->appliedParams.validateSequences) {
63266326
seqPos->posInSrc += litLength + matchLength;
63276327
FORWARD_IF_ERROR(ZSTD_validateSequence(offBase, matchLength, cctx->appliedParams.cParams.minMatch, seqPos->posInSrc,
6328-
cctx->appliedParams.cParams.windowLog, dictSize, cctx->appliedParams.useExternalMatchFinder),
6328+
cctx->appliedParams.cParams.windowLog, dictSize, cctx->appliedParams.useSequenceProducer),
63296329
"Sequence validation failed");
63306330
}
63316331
RETURN_ERROR_IF(idx - seqPos->idx >= cctx->seqStore.maxNbSeq, externalSequences_invalid,
@@ -6463,7 +6463,7 @@ ZSTD_copySequencesToSeqStoreNoBlockDelim(ZSTD_CCtx* cctx, ZSTD_sequencePosition*
64636463
if (cctx->appliedParams.validateSequences) {
64646464
seqPos->posInSrc += litLength + matchLength;
64656465
FORWARD_IF_ERROR(ZSTD_validateSequence(offBase, matchLength, cctx->appliedParams.cParams.minMatch, seqPos->posInSrc,
6466-
cctx->appliedParams.cParams.windowLog, dictSize, cctx->appliedParams.useExternalMatchFinder),
6466+
cctx->appliedParams.cParams.windowLog, dictSize, cctx->appliedParams.useSequenceProducer),
64676467
"Sequence validation failed");
64686468
}
64696469
DEBUGLOG(6, "Storing sequence: (of: %u, ml: %u, ll: %u)", offBase, matchLength, litLength);
@@ -6908,9 +6908,9 @@ ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeH
69086908
return ZSTD_getParams_internal(compressionLevel, srcSizeHint, dictSize, ZSTD_cpm_unknown);
69096909
}
69106910

6911-
void ZSTD_registerExternalMatchFinder(
6911+
void ZSTD_registerExternalSequenceProducer(
69126912
ZSTD_CCtx* zc, void* mState,
6913-
ZSTD_externalMatchFinder_F* mFinder
6913+
ZSTD_sequenceProducer_F* mFinder
69146914
) {
69156915
if (mFinder != NULL) {
69166916
ZSTD_externalMatchCtx emctx;
@@ -6919,9 +6919,9 @@ void ZSTD_registerExternalMatchFinder(
69196919
emctx.seqBuffer = NULL;
69206920
emctx.seqBufferCapacity = 0;
69216921
zc->externalMatchCtx = emctx;
6922-
zc->requestedParams.useExternalMatchFinder = 1;
6922+
zc->requestedParams.useSequenceProducer = 1;
69236923
} else {
69246924
ZSTD_memset(&zc->externalMatchCtx, 0, sizeof(zc->externalMatchCtx));
6925-
zc->requestedParams.useExternalMatchFinder = 0;
6925+
zc->requestedParams.useSequenceProducer = 0;
69266926
}
69276927
}

lib/compress/zstd_compress_internal.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ struct ZSTD_CCtx_params_s {
353353

354354
/* Indicates whether an external matchfinder has been referenced.
355355
* Users can't set this externally.
356-
* It is set internally in ZSTD_registerExternalMatchFinder(). */
357-
int useExternalMatchFinder;
356+
* It is set internally in ZSTD_registerExternalSequenceProducer(). */
357+
int useSequenceProducer;
358358

359359
/* Adjust the max block size*/
360360
size_t maxBlockSize;
@@ -395,7 +395,7 @@ typedef struct {
395395
/* Context for block-level external matchfinder API */
396396
typedef struct {
397397
void* mState;
398-
ZSTD_externalMatchFinder_F* mFinder;
398+
ZSTD_sequenceProducer_F* mFinder;
399399
ZSTD_Sequence* seqBuffer;
400400
size_t seqBufferCapacity;
401401
} ZSTD_externalMatchCtx;

0 commit comments

Comments
 (0)