Skip to content

Commit fad2aad

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

File tree

1 file changed

+104
-95
lines changed

1 file changed

+104
-95
lines changed

lib/zstd.h

+104-95
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ typedef enum {
478478
* ZSTD_c_useBlockSplitter
479479
* ZSTD_c_useRowMatchFinder
480480
* ZSTD_c_prefetchCDictTables
481-
* ZSTD_c_enableMatchFinderFallback
481+
* ZSTD_c_enableSeqProducerFallback
482482
* ZSTD_c_maxBlockSize
483483
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
484484
* note : never ever use experimentalParam? names directly;
@@ -565,7 +565,7 @@ typedef enum {
565565
* They will be used to compress next frame.
566566
* Resetting session never fails.
567567
* - The parameters : changes all parameters back to "default".
568-
* This also removes any reference to any dictionary or external matchfinder.
568+
* This also removes any reference to any dictionary or external sequence producer.
569569
* Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
570570
* otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
571571
* - Both : similar to resetting the session, followed by resetting parameters.
@@ -1627,8 +1627,8 @@ ZSTDLIB_API unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size);
16271627
* Note : only single-threaded compression is supported.
16281628
* ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
16291629
*
1630-
* Note 2 : ZSTD_estimateCCtxSize* functions are not compatible with the external matchfinder API at this time.
1631-
* Size estimates assume that no external matchfinder is registered.
1630+
* Note 2 : ZSTD_estimateCCtxSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
1631+
* Size estimates assume that no external sequence producer is registered.
16321632
*/
16331633
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize(int compressionLevel);
16341634
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams);
@@ -1650,8 +1650,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
16501650
* In this case, get total size by adding ZSTD_estimate?DictSize
16511651
* Note 2 : only single-threaded compression is supported.
16521652
* ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1653-
* Note 3 : ZSTD_estimateCStreamSize* functions are not compatible with the external matchfinder API at this time.
1654-
* Size estimates assume that no external matchfinder is registered.
1653+
* Note 3 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
1654+
* Size estimates assume that no external sequence producer is registered.
16551655
*/
16561656
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize(int compressionLevel);
16571657
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams);
@@ -2113,19 +2113,19 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
21132113
*/
21142114
#define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
21152115

2116-
/* ZSTD_c_enableMatchFinderFallback
2116+
/* ZSTD_c_enableSeqProducerFallback
21172117
* Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
21182118
*
2119-
* Controls whether zstd will fall back to an internal matchfinder if an
2120-
* external matchfinder is registered and returns an error code. This fallback is
2121-
* block-by-block: the internal matchfinder will only be called for blocks where
2122-
* the external matchfinder returns an error code. Fallback compression will
2119+
* Controls whether zstd will fall back to an internal sequence producer if an
2120+
* external sequence producer is registered and returns an error code. This fallback
2121+
* is block-by-block: the internal sequence producer will only be called for blocks
2122+
* where the external sequence producer returns an error code. Fallback parsing will
21232123
* follow any other cParam settings, such as compression level, the same as in a
21242124
* normal (fully-internal) compression operation.
21252125
*
2126-
* The user is strongly encouraged to read the full external matchfinder API
2126+
* The user is strongly encouraged to read the full Block-Level Sequence Producer API
21272127
* documentation (below) before setting this parameter. */
2128-
#define ZSTD_c_enableMatchFinderFallback ZSTD_c_experimentalParam17
2128+
#define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
21292129

21302130
/* ZSTD_c_maxBlockSize
21312131
* Allowed values are between 1KB and ZSTD_BLOCKSIZE_MAX (128KB).
@@ -2141,12 +2141,13 @@ ZSTDLIB_STATIC_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const vo
21412141

21422142
/* ZSTD_c_searchForExternalRepcodes
21432143
* This parameter affects how zstd parses external sequences, such as sequences
2144-
* provided through the compressSequences() API or from an external matchfinder.
2144+
* provided through the compressSequences() API or from an external block-level
2145+
* sequence producer.
21452146
*
21462147
* If set to ZSTD_ps_enable, the library will check for repeated offsets in
21472148
* external sequences, even if those repcodes are not explicitly indicated in
21482149
* the "rep" field. Note that this is the only way to exploit repcode matches
2149-
* while using compressSequences() or an external matchfinder, since zstd
2150+
* while using compressSequences() or an external sequence producer, since zstd
21502151
* currently ignores the "rep" field of external sequences.
21512152
*
21522153
* If set to ZSTD_ps_disable, the library will not exploit repeated offsets in
@@ -2805,43 +2806,52 @@ ZSTDLIB_STATIC_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_
28052806
ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */
28062807

