VR-Vantage 3.0 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tracy_lz4hc.hpp
Go to the documentation of this file.
1 /*
2  LZ4 HC - High Compression Mode of LZ4
3  Header File
4  Copyright (C) 2011-2017, Yann Collet.
5  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are
9  met:
10 
11  * Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13  * Redistributions in binary form must reproduce the above
14  copyright notice, this list of conditions and the following disclaimer
15  in the documentation and/or other materials provided with the
16  distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30  You can contact the author at :
31  - LZ4 source repository : https://github.com/lz4/lz4
32  - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
33 */
34 #ifndef TRACY_LZ4_HC_H_19834876238432
35 #define TRACY_LZ4_HC_H_19834876238432
36 
37 /* --- Dependency --- */
38 /* note : lz4hc requires lz4.h/lz4.c for compilation */
39 #include "tracy_lz4.hpp" /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
40 
41 
42 /* --- Useful constants --- */
43 #define LZ4HC_CLEVEL_MIN 3
44 #define LZ4HC_CLEVEL_DEFAULT 9
45 #define LZ4HC_CLEVEL_OPT_MIN 10
46 #define LZ4HC_CLEVEL_MAX 12
47 
48 namespace tracy
49 {
50 
51 /*-************************************
52  * Block Compression
53  **************************************/
64 LZ4LIB_API int LZ4_compress_HC (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
65 
66 
67 /* Note :
68  * Decompression functions are provided within "lz4.h" (BSD license)
69  */
70 
71 
78 LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
79 
80 
89 LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
90  const char* src, char* dst,
91  int* srcSizePtr, int targetDstSize,
92  int compressionLevel);
93 
94 
95 /*-************************************
96  * Streaming Compression
97  * Bufferless synchronous API
98  **************************************/
99  typedef union LZ4_streamHC_u LZ4_streamHC_t; /* incomplete type (defined later) */
100 
108 LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
109 
110 /*
111  These functions compress data in successive blocks of any size,
112  using previous blocks as dictionary, to improve compression ratio.
113  One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
114  There is an exception for ring buffers, which can be smaller than 64 KB.
115  Ring-buffer scenario is automatically detected and handled within LZ4_compress_HC_continue().
116 
117  Before starting compression, state must be allocated and properly initialized.
118  LZ4_createStreamHC() does both, though compression level is set to LZ4HC_CLEVEL_DEFAULT.
119 
120  Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
121  or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
122  LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
123  which is automatically the case when state is created using LZ4_createStreamHC().
124 
125  After reset, a first "fictional block" can be designated as initial dictionary,
126  using LZ4_loadDictHC() (Optional).
127 
128  Invoke LZ4_compress_HC_continue() to compress each successive block.
129  The number of blocks is unlimited.
130  Previous input blocks, including initial dictionary when present,
131  must remain accessible and unmodified during compression.
132 
133  It's allowed to update compression level anytime between blocks,
134  using LZ4_setCompressionLevel() (experimental).
135 
136  'dst' buffer should be sized to handle worst case scenarios
137  (see LZ4_compressBound(), it ensures compression success).
138  In case of failure, the API does not guarantee recovery,
139  so the state _must_ be reset.
140  To ensure compression success
141  whenever `dst` buffer size cannot be made >= LZ4_compressBound(),
142  consider using LZ4_compress_HC_continue_destSize().
143 
144  Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
145  it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
146  Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
147 
148  After completing a streaming compression,
149  it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
150  just by resetting it, using LZ4_resetStreamHC_fast().
151 */
152 
153 LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel); /* v1.9.0+ */
154 LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
155 
157  const char* src, char* dst,
158  int srcSize, int maxDstSize);
159 
171  const char* src, char* dst,
172  int* srcSizePtr, int targetDstSize);
173 
174 LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
175 
176 
177 
178 /*^**********************************************
179  * !!!!!! STATIC LINKING ONLY !!!!!!
180  ***********************************************/
181 
182 /*-******************************************************************
183  * PRIVATE DEFINITIONS :
184  * Do not use these definitions directly.
185  * They are merely exposed to allow static allocation of `LZ4_streamHC_t`.
186  * Declare an `LZ4_streamHC_t` directly, rather than any type below.
187  * Even then, only do so in the context of static linking, as definitions may change between versions.
188  ********************************************************************/
189 
190 #define LZ4HC_DICTIONARY_LOGSIZE 16
191 #define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
192 #define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
193 
194 #define LZ4HC_HASH_LOG 15
195 #define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
196 #define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
197 
198 
201 {
204  const LZ4_byte* end; /* next block here to continue on current prefix */
205  const LZ4_byte* base; /* All index relative to this position */
206  const LZ4_byte* dictBase; /* alternate base for extDict */
207  LZ4_u32 dictLimit; /* below that point, need extDict */
208  LZ4_u32 lowLimit; /* below that point, no more dict */
209  LZ4_u32 nextToUpdate; /* index from which to continue dictionary update */
211  LZ4_i8 favorDecSpeed; /* favor decompression speed if this flag set,
212  otherwise, favor compression ratio */
213  LZ4_i8 dirty; /* stream has to be fully reset if this flag is set */
215 };
216 
217 
218 /* Do not use these definitions directly !
219  * Declare or allocate an LZ4_streamHC_t instead.
220  */
221 #define LZ4_STREAMHCSIZE 262200 /* static size, for inter-version compatibility */
222 #define LZ4_STREAMHCSIZE_VOIDP (LZ4_STREAMHCSIZE / sizeof(void*))
226 }; /* previously typedef'd to LZ4_streamHC_t */
227 
228 /* LZ4_streamHC_t :
229  * This structure allows static allocation of LZ4 HC streaming state.
230  * This can be used to allocate statically, on state, or as part of a larger structure.
231  *
232  * Such state **must** be initialized using LZ4_initStreamHC() before first use.
233  *
234  * Note that invoking LZ4_initStreamHC() is not required when
235  * the state was created using LZ4_createStreamHC() (which is recommended).
236  * Using the normal builder, a newly created state is automatically initialized.
237  *
238  * Static allocation shall only be used in combination with static linking.
239  */
240 
241 /* LZ4_initStreamHC() : v1.9.0+
242  * Required before first use of a statically allocated LZ4_streamHC_t.
243  * Before v1.9.0 : use LZ4_resetStreamHC() instead
244  */
246 
247 
248 /*-************************************
249 * Deprecated Functions
250 **************************************/
251 /* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
252 
253 /* deprecated compression functions */
254 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
255 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
256 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
257 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
258 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
259 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
260 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
261 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
262 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
263 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
264 
265 /* Obsolete streaming functions; degraded functionality; do not use!
266  *
267  * In order to perform streaming compression, these functions depended on data
268  * that is no longer tracked in the state. They have been preserved as well as
269  * possible: using them will still produce a correct output. However, use of
270  * LZ4_slideInputBufferHC() will truncate the history of the stream, rather
271  * than preserve a window-sized chunk of history.
272  */
273 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
274 LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
275 LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
276 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
277 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
278 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int LZ4_sizeofStreamStateHC(void);
279 LZ4_DEPRECATED("use LZ4_initStreamHC() instead") LZ4LIB_API int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
280 
281 
282 /* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
283  * The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
284  * which is now the recommended function to start a new stream of blocks,
285  * but cannot be used to initialize a memory segment containing arbitrary garbage data.
286  *
287  * It is recommended to switch to LZ4_initStreamHC().
288  * LZ4_resetStreamHC() will generate deprecation warnings in a future version.
289  */
290 LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
291 
292 }
293 
294 #endif /* LZ4_HC_H_19834876238432 */
295 
296 
297 /*-**************************************************
298  * !!!!! STATIC LINKING ONLY !!!!!
299  * Following definitions are considered experimental.
300  * They should not be linked from DLL,
301  * as there is no guarantee of API stability yet.
302  * Prototypes will be promoted to "stable" status
303  * after successfull usage in real-life scenarios.
304  ***************************************************/
305 #ifdef LZ4_HC_STATIC_LINKING_ONLY /* protection macro */
306 #ifndef TRACY_LZ4_HC_SLO_098092834
307 #define TRACY_LZ4_HC_SLO_098092834
308 
309 #define LZ4_STATIC_LINKING_ONLY /* LZ4LIB_STATIC_API */
310 #include "tracy_lz4.hpp"
311 
312 namespace tracy
313 {
314 
320 LZ4LIB_STATIC_API void LZ4_setCompressionLevel(
321  LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
322 
327 LZ4LIB_STATIC_API void LZ4_favorDecompressionSpeed(
328  LZ4_streamHC_t* LZ4_streamHCPtr, int favor);
329 
353 LZ4LIB_STATIC_API void LZ4_resetStreamHC_fast(
354  LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
355 
367 LZ4LIB_STATIC_API int LZ4_compress_HC_extStateHC_fastReset (
368  void* state,
369  const char* src, char* dst,
370  int srcSize, int dstCapacity,
371  int compressionLevel);
372 
398 LZ4LIB_STATIC_API void LZ4_attach_HC_dictionary(
399  LZ4_streamHC_t *working_stream,
400  const LZ4_streamHC_t *dictionary_stream);
401 
402 }
403 
404 #endif /* LZ4_HC_SLO_098092834 */
405 #endif /* LZ4_HC_STATIC_LINKING_ONLY */


Copyright © 2005-2022 MAK Technologies. All Rights Reserved (www.mak.com)