|
||||
File indexing completed on 2024-05-18 08:30:30
0001 /* 0002 * Copyright (c) Meta Platforms, Inc. and affiliates. 0003 * All rights reserved. 0004 * 0005 * This source code is licensed under both the BSD-style license (found in the 0006 * LICENSE file in the root directory of this source tree) and the GPLv2 (found 0007 * in the COPYING file in the root directory of this source tree). 0008 * You may select, at your option, one of the above-listed licenses. 0009 */ 0010 0011 #if defined (__cplusplus) 0012 extern "C" { 0013 #endif 0014 0015 #ifndef ZSTD_ZDICT_H 0016 #define ZSTD_ZDICT_H 0017 0018 /*====== Dependencies ======*/ 0019 #include <stddef.h> /* size_t */ 0020 0021 0022 /* ===== ZDICTLIB_API : control library symbols visibility ===== */ 0023 #ifndef ZDICTLIB_VISIBLE 0024 /* Backwards compatibility with old macro name */ 0025 # ifdef ZDICTLIB_VISIBILITY 0026 # define ZDICTLIB_VISIBLE ZDICTLIB_VISIBILITY 0027 # elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__) 0028 # define ZDICTLIB_VISIBLE __attribute__ ((visibility ("default"))) 0029 # else 0030 # define ZDICTLIB_VISIBLE 0031 # endif 0032 #endif 0033 0034 #ifndef ZDICTLIB_HIDDEN 0035 # if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__) 0036 # define ZDICTLIB_HIDDEN __attribute__ ((visibility ("hidden"))) 0037 # else 0038 # define ZDICTLIB_HIDDEN 0039 # endif 0040 #endif 0041 0042 #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) 0043 # define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBLE 0044 #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) 0045 # define ZDICTLIB_API __declspec(dllimport) ZDICTLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ 0046 #else 0047 # define ZDICTLIB_API ZDICTLIB_VISIBLE 0048 #endif 0049 0050 /******************************************************************************* 0051 * Zstd dictionary builder 0052 * 0053 * FAQ 0054 * === 0055 * Why should I use a dictionary? 0056 * ------------------------------ 0057 * 0058 * Zstd can use dictionaries to improve compression ratio of small data. 0059 * Traditionally small files don't compress well because there is very little 0060 * repetition in a single sample, since it is small. But, if you are compressing 0061 * many similar files, like a bunch of JSON records that share the same 0062 * structure, you can train a dictionary on ahead of time on some samples of 0063 * these files. Then, zstd can use the dictionary to find repetitions that are 0064 * present across samples. This can vastly improve compression ratio. 0065 * 0066 * When is a dictionary useful? 0067 * ---------------------------- 0068 * 0069 * Dictionaries are useful when compressing many small files that are similar. 0070 * The larger a file is, the less benefit a dictionary will have. Generally, 0071 * we don't expect dictionary compression to be effective past 100KB. And the 0072 * smaller a file is, the more we would expect the dictionary to help. 0073 * 0074 * How do I use a dictionary? 0075 * -------------------------- 0076 * 0077 * Simply pass the dictionary to the zstd compressor with 0078 * `ZSTD_CCtx_loadDictionary()`. The same dictionary must then be passed to 0079 * the decompressor, using `ZSTD_DCtx_loadDictionary()`. There are other 0080 * more advanced functions that allow selecting some options, see zstd.h for 0081 * complete documentation. 0082 * 0083 * What is a zstd dictionary? 0084 * -------------------------- 0085 * 0086 * A zstd dictionary has two pieces: Its header, and its content. The header 0087 * contains a magic number, the dictionary ID, and entropy tables. These 0088 * entropy tables allow zstd to save on header costs in the compressed file, 0089 * which really matters for small data. The content is just bytes, which are 0090 * repeated content that is common across many samples. 0091 * 0092 * What is a raw content dictionary? 0093 * --------------------------------- 0094 * 0095 * A raw content dictionary is just bytes. It doesn't have a zstd dictionary 0096 * header, a dictionary ID, or entropy tables. Any buffer is a valid raw 0097 * content dictionary. 0098 * 0099 * How do I train a dictionary? 0100 * ---------------------------- 0101 * 0102 * Gather samples from your use case. These samples should be similar to each 0103 * other. If you have several use cases, you could try to train one dictionary 0104 * per use case. 0105 * 0106 * Pass those samples to `ZDICT_trainFromBuffer()` and that will train your 0107 * dictionary. There are a few advanced versions of this function, but this 0108 * is a great starting point. If you want to further tune your dictionary 0109 * you could try `ZDICT_optimizeTrainFromBuffer_cover()`. If that is too slow 0110 * you can try `ZDICT_optimizeTrainFromBuffer_fastCover()`. 0111 * 0112 * If the dictionary training function fails, that is likely because you 0113 * either passed too few samples, or a dictionary would not be effective 0114 * for your data. Look at the messages that the dictionary trainer printed, 0115 * if it doesn't say too few samples, then a dictionary would not be effective. 0116 * 0117 * How large should my dictionary be? 0118 * ---------------------------------- 0119 * 0120 * A reasonable dictionary size, the `dictBufferCapacity`, is about 100KB. 0121 * The zstd CLI defaults to a 110KB dictionary. You likely don't need a 0122 * dictionary larger than that. But, most use cases can get away with a 0123 * smaller dictionary. The advanced dictionary builders can automatically 0124 * shrink the dictionary for you, and select the smallest size that doesn't 0125 * hurt compression ratio too much. See the `shrinkDict` parameter. 0126 * A smaller dictionary can save memory, and potentially speed up 0127 * compression. 0128 * 0129 * How many samples should I provide to the dictionary builder? 0130 * ------------------------------------------------------------ 0131 * 0132 * We generally recommend passing ~100x the size of the dictionary 0133 * in samples. A few thousand should suffice. Having too few samples 0134 * can hurt the dictionaries effectiveness. Having more samples will 0135 * only improve the dictionaries effectiveness. But having too many 0136 * samples can slow down the dictionary builder. 0137 * 0138 * How do I determine if a dictionary will be effective? 0139 * ----------------------------------------------------- 0140 * 0141 * Simply train a dictionary and try it out. You can use zstd's built in 0142 * benchmarking tool to test the dictionary effectiveness. 0143 * 0144 * # Benchmark levels 1-3 without a dictionary 0145 * zstd -b1e3 -r /path/to/my/files 0146 * # Benchmark levels 1-3 with a dictionary 0147 * zstd -b1e3 -r /path/to/my/files -D /path/to/my/dictionary 0148 * 0149 * When should I retrain a dictionary? 0150 * ----------------------------------- 0151 * 0152 * You should retrain a dictionary when its effectiveness drops. Dictionary 0153 * effectiveness drops as the data you are compressing changes. Generally, we do 0154 * expect dictionaries to "decay" over time, as your data changes, but the rate 0155 * at which they decay depends on your use case. Internally, we regularly 0156 * retrain dictionaries, and if the new dictionary performs significantly 0157 * better than the old dictionary, we will ship the new dictionary. 0158 * 0159 * I have a raw content dictionary, how do I turn it into a zstd dictionary? 0160 * ------------------------------------------------------------------------- 0161 * 0162 * If you have a raw content dictionary, e.g. by manually constructing it, or 0163 * using a third-party dictionary builder, you can turn it into a zstd 0164 * dictionary by using `ZDICT_finalizeDictionary()`. You'll also have to 0165 * provide some samples of the data. It will add the zstd header to the 0166 * raw content, which contains a dictionary ID and entropy tables, which 0167 * will improve compression ratio, and allow zstd to write the dictionary ID 0168 * into the frame, if you so choose. 0169 * 0170 * Do I have to use zstd's dictionary builder? 0171 * ------------------------------------------- 0172 * 0173 * No! You can construct dictionary content however you please, it is just 0174 * bytes. It will always be valid as a raw content dictionary. If you want 0175 * a zstd dictionary, which can improve compression ratio, use 0176 * `ZDICT_finalizeDictionary()`. 0177 * 0178 * What is the attack surface of a zstd dictionary? 0179 * ------------------------------------------------ 0180 * 0181 * Zstd is heavily fuzz tested, including loading fuzzed dictionaries, so 0182 * zstd should never crash, or access out-of-bounds memory no matter what 0183 * the dictionary is. However, if an attacker can control the dictionary 0184 * during decompression, they can cause zstd to generate arbitrary bytes, 0185 * just like if they controlled the compressed data. 0186 * 0187 ******************************************************************************/ 0188 0189 0190 /*! ZDICT_trainFromBuffer(): 0191 * Train a dictionary from an array of samples. 0192 * Redirect towards ZDICT_optimizeTrainFromBuffer_fastCover() single-threaded, with d=8, steps=4, 0193 * f=20, and accel=1. 0194 * Samples must be stored concatenated in a single flat buffer `samplesBuffer`, 0195 * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. 0196 * The resulting dictionary will be saved into `dictBuffer`. 0197 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0198 * or an error code, which can be tested with ZDICT_isError(). 0199 * Note: Dictionary training will fail if there are not enough samples to construct a 0200 * dictionary, or if most of the samples are too small (< 8 bytes being the lower limit). 0201 * If dictionary training fails, you should use zstd without a dictionary, as the dictionary 0202 * would've been ineffective anyways. If you believe your samples would benefit from a dictionary 0203 * please open an issue with details, and we can look into it. 0204 * Note: ZDICT_trainFromBuffer()'s memory usage is about 6 MB. 0205 * Tips: In general, a reasonable dictionary has a size of ~ 100 KB. 0206 * It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`. 0207 * In general, it's recommended to provide a few thousands samples, though this can vary a lot. 0208 * It's recommended that total size of all samples be about ~x100 times the target size of dictionary. 0209 */ 0210 ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity, 0211 const void* samplesBuffer, 0212 const size_t* samplesSizes, unsigned nbSamples); 0213 0214 typedef struct { 0215 int compressionLevel; /**< optimize for a specific zstd compression level; 0 means default */ 0216 unsigned notificationLevel; /**< Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */ 0217 unsigned dictID; /**< force dictID value; 0 means auto mode (32-bits random value) 0218 * NOTE: The zstd format reserves some dictionary IDs for future use. 0219 * You may use them in private settings, but be warned that they 0220 * may be used by zstd in a public dictionary registry in the future. 0221 * These dictionary IDs are: 0222 * - low range : <= 32767 0223 * - high range : >= (2^31) 0224 */ 0225 } ZDICT_params_t; 0226 0227 /*! ZDICT_finalizeDictionary(): 0228 * Given a custom content as a basis for dictionary, and a set of samples, 0229 * finalize dictionary by adding headers and statistics according to the zstd 0230 * dictionary format. 0231 * 0232 * Samples must be stored concatenated in a flat buffer `samplesBuffer`, 0233 * supplied with an array of sizes `samplesSizes`, providing the size of each 0234 * sample in order. The samples are used to construct the statistics, so they 0235 * should be representative of what you will compress with this dictionary. 0236 * 0237 * The compression level can be set in `parameters`. You should pass the 0238 * compression level you expect to use in production. The statistics for each 0239 * compression level differ, so tuning the dictionary for the compression level 0240 * can help quite a bit. 0241 * 0242 * You can set an explicit dictionary ID in `parameters`, or allow us to pick 0243 * a random dictionary ID for you, but we can't guarantee no collisions. 0244 * 0245 * The dstDictBuffer and the dictContent may overlap, and the content will be 0246 * appended to the end of the header. If the header + the content doesn't fit in 0247 * maxDictSize the beginning of the content is truncated to make room, since it 0248 * is presumed that the most profitable content is at the end of the dictionary, 0249 * since that is the cheapest to reference. 0250 * 0251 * `maxDictSize` must be >= max(dictContentSize, ZSTD_DICTSIZE_MIN). 0252 * 0253 * @return: size of dictionary stored into `dstDictBuffer` (<= `maxDictSize`), 0254 * or an error code, which can be tested by ZDICT_isError(). 0255 * Note: ZDICT_finalizeDictionary() will push notifications into stderr if 0256 * instructed to, using notificationLevel>0. 0257 * NOTE: This function currently may fail in several edge cases including: 0258 * * Not enough samples 0259 * * Samples are uncompressible 0260 * * Samples are all exactly the same 0261 */ 0262 ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dstDictBuffer, size_t maxDictSize, 0263 const void* dictContent, size_t dictContentSize, 0264 const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, 0265 ZDICT_params_t parameters); 0266 0267 0268 /*====== Helper functions ======*/ 0269 ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize); /**< extracts dictID; @return zero if error (not a valid dictionary) */ 0270 ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize); /* returns dict header size; returns a ZSTD error code on failure */ 0271 ZDICTLIB_API unsigned ZDICT_isError(size_t errorCode); 0272 ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode); 0273 0274 #endif /* ZSTD_ZDICT_H */ 0275 0276 #if defined(ZDICT_STATIC_LINKING_ONLY) && !defined(ZSTD_ZDICT_H_STATIC) 0277 #define ZSTD_ZDICT_H_STATIC 0278 0279 /* This can be overridden externally to hide static symbols. */ 0280 #ifndef ZDICTLIB_STATIC_API 0281 # if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) 0282 # define ZDICTLIB_STATIC_API __declspec(dllexport) ZDICTLIB_VISIBLE 0283 # elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) 0284 # define ZDICTLIB_STATIC_API __declspec(dllimport) ZDICTLIB_VISIBLE 0285 # else 0286 # define ZDICTLIB_STATIC_API ZDICTLIB_VISIBLE 0287 # endif 0288 #endif 0289 0290 /* ==================================================================================== 0291 * The definitions in this section are considered experimental. 0292 * They should never be used with a dynamic library, as they may change in the future. 0293 * They are provided for advanced usages. 0294 * Use them only in association with static linking. 0295 * ==================================================================================== */ 0296 0297 #define ZDICT_DICTSIZE_MIN 256 0298 /* Deprecated: Remove in v1.6.0 */ 0299 #define ZDICT_CONTENTSIZE_MIN 128 0300 0301 /*! ZDICT_cover_params_t: 0302 * k and d are the only required parameters. 0303 * For others, value 0 means default. 0304 */ 0305 typedef struct { 0306 unsigned k; /* Segment size : constraint: 0 < k : Reasonable range [16, 2048+] */ 0307 unsigned d; /* dmer size : constraint: 0 < d <= k : Reasonable range [6, 16] */ 0308 unsigned steps; /* Number of steps : Only used for optimization : 0 means default (40) : Higher means more parameters checked */ 0309 unsigned nbThreads; /* Number of threads : constraint: 0 < nbThreads : 1 means single-threaded : Only used for optimization : Ignored if ZSTD_MULTITHREAD is not defined */ 0310 double splitPoint; /* Percentage of samples used for training: Only used for optimization : the first nbSamples * splitPoint samples will be used to training, the last nbSamples * (1 - splitPoint) samples will be used for testing, 0 means default (1.0), 1.0 when all samples are used for both training and testing */ 0311 unsigned shrinkDict; /* Train dictionaries to shrink in size starting from the minimum size and selects the smallest dictionary that is shrinkDictMaxRegression% worse than the largest dictionary. 0 means no shrinking and 1 means shrinking */ 0312 unsigned shrinkDictMaxRegression; /* Sets shrinkDictMaxRegression so that a smaller dictionary can be at worse shrinkDictMaxRegression% worse than the max dict size dictionary. */ 0313 ZDICT_params_t zParams; 0314 } ZDICT_cover_params_t; 0315 0316 typedef struct { 0317 unsigned k; /* Segment size : constraint: 0 < k : Reasonable range [16, 2048+] */ 0318 unsigned d; /* dmer size : constraint: 0 < d <= k : Reasonable range [6, 16] */ 0319 unsigned f; /* log of size of frequency array : constraint: 0 < f <= 31 : 1 means default(20)*/ 0320 unsigned steps; /* Number of steps : Only used for optimization : 0 means default (40) : Higher means more parameters checked */ 0321 unsigned nbThreads; /* Number of threads : constraint: 0 < nbThreads : 1 means single-threaded : Only used for optimization : Ignored if ZSTD_MULTITHREAD is not defined */ 0322 double splitPoint; /* Percentage of samples used for training: Only used for optimization : the first nbSamples * splitPoint samples will be used to training, the last nbSamples * (1 - splitPoint) samples will be used for testing, 0 means default (0.75), 1.0 when all samples are used for both training and testing */ 0323 unsigned accel; /* Acceleration level: constraint: 0 < accel <= 10, higher means faster and less accurate, 0 means default(1) */ 0324 unsigned shrinkDict; /* Train dictionaries to shrink in size starting from the minimum size and selects the smallest dictionary that is shrinkDictMaxRegression% worse than the largest dictionary. 0 means no shrinking and 1 means shrinking */ 0325 unsigned shrinkDictMaxRegression; /* Sets shrinkDictMaxRegression so that a smaller dictionary can be at worse shrinkDictMaxRegression% worse than the max dict size dictionary. */ 0326 0327 ZDICT_params_t zParams; 0328 } ZDICT_fastCover_params_t; 0329 0330 /*! ZDICT_trainFromBuffer_cover(): 0331 * Train a dictionary from an array of samples using the COVER algorithm. 0332 * Samples must be stored concatenated in a single flat buffer `samplesBuffer`, 0333 * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. 0334 * The resulting dictionary will be saved into `dictBuffer`. 0335 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0336 * or an error code, which can be tested with ZDICT_isError(). 0337 * See ZDICT_trainFromBuffer() for details on failure modes. 0338 * Note: ZDICT_trainFromBuffer_cover() requires about 9 bytes of memory for each input byte. 0339 * Tips: In general, a reasonable dictionary has a size of ~ 100 KB. 0340 * It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`. 0341 * In general, it's recommended to provide a few thousands samples, though this can vary a lot. 0342 * It's recommended that total size of all samples be about ~x100 times the target size of dictionary. 0343 */ 0344 ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_cover( 0345 void *dictBuffer, size_t dictBufferCapacity, 0346 const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples, 0347 ZDICT_cover_params_t parameters); 0348 0349 /*! ZDICT_optimizeTrainFromBuffer_cover(): 0350 * The same requirements as above hold for all the parameters except `parameters`. 0351 * This function tries many parameter combinations and picks the best parameters. 0352 * `*parameters` is filled with the best parameters found, 0353 * dictionary constructed with those parameters is stored in `dictBuffer`. 0354 * 0355 * All of the parameters d, k, steps are optional. 0356 * If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8}. 0357 * if steps is zero it defaults to its default value. 0358 * If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [50, 2000]. 0359 * 0360 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0361 * or an error code, which can be tested with ZDICT_isError(). 0362 * On success `*parameters` contains the parameters selected. 0363 * See ZDICT_trainFromBuffer() for details on failure modes. 0364 * Note: ZDICT_optimizeTrainFromBuffer_cover() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread. 0365 */ 0366 ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_cover( 0367 void* dictBuffer, size_t dictBufferCapacity, 0368 const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, 0369 ZDICT_cover_params_t* parameters); 0370 0371 /*! ZDICT_trainFromBuffer_fastCover(): 0372 * Train a dictionary from an array of samples using a modified version of COVER algorithm. 0373 * Samples must be stored concatenated in a single flat buffer `samplesBuffer`, 0374 * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. 0375 * d and k are required. 0376 * All other parameters are optional, will use default values if not provided 0377 * The resulting dictionary will be saved into `dictBuffer`. 0378 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0379 * or an error code, which can be tested with ZDICT_isError(). 0380 * See ZDICT_trainFromBuffer() for details on failure modes. 0381 * Note: ZDICT_trainFromBuffer_fastCover() requires 6 * 2^f bytes of memory. 0382 * Tips: In general, a reasonable dictionary has a size of ~ 100 KB. 0383 * It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`. 0384 * In general, it's recommended to provide a few thousands samples, though this can vary a lot. 0385 * It's recommended that total size of all samples be about ~x100 times the target size of dictionary. 0386 */ 0387 ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_fastCover(void *dictBuffer, 0388 size_t dictBufferCapacity, const void *samplesBuffer, 0389 const size_t *samplesSizes, unsigned nbSamples, 0390 ZDICT_fastCover_params_t parameters); 0391 0392 /*! ZDICT_optimizeTrainFromBuffer_fastCover(): 0393 * The same requirements as above hold for all the parameters except `parameters`. 0394 * This function tries many parameter combinations (specifically, k and d combinations) 0395 * and picks the best parameters. `*parameters` is filled with the best parameters found, 0396 * dictionary constructed with those parameters is stored in `dictBuffer`. 0397 * All of the parameters d, k, steps, f, and accel are optional. 0398 * If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8}. 0399 * if steps is zero it defaults to its default value. 0400 * If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [50, 2000]. 0401 * If f is zero, default value of 20 is used. 0402 * If accel is zero, default value of 1 is used. 0403 * 0404 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0405 * or an error code, which can be tested with ZDICT_isError(). 0406 * On success `*parameters` contains the parameters selected. 0407 * See ZDICT_trainFromBuffer() for details on failure modes. 0408 * Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread. 0409 */ 0410 ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_fastCover(void* dictBuffer, 0411 size_t dictBufferCapacity, const void* samplesBuffer, 0412 const size_t* samplesSizes, unsigned nbSamples, 0413 ZDICT_fastCover_params_t* parameters); 0414 0415 typedef struct { 0416 unsigned selectivityLevel; /* 0 means default; larger => select more => larger dictionary */ 0417 ZDICT_params_t zParams; 0418 } ZDICT_legacy_params_t; 0419 0420 /*! ZDICT_trainFromBuffer_legacy(): 0421 * Train a dictionary from an array of samples. 0422 * Samples must be stored concatenated in a single flat buffer `samplesBuffer`, 0423 * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. 0424 * The resulting dictionary will be saved into `dictBuffer`. 0425 * `parameters` is optional and can be provided with values set to 0 to mean "default". 0426 * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) 0427 * or an error code, which can be tested with ZDICT_isError(). 0428 * See ZDICT_trainFromBuffer() for details on failure modes. 0429 * Tips: In general, a reasonable dictionary has a size of ~ 100 KB. 0430 * It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`. 0431 * In general, it's recommended to provide a few thousands samples, though this can vary a lot. 0432 * It's recommended that total size of all samples be about ~x100 times the target size of dictionary. 0433 * Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0. 0434 */ 0435 ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_legacy( 0436 void* dictBuffer, size_t dictBufferCapacity, 0437 const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, 0438 ZDICT_legacy_params_t parameters); 0439 0440 0441 /* Deprecation warnings */ 0442 /* It is generally possible to disable deprecation warnings from compiler, 0443 for example with -Wno-deprecated-declarations for gcc 0444 or _CRT_SECURE_NO_WARNINGS in Visual. 0445 Otherwise, it's also possible to manually define ZDICT_DISABLE_DEPRECATE_WARNINGS */ 0446 #ifdef ZDICT_DISABLE_DEPRECATE_WARNINGS 0447 # define ZDICT_DEPRECATED(message) /* disable deprecation warnings */ 0448 #else 0449 # define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 0450 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ 0451 # define ZDICT_DEPRECATED(message) [[deprecated(message)]] 0452 # elif defined(__clang__) || (ZDICT_GCC_VERSION >= 405) 0453 # define ZDICT_DEPRECATED(message) __attribute__((deprecated(message))) 0454 # elif (ZDICT_GCC_VERSION >= 301) 0455 # define ZDICT_DEPRECATED(message) __attribute__((deprecated)) 0456 # elif defined(_MSC_VER) 0457 # define ZDICT_DEPRECATED(message) __declspec(deprecated(message)) 0458 # else 0459 # pragma message("WARNING: You need to implement ZDICT_DEPRECATED for this compiler") 0460 # define ZDICT_DEPRECATED(message) 0461 # endif 0462 #endif /* ZDICT_DISABLE_DEPRECATE_WARNINGS */ 0463 0464 ZDICT_DEPRECATED("use ZDICT_finalizeDictionary() instead") 0465 ZDICTLIB_STATIC_API 0466 size_t ZDICT_addEntropyTablesFromBuffer(void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity, 0467 const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples); 0468 0469 0470 #endif /* ZSTD_ZDICT_H_STATIC */ 0471 0472 #if defined (__cplusplus) 0473 } 0474 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.5 LXR engine. The LXR team |