28072808

2808-
/* ********************** EXTERNAL MATCHFINDER API **********************
2809+
/* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
28092810
*
28102811
* *** OVERVIEW ***
2811-
* This API allows users to replace the zstd internal block-level matchfinder
2812-
* with an external matchfinder function. Potential applications of the API
2813-
* include hardware-accelerated matchfinders and matchfinders specialized to
2814-
* particular types of data.
2815-
*
2816-
* See contrib/externalMatchfinder for an example program employing the
2817-
* external matchfinder API.
2812+
* The Block-Level Sequence Producer API allows users to provide their own custom
2813+
* sequence producer which libzstd invokes to process each block. The produced list
2814+
* of sequences (literals and matches) is then post-processed by libzstd to produce
2815+
* valid compressed blocks.
2816+
*
2817+
* This block-level offload API is a more granular complement of the existing
2818+
* frame-level offload API compressSequences() (introduced in v1.5.1). It offers
2819+
* an easier migration story for applications already integrated with libzstd: the
2820+
* user application continues to invoke the same compression functions
2821+
* ZSTD_compress2() or ZSTD_compressStream2() as usual, and transparently benefits
2822+
* from the specific advantages of the external sequence producer. For example,
2823+
* the sequence producer could be tuned to take advantage of known characteristics
2824+
* of the input, to offer better speed / ratio, or could leverage hardware
2825+
* acceleration not available within libzstd itself.
2826+
*
2827+
* See contrib/sequenceProducer for an example program employing the Block-Level
2828+
* Sequence Producer API.
28182829
*
28192830
* *** USAGE ***
28202831
* The user is responsible for implementing a function of type
2821-
* ZSTD_externalMatchFinder_F. For each block, zstd will pass the following
2832+
* ZSTD_sequenceProducer_F. For each block, zstd will pass the following
28222833
* arguments to the user-provided function:
28232834
*
2824-
* - externalMatchState: a pointer to a user-managed state for the external
2825-
* matchfinder.
2835+
* - sequenceProducerState: a pointer to a user-managed state for the sequence
2836+
* producer.
28262837
*
2827-
* - outSeqs, outSeqsCapacity: an output buffer for sequences produced by the
2828-
* external matchfinder. outSeqsCapacity is guaranteed >=
2829-
* ZSTD_sequenceBound(srcSize). The memory backing outSeqs is managed by
2830-
* the CCtx.
2838+
* - outSeqs, outSeqsCapacity: an output buffer for the sequence producer.
2839+
* outSeqsCapacity is guaranteed >= ZSTD_sequenceBound(srcSize). The memory
2840+
* backing outSeqs is managed by the CCtx.
28312841
*
2832-
* - src, srcSize: an input buffer which the external matchfinder must parse
2833-
* into sequences. srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
2842+
* - src, srcSize: an input buffer for the sequence producer to parse.
2843+
* srcSize is guaranteed to be <= ZSTD_BLOCKSIZE_MAX.
28342844
*
2835-
* - dict, dictSize: a history buffer, which may be empty, which the external
2836-
* matchfinder may reference as it produces sequences for the src buffer.
2837-
* Currently, zstd will always pass dictSize == 0 into external matchfinders,
2838-
* but this will change in the future.
2845+
* - dict, dictSize: a history buffer, which may be empty, which the sequence
2846+
* producer may reference as it parses the src buffer. Currently, zstd will
2847+
* always pass dictSize == 0 into external sequence producers, but this will
2848+
* change in the future.
28392849
*
28402850
* - compressionLevel: a signed integer representing the zstd compression level
2841-
* set by the user for the current operation. The external matchfinder may
2842-
* choose to use this information to change its compression strategy and
2843-
* speed/ratio tradeoff. Note: The compression level does not reflect zstd
2844-
* parameters set through the advanced API.
2851+
* set by the user for the current operation. The sequence producer may choose
2852+
* to use this information to change its compression strategy and speed/ratio
2853+
* tradeoff. Note: the compression level does not reflect zstd parameters set
2854+
* through the advanced API.
28452855
*
28462856
* - windowSize: a size_t representing the maximum allowed offset for external
28472857
* sequences. Note that sequence offsets are sometimes allowed to exceed the
@@ -2851,7 +2861,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* bloc
28512861
* The user-provided function shall return a size_t representing the number of
28522862
* sequences written to outSeqs. This return value will be treated as an error
28532863
* code if it is greater than outSeqsCapacity. The return value must be non-zero
2854-
* if srcSize is non-zero. The ZSTD_EXTERNAL_MATCHFINDER_ERROR macro is provided
2864+
* if srcSize is non-zero. The ZSTD_SEQUENCE_PRODUCER_ERROR macro is provided
28552865
* for convenience, but any value greater than outSeqsCapacity will be treated as
28562866
* an error code.
28572867
*
@@ -2870,90 +2880,89 @@ ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* bloc
28702880
* validation has a performance cost.
28712881
*
28722882
* If the user-provided function returns an error, zstd will either fall back
2873-
* to an internal matchfinder or fail the compression operation. The user can
2874-
* choose between the two behaviors by setting the
2875-
* ZSTD_c_enableMatchFinderFallback cParam. Fallback compression will follow any
2876-
* other cParam settings, such as compression level, the same as in a normal
2877-
* compression operation.
2878-
*
2879-
* The user shall instruct zstd to use a particular ZSTD_externalMatchFinder_F
2880-
* function by calling ZSTD_registerExternalMatchFinder(cctx, externalMatchState,
2881-
* externalMatchFinder). This setting will persist until the next parameter reset
2882-
* of the CCtx.
2883-
*
2884-
* The externalMatchState must be initialized by the user before calling
2885-
* ZSTD_registerExternalMatchFinder. The user is responsible for destroying the
2886-
* externalMatchState.
2883+
* to an internal sequence producer or fail the compression operation. The user can
2884+
* choose between the two behaviors by setting the ZSTD_c_enableSeqProducerFallback
2885+
* cParam. Fallback compression will follow any other cParam settings, such as
2886+
* compression level, the same as in a normal compression operation.
2887+
*
2888+
* The user shall instruct zstd to use a particular ZSTD_sequenceProducer_F
2889+
* function by calling
2890+
* ZSTD_registerSequenceProducer(cctx,
2891+
* sequenceProducerState,
2892+
* sequenceProducer)
2893+
* This setting will persist until the next parameter reset of the CCtx.
2894+
*
2895+
* The sequenceProducerState must be initialized by the user before calling
2896+
* ZSTD_registerSequenceProducer(). The user is responsible for destroying the
2897+
* sequenceProducerState.
28872898
*
28882899
* *** LIMITATIONS ***
2889-
* External matchfinders are compatible with all zstd compression APIs which respect
2890-
* advanced parameters. However, there are three limitations:
2891-
*
2892-
* First, the ZSTD_c_enableLongDistanceMatching cParam is not supported.
2893-
* COMPRESSION WILL FAIL if it is enabled and the user tries to compress with an
2894-
* external matchfinder.
2895-
* - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in
2896-
* some cases (see its documentation for details). Users must explicitly set
2897-
* ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an
2898-
* external matchfinder is registered.
2900+
* This API is compatible with all zstd compression APIs which respect advanced parameters.
2901+
* However, there are three limitations:
2902+
*
2903+
* First, the ZSTD_c_enableLongDistanceMatching cParam is not currently supported.
2904+
* COMPRESSION WILL FAIL if it is enabled and the user tries to compress with a block-level
2905+
* external sequence producer.
2906+
* - Note that ZSTD_c_enableLongDistanceMatching is auto-enabled by default in some
2907+
* cases (see its documentation for details). Users must explicitly set
2908+
* ZSTD_c_enableLongDistanceMatching to ZSTD_ps_disable in such cases if an external
2909+
* sequence producer is registered.
28992910
* - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
29002911
* whenever ZSTD_c_windowLog < 128MB, but that's subject to change. Users should
2901-
* check the docs on ZSTD_c_enableLongDistanceMatching whenever the external
2902-
* matchfinder API is used in conjunction with advanced settings (like windowLog).
2912+
* check the docs on ZSTD_c_enableLongDistanceMatching whenever the Block-Level Sequence
2913+
* Producer API is used in conjunction with advanced settings (like ZSTD_c_windowLog).
29032914
*
2904-
* Second, history buffers are not supported. Concretely, zstd will always pass
2905-
* dictSize == 0 to the external matchfinder (for now). This has two implications:
2906-
* - Dictionaries are not supported. Compression will *not* fail if the user
2915+
* Second, history buffers are not currently supported. Concretely, zstd will always pass
2916+
* dictSize == 0 to the external sequence producer (for now). This has two implications:
2917+
* - Dictionaries are not currently supported. Compression will *not* fail if the user
29072918
* references a dictionary, but the dictionary won't have any effect.
2908-
* - Stream history is not supported. All compression APIs, including streaming
2909-
* APIs, work with the external matchfinder, but the external matchfinder won't
2910-
* receive any history from the previous block. Each block is an independent chunk.
2919+
* - Stream history is not currently supported. All advanced compression APIs (including streaming APIs)
2920+
* work with external sequence producers, but each block is treated as an independent chunk
2921+
* without history from previous blocks.
29112922
*
2912-
* Third, multi-threading within a single compression is not supported. In other words,
2913-
* COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external matchfinder is registered.
2923+
* Third, multi-threading within a single compression is not currently supported. In other words,
2924+
* COMPRESSION WILL FAIL if ZSTD_c_nbWorkers > 0 and an external sequence producer is registered.
29142925
* Multi-threading across compressions is fine: simply create one CCtx per thread.
29152926
*
29162927
* Long-term, we plan to overcome all three limitations. There is no technical blocker to
29172928
* overcoming them. It is purely a question of engineering effort.
29182929
*/
29192930

