@@ -478,7 +478,7 @@ typedef enum {
478
478
* ZSTD_c_useBlockSplitter
479
479
* ZSTD_c_useRowMatchFinder
480
480
* ZSTD_c_prefetchCDictTables
481
- * ZSTD_c_enableMatchFinderFallback
481
+ * ZSTD_c_enableSeqProducerFallback
482
482
* ZSTD_c_maxBlockSize
483
483
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
484
484
* note : never ever use experimentalParam? names directly;
@@ -565,7 +565,7 @@ typedef enum {
565
565
* They will be used to compress next frame.
566
566
* Resetting session never fails.
567
567
* - 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 .
569
569
* Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing)
570
570
* otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError())
571
571
* - 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);
1627
1627
* Note : only single-threaded compression is supported.
1628
1628
* ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
1629
1629
*
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.
1632
1632
*/
1633
1633
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize (int compressionLevel);
1634
1634
ZSTDLIB_STATIC_API size_t ZSTD_estimateCCtxSize_usingCParams (ZSTD_compressionParameters cParams);
@@ -1650,8 +1650,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_estimateDCtxSize(void);
1650
1650
* In this case, get total size by adding ZSTD_estimate?DictSize
1651
1651
* Note 2 : only single-threaded compression is supported.
1652
1652
* 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.
1655
1655
*/
1656
1656
ZSTDLIB_STATIC_API size_t ZSTD_estimateCStreamSize (int compressionLevel);
1657
1657
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
2113
2113
*/
2114
2114
#define ZSTD_c_prefetchCDictTables ZSTD_c_experimentalParam16
2115
2115
2116
- /* ZSTD_c_enableMatchFinderFallback
2116
+ /* ZSTD_c_enableSeqProducerFallback
2117
2117
* Allowed values are 0 (disable) and 1 (enable). The default setting is 0.
2118
2118
*
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
2123
2123
* follow any other cParam settings, such as compression level, the same as in a
2124
2124
* normal (fully-internal) compression operation.
2125
2125
*
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
2127
2127
* documentation (below) before setting this parameter. */
2128
- #define ZSTD_c_enableMatchFinderFallback ZSTD_c_experimentalParam17
2128
+ #define ZSTD_c_enableSeqProducerFallback ZSTD_c_experimentalParam17
2129
2129
2130
2130
/* ZSTD_c_maxBlockSize
2131
2131
* 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
2141
2141
2142
2142
/* ZSTD_c_searchForExternalRepcodes
2143
2143
* 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.
2145
2146
*
2146
2147
* If set to ZSTD_ps_enable, the library will check for repeated offsets in
2147
2148
* external sequences, even if those repcodes are not explicitly indicated in
2148
2149
* 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
2150
2151
* currently ignores the "rep" field of external sequences.
2151
2152
*
2152
2153
* 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_
2805
2806
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. */
2806
2807
2807
2808
2808
- /* ********************** EXTERNAL MATCHFINDER API * *********************
2809
+ /* ********************* BLOCK-LEVEL SEQUENCE PRODUCER API *********************
2809
2810
*
2810
2811
* *** 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.
2818
2829
*
2819
2830
* *** USAGE ***
2820
2831
* 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
2822
2833
* arguments to the user-provided function:
2823
2834
*
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 .
2826
2837
*
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.
2831
2841
*
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.
2834
2844
*
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.
2839
2849
*
2840
2850
* - 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.
2845
2855
*
2846
2856
* - windowSize: a size_t representing the maximum allowed offset for external
2847
2857
* 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
2851
2861
* The user-provided function shall return a size_t representing the number of
2852
2862
* sequences written to outSeqs. This return value will be treated as an error
2853
2863
* 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
2855
2865
* for convenience, but any value greater than outSeqsCapacity will be treated as
2856
2866
* an error code.
2857
2867
*
@@ -2870,90 +2880,89 @@ ZSTDLIB_STATIC_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* bloc
2870
2880
* validation has a performance cost.
2871
2881
*
2872
2882
* 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.
2887
2898
*
2888
2899
* *** 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.
2899
2910
* - As of this writing, ZSTD_c_enableLongDistanceMatching is disabled by default
2900
2911
* 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 ).
2903
2914
*
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
2907
2918
* 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 .
2911
2922
*
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.
2914
2925
* Multi-threading across compressions is fine: simply create one CCtx per thread.
2915
2926
*
2916
2927
* Long-term, we plan to overcome all three limitations. There is no technical blocker to
2917
2928
* overcoming them. It is purely a question of engineering effort.
2918
2929
*/
2919
2930
2920
- #define ZSTD_EXTERNAL_MATCHFINDER_ERROR ((size_t )(-1 ))
2931
+ #define ZSTD_SEQUENCE_PRODUCER_ERROR ((size_t )(-1 ))
2921
2932
2922
- typedef size_t ZSTD_externalMatchFinder_F (
2923
- void * externalMatchState ,
2933
+ typedef size_t ZSTD_sequenceProducer_F (
2934
+ void * sequenceProducerState ,
2924
2935
ZSTD_Sequence* outSeqs, size_t outSeqsCapacity,
2925
2936
const void * src, size_t srcSize,
2926
2937
const void * dict, size_t dictSize,
2927
2938
int compressionLevel,
2928
2939
size_t windowSize
2929
2940
);
2930
2941
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.
2933
2944
*
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
2935
2946
* responsible for managing its lifetime. This parameter is sticky across
2936
2947
* compressions. It will remain set until the user explicitly resets compression
2937
2948
* parameters.
2938
2949
*
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.
2945
2955
*
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.
2949
2958
*
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. */
2952
2961
ZSTDLIB_STATIC_API void
2953
- ZSTD_registerExternalMatchFinder (
2962
+ ZSTD_registerExternalSequenceProducer (
2954
2963
ZSTD_CCtx* cctx,
2955
- void * externalMatchState ,
2956
- ZSTD_externalMatchFinder_F* externalMatchFinder
2964
+ void * sequenceProducerState ,
2965
+ ZSTD_sequenceProducer_F* sequenceProducer
2957
2966
);
2958
2967
2959
2968
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */
0 commit comments