contrib/python-zstandard/zstd/compress/zstdmt_compress.h
changeset 42937 69de49c4e39c
parent 42070 675775c33ab6
equal deleted inserted replaced
42936:2da754532dd3 42937:69de49c4e39c
    15  extern "C" {
    15  extern "C" {
    16  #endif
    16  #endif
    17 
    17 
    18 
    18 
    19 /* Note : This is an internal API.
    19 /* Note : This is an internal API.
    20  *        Some methods are still exposed (ZSTDLIB_API),
    20  *        These APIs used to be exposed with ZSTDLIB_API,
    21  *        because it used to be the only way to invoke MT compression.
    21  *        because it used to be the only way to invoke MT compression.
    22  *        Now, it's recommended to use ZSTD_compress_generic() instead.
    22  *        Now, it's recommended to use ZSTD_compress2 and ZSTD_compressStream2()
    23  *        These methods will stop being exposed in a future version */
    23  *        instead.
       
    24  *
       
    25  *        If you depend on these APIs and can't switch, then define
       
    26  *        ZSTD_LEGACY_MULTITHREADED_API when making the dynamic library.
       
    27  *        However, we may completely remove these functions in a future
       
    28  *        release, so please switch soon.
       
    29  *
       
    30  *        This API requires ZSTD_MULTITHREAD to be defined during compilation,
       
    31  *        otherwise ZSTDMT_createCCtx*() will fail.
       
    32  */
       
    33 
       
    34 #ifdef ZSTD_LEGACY_MULTITHREADED_API
       
    35 #  define ZSTDMT_API ZSTDLIB_API
       
    36 #else
       
    37 #  define ZSTDMT_API
       
    38 #endif
    24 
    39 
    25 /* ===   Dependencies   === */
    40 /* ===   Dependencies   === */
    26 #include <stddef.h>                /* size_t */
    41 #include <stddef.h>                /* size_t */
    27 #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_parameters */
    42 #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_parameters */
    28 #include "zstd.h"            /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
    43 #include "zstd.h"            /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
    33 #  define ZSTDMT_NBWORKERS_MAX 200
    48 #  define ZSTDMT_NBWORKERS_MAX 200
    34 #endif
    49 #endif
    35 #ifndef ZSTDMT_JOBSIZE_MIN
    50 #ifndef ZSTDMT_JOBSIZE_MIN
    36 #  define ZSTDMT_JOBSIZE_MIN (1 MB)
    51 #  define ZSTDMT_JOBSIZE_MIN (1 MB)
    37 #endif
    52 #endif
       
    53 #define ZSTDMT_JOBLOG_MAX   (MEM_32bits() ? 29 : 30)
    38 #define ZSTDMT_JOBSIZE_MAX  (MEM_32bits() ? (512 MB) : (1024 MB))
    54 #define ZSTDMT_JOBSIZE_MAX  (MEM_32bits() ? (512 MB) : (1024 MB))
    39 
    55 
    40 
    56 
    41 /* ===   Memory management   === */
    57 /* ===   Memory management   === */
    42 typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
    58 typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
    43 ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbWorkers);
    59 /* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
    44 ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
    60 ZSTDMT_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbWorkers);
       
    61 /* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
       
    62 ZSTDMT_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
    45                                                     ZSTD_customMem cMem);
    63                                                     ZSTD_customMem cMem);
    46 ZSTDLIB_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
    64 ZSTDMT_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
    47 
    65 
    48 ZSTDLIB_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
    66 ZSTDMT_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
    49 
    67 
    50 
    68 
    51 /* ===   Simple one-pass compression function   === */
    69 /* ===   Simple one-pass compression function   === */
    52 
    70 
    53 ZSTDLIB_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
    71 ZSTDMT_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
    54                                        void* dst, size_t dstCapacity,
    72                                        void* dst, size_t dstCapacity,
    55                                  const void* src, size_t srcSize,
    73                                  const void* src, size_t srcSize,
    56                                        int compressionLevel);
    74                                        int compressionLevel);
    57 
    75 
    58 
    76 
    59 
    77 
    60 /* ===   Streaming functions   === */
    78 /* ===   Streaming functions   === */
    61 
    79 
    62 ZSTDLIB_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel);
    80 ZSTDMT_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel);
    63 ZSTDLIB_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize);  /**< if srcSize is not known at reset time, use ZSTD_CONTENTSIZE_UNKNOWN. Note: for compatibility with older programs, 0 means the same as ZSTD_CONTENTSIZE_UNKNOWN, but it will change in the future to mean "empty" */
    81 ZSTDMT_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize);  /**< if srcSize is not known at reset time, use ZSTD_CONTENTSIZE_UNKNOWN. Note: for compatibility with older programs, 0 means the same as ZSTD_CONTENTSIZE_UNKNOWN, but it will change in the future to mean "empty" */
    64 
    82 
    65 ZSTDLIB_API size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
    83 ZSTDMT_API size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
    66 ZSTDLIB_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
    84 ZSTDMT_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
    67 
    85 
    68 ZSTDLIB_API size_t ZSTDMT_flushStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output);   /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
    86 ZSTDMT_API size_t ZSTDMT_flushStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output);   /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
    69 ZSTDLIB_API size_t ZSTDMT_endStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output);     /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
    87 ZSTDMT_API size_t ZSTDMT_endStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output);     /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
    70 
    88 
    71 
    89 
    72 /* ===   Advanced functions and parameters  === */
    90 /* ===   Advanced functions and parameters  === */
    73 
    91 
    74 ZSTDLIB_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
    92 ZSTDMT_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
    75                                            void* dst, size_t dstCapacity,
    93                                           void* dst, size_t dstCapacity,
    76                                      const void* src, size_t srcSize,
    94                                     const void* src, size_t srcSize,
    77                                      const ZSTD_CDict* cdict,
    95                                     const ZSTD_CDict* cdict,
    78                                            ZSTD_parameters params,
    96                                           ZSTD_parameters params,
    79                                            int overlapLog);
    97                                           int overlapLog);
    80 
    98 
    81 ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
    99 ZSTDMT_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
    82                                         const void* dict, size_t dictSize,   /* dict can be released after init, a local copy is preserved within zcs */
   100                                         const void* dict, size_t dictSize,   /* dict can be released after init, a local copy is preserved within zcs */
    83                                         ZSTD_parameters params,
   101                                         ZSTD_parameters params,
    84                                         unsigned long long pledgedSrcSize);  /* pledgedSrcSize is optional and can be zero == unknown */
   102                                         unsigned long long pledgedSrcSize);  /* pledgedSrcSize is optional and can be zero == unknown */
    85 
   103 
    86 ZSTDLIB_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
   104 ZSTDMT_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
    87                                         const ZSTD_CDict* cdict,
   105                                         const ZSTD_CDict* cdict,
    88                                         ZSTD_frameParameters fparams,
   106                                         ZSTD_frameParameters fparams,
    89                                         unsigned long long pledgedSrcSize);  /* note : zero means empty */
   107                                         unsigned long long pledgedSrcSize);  /* note : zero means empty */
    90 
   108 
    91 /* ZSTDMT_parameter :
   109 /* ZSTDMT_parameter :
    92  * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
   110  * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
    93 typedef enum {
   111 typedef enum {
    94     ZSTDMT_p_jobSize,     /* Each job is compressed in parallel. By default, this value is dynamically determined depending on compression parameters. Can be set explicitly here. */
   112     ZSTDMT_p_jobSize,     /* Each job is compressed in parallel. By default, this value is dynamically determined depending on compression parameters. Can be set explicitly here. */
    95     ZSTDMT_p_overlapLog,  /* Each job may reload a part of previous job to enhance compressionr ratio; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window. This is a "sticky" parameter : its value will be re-used on next compression job */
   113     ZSTDMT_p_overlapLog,  /* Each job may reload a part of previous job to enhance compression ratio; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window. This is a "sticky" parameter : its value will be re-used on next compression job */
    96     ZSTDMT_p_rsyncable    /* Enables rsyncable mode. */
   114     ZSTDMT_p_rsyncable    /* Enables rsyncable mode. */
    97 } ZSTDMT_parameter;
   115 } ZSTDMT_parameter;
    98 
   116 
    99 /* ZSTDMT_setMTCtxParameter() :
   117 /* ZSTDMT_setMTCtxParameter() :
   100  * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
   118  * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
   101  * The function must be called typically after ZSTD_createCCtx() but __before ZSTDMT_init*() !__
   119  * The function must be called typically after ZSTD_createCCtx() but __before ZSTDMT_init*() !__
   102  * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
   120  * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
   103  * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
   121  * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
   104 ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int value);
   122 ZSTDMT_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int value);
   105 
   123 
   106 /* ZSTDMT_getMTCtxParameter() :
   124 /* ZSTDMT_getMTCtxParameter() :
   107  * Query the ZSTDMT_CCtx for a parameter value.
   125  * Query the ZSTDMT_CCtx for a parameter value.
   108  * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
   126  * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
   109 ZSTDLIB_API size_t ZSTDMT_getMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int* value);
   127 ZSTDMT_API size_t ZSTDMT_getMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, int* value);
   110 
   128 
   111 
   129 
   112 /*! ZSTDMT_compressStream_generic() :
   130 /*! ZSTDMT_compressStream_generic() :
   113  *  Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
   131  *  Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
   114  *  depending on flush directive.
   132  *  depending on flush directive.
   115  * @return : minimum amount of data still to be flushed
   133  * @return : minimum amount of data still to be flushed
   116  *           0 if fully flushed
   134  *           0 if fully flushed
   117  *           or an error code
   135  *           or an error code
   118  *  note : needs to be init using any ZSTD_initCStream*() variant */
   136  *  note : needs to be init using any ZSTD_initCStream*() variant */
   119 ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
   137 ZSTDMT_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
   120                                                 ZSTD_outBuffer* output,
   138                                                 ZSTD_outBuffer* output,
   121                                                 ZSTD_inBuffer* input,
   139                                                 ZSTD_inBuffer* input,
   122                                                 ZSTD_EndDirective endOp);
   140                                                 ZSTD_EndDirective endOp);
   123 
   141 
   124 
   142