VR-Vantage 2.8 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 namespace tracy
42 {
43 
44 /* --- Useful constants --- */
45 #define LZ4HC_CLEVEL_MIN 3
46 #define LZ4HC_CLEVEL_DEFAULT 9
47 #define LZ4HC_CLEVEL_OPT_MIN 10
48 #define LZ4HC_CLEVEL_MAX 12
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 
199 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
200 #include <stdint.h>
201 
203 struct LZ4HC_CCtx_internal
204 {
207  const uint8_t* end; /* next block here to continue on current prefix */
208  const uint8_t* base; /* All index relative to this position */
209  const uint8_t* dictBase; /* alternate base for extDict */
210  uint32_t dictLimit; /* below that point, need extDict */
211  uint32_t lowLimit; /* below that point, no more dict */
212  uint32_t nextToUpdate; /* index from which to continue dictionary update */
213  short compressionLevel;
214  int8_t favorDecSpeed; /* favor decompression speed if this flag set,
215  otherwise, favor compression ratio */
216  int8_t dirty; /* stream has to be fully reset if this flag is set */
218 };
219 
220 #else
221 
224 {
226  unsigned short chainTable[LZ4HC_MAXD];
227  const unsigned char* end; /* next block here to continue on current prefix */
228  const unsigned char* base; /* All index relative to this position */
229  const unsigned char* dictBase; /* alternate base for extDict */
230  unsigned int dictLimit; /* below that point, need extDict */
231  unsigned int lowLimit; /* below that point, no more dict */
232  unsigned int nextToUpdate; /* index from which to continue dictionary update */
234  char favorDecSpeed; /* favor decompression speed if this flag set,
235  otherwise, favor compression ratio */
236  char dirty; /* stream has to be fully reset if this flag is set */
238 };
239 
240 #endif
241 
242 
243 /* Do not use these definitions directly !
244  * Declare or allocate an LZ4_streamHC_t instead.
245  */
246 #define LZ4_STREAMHCSIZE (4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 56 + ((sizeof(void*)==16) ? 56 : 0) /* AS400*/ ) /* 262200 or 262256*/
247 #define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
251 }; /* previously typedef'd to LZ4_streamHC_t */
252 
253 /* LZ4_streamHC_t :
254  * This structure allows static allocation of LZ4 HC streaming state.
255  * This can be used to allocate statically, on state, or as part of a larger structure.
256  *
257  * Such state **must** be initialized using LZ4_initStreamHC() before first use.
258  *
259  * Note that invoking LZ4_initStreamHC() is not required when
260  * the state was created using LZ4_createStreamHC() (which is recommended).
261  * Using the normal builder, a newly created state is automatically initialized.
262  *
263  * Static allocation shall only be used in combination with static linking.
264  */
265 
266 /* LZ4_initStreamHC() : v1.9.0+
267  * Required before first use of a statically allocated LZ4_streamHC_t.
268  * Before v1.9.0 : use LZ4_resetStreamHC() instead
269  */
271 
272 
273 /*-************************************
274 * Deprecated Functions
275 **************************************/
276 /* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
277 
278 /* deprecated compression functions */
279 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
280 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
281 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
282 LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
283 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
284 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);
285 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);
286 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);
287 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);
288 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);
289 
290 /* Obsolete streaming functions; degraded functionality; do not use!
291  *
292  * In order to perform streaming compression, these functions depended on data
293  * that is no longer tracked in the state. They have been preserved as well as
294  * possible: using them will still produce a correct output. However, use of
295  * LZ4_slideInputBufferHC() will truncate the history of the stream, rather
296  * than preserve a window-sized chunk of history.
297  */
298 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
299 LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
300 LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
301 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);
302 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);
303 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int LZ4_sizeofStreamStateHC(void);
304 LZ4_DEPRECATED("use LZ4_initStreamHC() instead") LZ4LIB_API int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
305 
306 
307 /* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
308  * The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
309  * which is now the recommended function to start a new stream of blocks,
310  * but cannot be used to initialize a memory segment containing arbitrary garbage data.
311  *
312  * It is recommended to switch to LZ4_initStreamHC().
313  * LZ4_resetStreamHC() will generate deprecation warnings in a future version.
314  */
315 LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
316 
317 
318 }
319 
320 #endif /* LZ4_HC_H_19834876238432 */
321 
322 
323 /*-**************************************************
324  * !!!!! STATIC LINKING ONLY !!!!!
325  * Following definitions are considered experimental.
326  * They should not be linked from DLL,
327  * as there is no guarantee of API stability yet.
328  * Prototypes will be promoted to "stable" status
329  * after successfull usage in real-life scenarios.
330  ***************************************************/
331 #ifdef LZ4_HC_STATIC_LINKING_ONLY /* protection macro */
332 #ifndef LZ4_HC_SLO_098092834
333 #define LZ4_HC_SLO_098092834
334 
335 namespace tracy
336 {
337 
343 LZ4LIB_STATIC_API void LZ4_setCompressionLevel(
344  LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
345 
350 LZ4LIB_STATIC_API void LZ4_favorDecompressionSpeed(
351  LZ4_streamHC_t* LZ4_streamHCPtr, int favor);
352 
377  LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
378 
390 LZ4LIB_STATIC_API int LZ4_compress_HC_extStateHC_fastReset (
391  void* state,
392  const char* src, char* dst,
393  int srcSize, int dstCapacity,
394  int compressionLevel);
395 
421 LZ4LIB_STATIC_API void LZ4_attach_HC_dictionary(
422  LZ4_streamHC_t *working_stream,
423  const LZ4_streamHC_t *dictionary_stream);
424 
425 }
426 
427 #endif /* LZ4_HC_SLO_098092834 */
428 #endif /* LZ4_HC_STATIC_LINKING_ONLY */


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