2920-
#define ZSTD_EXTERNAL_MATCHFINDER_ERROR ((size_t)(-1))
2931+
#define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t)(-1))
29212932

2922-
typedef size_t ZSTD_externalMatchFinder_F (
2923-
void* externalMatchState,
2933+
typedef size_t ZSTD_sequenceProducer_F (
2934+
void* sequenceProducerState,
29242935
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
29252936
const void* src, size_t srcSize,
29262937
const void* dict, size_t dictSize,
29272938
int compressionLevel,
29282939
size_t windowSize
29292940
);
29302941

2931-
/*! ZSTD_registerExternalMatchFinder() :
2932-
* Instruct zstd to use an external matchfinder function.
2942+
/*! ZSTD_registerSequenceProducer() :
2943+
* Instruct zstd to use a block-level external sequence producer function.
29332944
*
2934-
* The externalMatchState must be initialized by the caller, and the caller is
2945+
* The sequenceProducerState must be initialized by the caller, and the caller is
29352946
* responsible for managing its lifetime. This parameter is sticky across
29362947
* compressions. It will remain set until the user explicitly resets compression
29372948
* parameters.
29382949
*
2939-
* External matchfinder registration is considered to be an "advanced parameter",
2940-
* part of the "advanced API". This means it will only have an effect on
2941-
* compression APIs which respect advanced parameters, such as compress2() and
2942-
* compressStream(). Older compression APIs such as compressCCtx(), which predate
2943-
* the introduction of "advanced parameters", will ignore any external matchfinder
2944-
* setting.
2950+
* Sequence producer registration is considered to be an "advanced parameter",
2951+
* part of the "advanced API". This means it will only have an effect on compression
2952+
* APIs which respect advanced parameters, such as compress2() and compressStream2().
2953+
* Older compression APIs such as compressCCtx(), which predate the introduction of
2954+
* "advanced parameters", will ignore any external sequence producer setting.
29452955
*
2946-
* The external matchfinder can be "cleared" by registering a NULL external
2947-
* matchfinder function pointer. This removes all limitations described above in
2948-
* the "LIMITATIONS" section of the API docs.
2956+
* The sequence producer can be "cleared" by registering a NULL function pointer. This
2957+
* removes all limitations described above in the "LIMITATIONS" section of the API docs.
29492958
*
2950-
* The user is strongly encouraged to read the full API documentation (above)
2951-
* before calling this function. */
2959+
* The user is strongly encouraged to read the full API documentation (above) before
2960+
* calling this function. */
29522961
ZSTDLIB_STATIC_API void
2953-
ZSTD_registerExternalMatchFinder(
2962+
ZSTD_registerExternalSequenceProducer(
29542963
ZSTD_CCtx* cctx,
2955-
void* externalMatchState,
2956-
ZSTD_externalMatchFinder_F* externalMatchFinder
2964+
void* sequenceProducerState,
2965+
ZSTD_sequenceProducer_F* sequenceProducer
29572966
);
29582967

29592968
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */

0 commit comments

Comments
 (0)