zstd_sys/
bindings_zdict_experimental.rs

1/*
2This file is auto-generated from the public API of the zstd library.
3It is released under the same BSD license.
4
5BSD License
6
7For Zstandard software
8
9Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
10
11Redistribution and use in source and binary forms, with or without modification,
12are permitted provided that the following conditions are met:
13
14 * Redistributions of source code must retain the above copyright notice, this
15   list of conditions and the following disclaimer.
16
17 * Redistributions in binary form must reproduce the above copyright notice,
18   this list of conditions and the following disclaimer in the documentation
19   and/or other materials provided with the distribution.
20
21 * Neither the name Facebook, nor Meta, nor the names of its contributors may
22   be used to endorse or promote products derived from this software without
23   specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
29ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35*/
36/* automatically generated by rust-bindgen 0.71.1 */
37
38pub const ZDICT_DICTSIZE_MIN: u32 = 256;
39pub const ZDICT_CONTENTSIZE_MIN: u32 = 128;
40extern "C" {
41    #[doc = " ZDICT_trainFromBuffer():\n  Train a dictionary from an array of samples.\n  Redirect towards ZDICT_optimizeTrainFromBuffer_fastCover() single-threaded, with d=8, steps=4,\n  f=20, and accel=1.\n  Samples must be stored concatenated in a single flat buffer `samplesBuffer`,\n  supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.\n  The resulting dictionary will be saved into `dictBuffer`.\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n  Note:  Dictionary training will fail if there are not enough samples to construct a\n         dictionary, or if most of the samples are too small (< 8 bytes being the lower limit).\n         If dictionary training fails, you should use zstd without a dictionary, as the dictionary\n         would've been ineffective anyways. If you believe your samples would benefit from a dictionary\n         please open an issue with details, and we can look into it.\n  Note: ZDICT_trainFromBuffer()'s memory usage is about 6 MB.\n  Tips: In general, a reasonable dictionary has a size of ~ 100 KB.\n        It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`.\n        In general, it's recommended to provide a few thousands samples, though this can vary a lot.\n        It's recommended that total size of all samples be about ~x100 times the target size of dictionary."]
42    pub fn ZDICT_trainFromBuffer(
43        dictBuffer: *mut ::core::ffi::c_void,
44        dictBufferCapacity: usize,
45        samplesBuffer: *const ::core::ffi::c_void,
46        samplesSizes: *const usize,
47        nbSamples: ::core::ffi::c_uint,
48    ) -> usize;
49}
50#[repr(C)]
51#[derive(Debug, Copy, Clone)]
52pub struct ZDICT_params_t {
53    #[doc = "< optimize for a specific zstd compression level; 0 means default"]
54    pub compressionLevel: ::core::ffi::c_int,
55    #[doc = "< Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug;"]
56    pub notificationLevel: ::core::ffi::c_uint,
57    #[doc = "< force dictID value; 0 means auto mode (32-bits random value)\n   NOTE: The zstd format reserves some dictionary IDs for future use.\n         You may use them in private settings, but be warned that they\n         may be used by zstd in a public dictionary registry in the future.\n         These dictionary IDs are:\n           - low range  : <= 32767\n           - high range : >= (2^31)"]
58    pub dictID: ::core::ffi::c_uint,
59}
60extern "C" {
61    #[doc = " ZDICT_finalizeDictionary():\n Given a custom content as a basis for dictionary, and a set of samples,\n finalize dictionary by adding headers and statistics according to the zstd\n dictionary format.\n\n Samples must be stored concatenated in a flat buffer `samplesBuffer`,\n supplied with an array of sizes `samplesSizes`, providing the size of each\n sample in order. The samples are used to construct the statistics, so they\n should be representative of what you will compress with this dictionary.\n\n The compression level can be set in `parameters`. You should pass the\n compression level you expect to use in production. The statistics for each\n compression level differ, so tuning the dictionary for the compression level\n can help quite a bit.\n\n You can set an explicit dictionary ID in `parameters`, or allow us to pick\n a random dictionary ID for you, but we can't guarantee no collisions.\n\n The dstDictBuffer and the dictContent may overlap, and the content will be\n appended to the end of the header. If the header + the content doesn't fit in\n maxDictSize the beginning of the content is truncated to make room, since it\n is presumed that the most profitable content is at the end of the dictionary,\n since that is the cheapest to reference.\n\n `maxDictSize` must be >= max(dictContentSize, ZDICT_DICTSIZE_MIN).\n\n @return: size of dictionary stored into `dstDictBuffer` (<= `maxDictSize`),\n          or an error code, which can be tested by ZDICT_isError().\n Note: ZDICT_finalizeDictionary() will push notifications into stderr if\n       instructed to, using notificationLevel>0.\n NOTE: This function currently may fail in several edge cases including:\n         * Not enough samples\n         * Samples are uncompressible\n         * Samples are all exactly the same"]
62    pub fn ZDICT_finalizeDictionary(
63        dstDictBuffer: *mut ::core::ffi::c_void,
64        maxDictSize: usize,
65        dictContent: *const ::core::ffi::c_void,
66        dictContentSize: usize,
67        samplesBuffer: *const ::core::ffi::c_void,
68        samplesSizes: *const usize,
69        nbSamples: ::core::ffi::c_uint,
70        parameters: ZDICT_params_t,
71    ) -> usize;
72}
73extern "C" {
74    pub fn ZDICT_getDictID(
75        dictBuffer: *const ::core::ffi::c_void,
76        dictSize: usize,
77    ) -> ::core::ffi::c_uint;
78}
79extern "C" {
80    pub fn ZDICT_getDictHeaderSize(
81        dictBuffer: *const ::core::ffi::c_void,
82        dictSize: usize,
83    ) -> usize;
84}
85extern "C" {
86    pub fn ZDICT_isError(errorCode: usize) -> ::core::ffi::c_uint;
87}
88extern "C" {
89    pub fn ZDICT_getErrorName(errorCode: usize) -> *const ::core::ffi::c_char;
90}
91#[doc = " ZDICT_cover_params_t:\n  k and d are the only required parameters.\n  For others, value 0 means default."]
92#[repr(C)]
93#[derive(Debug, Copy, Clone)]
94pub struct ZDICT_cover_params_t {
95    pub k: ::core::ffi::c_uint,
96    pub d: ::core::ffi::c_uint,
97    pub steps: ::core::ffi::c_uint,
98    pub nbThreads: ::core::ffi::c_uint,
99    pub splitPoint: f64,
100    pub shrinkDict: ::core::ffi::c_uint,
101    pub shrinkDictMaxRegression: ::core::ffi::c_uint,
102    pub zParams: ZDICT_params_t,
103}
104#[repr(C)]
105#[derive(Debug, Copy, Clone)]
106pub struct ZDICT_fastCover_params_t {
107    pub k: ::core::ffi::c_uint,
108    pub d: ::core::ffi::c_uint,
109    pub f: ::core::ffi::c_uint,
110    pub steps: ::core::ffi::c_uint,
111    pub nbThreads: ::core::ffi::c_uint,
112    pub splitPoint: f64,
113    pub accel: ::core::ffi::c_uint,
114    pub shrinkDict: ::core::ffi::c_uint,
115    pub shrinkDictMaxRegression: ::core::ffi::c_uint,
116    pub zParams: ZDICT_params_t,
117}
118extern "C" {
119    #[doc = " ZDICT_trainFromBuffer_cover():\n  Train a dictionary from an array of samples using the COVER algorithm.\n  Samples must be stored concatenated in a single flat buffer `samplesBuffer`,\n  supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.\n  The resulting dictionary will be saved into `dictBuffer`.\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n          See ZDICT_trainFromBuffer() for details on failure modes.\n  Note: ZDICT_trainFromBuffer_cover() requires about 9 bytes of memory for each input byte.\n  Tips: In general, a reasonable dictionary has a size of ~ 100 KB.\n        It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`.\n        In general, it's recommended to provide a few thousands samples, though this can vary a lot.\n        It's recommended that total size of all samples be about ~x100 times the target size of dictionary."]
120    pub fn ZDICT_trainFromBuffer_cover(
121        dictBuffer: *mut ::core::ffi::c_void,
122        dictBufferCapacity: usize,
123        samplesBuffer: *const ::core::ffi::c_void,
124        samplesSizes: *const usize,
125        nbSamples: ::core::ffi::c_uint,
126        parameters: ZDICT_cover_params_t,
127    ) -> usize;
128}
129extern "C" {
130    #[doc = " ZDICT_optimizeTrainFromBuffer_cover():\n The same requirements as above hold for all the parameters except `parameters`.\n This function tries many parameter combinations and picks the best parameters.\n `*parameters` is filled with the best parameters found,\n dictionary constructed with those parameters is stored in `dictBuffer`.\n\n All of the parameters d, k, steps are optional.\n If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8}.\n if steps is zero it defaults to its default value.\n If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [50, 2000].\n\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n          On success `*parameters` contains the parameters selected.\n          See ZDICT_trainFromBuffer() for details on failure modes.\n 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."]
131    pub fn ZDICT_optimizeTrainFromBuffer_cover(
132        dictBuffer: *mut ::core::ffi::c_void,
133        dictBufferCapacity: usize,
134        samplesBuffer: *const ::core::ffi::c_void,
135        samplesSizes: *const usize,
136        nbSamples: ::core::ffi::c_uint,
137        parameters: *mut ZDICT_cover_params_t,
138    ) -> usize;
139}
140extern "C" {
141    #[doc = " ZDICT_trainFromBuffer_fastCover():\n  Train a dictionary from an array of samples using a modified version of COVER algorithm.\n  Samples must be stored concatenated in a single flat buffer `samplesBuffer`,\n  supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.\n  d and k are required.\n  All other parameters are optional, will use default values if not provided\n  The resulting dictionary will be saved into `dictBuffer`.\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n          See ZDICT_trainFromBuffer() for details on failure modes.\n  Note: ZDICT_trainFromBuffer_fastCover() requires 6 * 2^f bytes of memory.\n  Tips: In general, a reasonable dictionary has a size of ~ 100 KB.\n        It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`.\n        In general, it's recommended to provide a few thousands samples, though this can vary a lot.\n        It's recommended that total size of all samples be about ~x100 times the target size of dictionary."]
142    pub fn ZDICT_trainFromBuffer_fastCover(
143        dictBuffer: *mut ::core::ffi::c_void,
144        dictBufferCapacity: usize,
145        samplesBuffer: *const ::core::ffi::c_void,
146        samplesSizes: *const usize,
147        nbSamples: ::core::ffi::c_uint,
148        parameters: ZDICT_fastCover_params_t,
149    ) -> usize;
150}
151extern "C" {
152    #[doc = " ZDICT_optimizeTrainFromBuffer_fastCover():\n The same requirements as above hold for all the parameters except `parameters`.\n This function tries many parameter combinations (specifically, k and d combinations)\n and picks the best parameters. `*parameters` is filled with the best parameters found,\n dictionary constructed with those parameters is stored in `dictBuffer`.\n All of the parameters d, k, steps, f, and accel are optional.\n If d is non-zero then we don't check multiple values of d, otherwise we check d = {6, 8}.\n if steps is zero it defaults to its default value.\n If k is non-zero then we don't check multiple values of k, otherwise we check steps values in [50, 2000].\n If f is zero, default value of 20 is used.\n If accel is zero, default value of 1 is used.\n\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n          On success `*parameters` contains the parameters selected.\n          See ZDICT_trainFromBuffer() for details on failure modes.\n Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread."]
153    pub fn ZDICT_optimizeTrainFromBuffer_fastCover(
154        dictBuffer: *mut ::core::ffi::c_void,
155        dictBufferCapacity: usize,
156        samplesBuffer: *const ::core::ffi::c_void,
157        samplesSizes: *const usize,
158        nbSamples: ::core::ffi::c_uint,
159        parameters: *mut ZDICT_fastCover_params_t,
160    ) -> usize;
161}
162#[repr(C)]
163#[derive(Debug, Copy, Clone)]
164pub struct ZDICT_legacy_params_t {
165    pub selectivityLevel: ::core::ffi::c_uint,
166    pub zParams: ZDICT_params_t,
167}
168extern "C" {
169    #[doc = " ZDICT_trainFromBuffer_legacy():\n  Train a dictionary from an array of samples.\n  Samples must be stored concatenated in a single flat buffer `samplesBuffer`,\n  supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order.\n  The resulting dictionary will be saved into `dictBuffer`.\n `parameters` is optional and can be provided with values set to 0 to mean \"default\".\n @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)\n          or an error code, which can be tested with ZDICT_isError().\n          See ZDICT_trainFromBuffer() for details on failure modes.\n  Tips: In general, a reasonable dictionary has a size of ~ 100 KB.\n        It's possible to select smaller or larger size, just by specifying `dictBufferCapacity`.\n        In general, it's recommended to provide a few thousands samples, though this can vary a lot.\n        It's recommended that total size of all samples be about ~x100 times the target size of dictionary.\n  Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0."]
170    pub fn ZDICT_trainFromBuffer_legacy(
171        dictBuffer: *mut ::core::ffi::c_void,
172        dictBufferCapacity: usize,
173        samplesBuffer: *const ::core::ffi::c_void,
174        samplesSizes: *const usize,
175        nbSamples: ::core::ffi::c_uint,
176        parameters: ZDICT_legacy_params_t,
177    ) -> usize;
178}
179extern "C" {
180    pub fn ZDICT_addEntropyTablesFromBuffer(
181        dictBuffer: *mut ::core::ffi::c_void,
182        dictContentSize: usize,
183        dictBufferCapacity: usize,
184        samplesBuffer: *const ::core::ffi::c_void,
185        samplesSizes: *const usize,
186        nbSamples: ::core::ffi::c_uint,
187    ) -> usize;
188}