UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
lz4hc.h
Go to the documentation of this file.
1/*
2 LZ4 HC - High Compression Mode of LZ4
3 Header File
4 Copyright (C) 2011-2020, 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 LZ4_HC_H_19834876238432
35#define LZ4_HC_H_19834876238432
36
37// HEADER_UNIT_SKIP - Not compatible
38
39/* note : lz4hc requires lz4.h/lz4.c for compilation */
40#include "lz4.h" /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
41
42#if defined (__cplusplus)
43extern "C" {
44#endif
45
46/* --- Dependency --- */
47
48
49/* --- Useful constants --- */
50#define LZ4HC_CLEVEL_MIN 3
51#define LZ4HC_CLEVEL_DEFAULT 9
52#define LZ4HC_CLEVEL_OPT_MIN 10
53#define LZ4HC_CLEVEL_MAX 12
54
55
56/*-************************************
57 * Block Compression
58 **************************************/
69LZ4LIB_API int LZ4_compress_HC (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
70
71
72/* Note :
73 * Decompression functions are provided within "lz4.h" (BSD license)
74 */
75
76
83LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
84
85
95 const char* src, char* dst,
96 int* srcSizePtr, int targetDstSize,
97 int compressionLevel);
98
99
100/*-************************************
101 * Streaming Compression
102 * Bufferless synchronous API
103 **************************************/
104 typedef union LZ4_streamHC_u LZ4_streamHC_t; /* incomplete type (defined later) */
105
114
115/*
116 These functions compress data in successive blocks of any size,
117 using previous blocks as dictionary, to improve compression ratio.
118 One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
119 There is an exception for ring buffers, which can be smaller than 64 KB.
120 Ring-buffer scenario is automatically detected and handled within LZ4_compress_HC_continue().
121
122 Before starting compression, state must be allocated and properly initialized.
123 LZ4_createStreamHC() does both, though compression level is set to LZ4HC_CLEVEL_DEFAULT.
124
125 Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
126 or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
127 LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
128 which is automatically the case when state is created using LZ4_createStreamHC().
129
130 After reset, a first "fictional block" can be designated as initial dictionary,
131 using LZ4_loadDictHC() (Optional).
132
133 Invoke LZ4_compress_HC_continue() to compress each successive block.
134 The number of blocks is unlimited.
135 Previous input blocks, including initial dictionary when present,
136 must remain accessible and unmodified during compression.
137
138 It's allowed to update compression level anytime between blocks,
139 using LZ4_setCompressionLevel() (experimental).
140
141 'dst' buffer should be sized to handle worst case scenarios
142 (see LZ4_compressBound(), it ensures compression success).
143 In case of failure, the API does not guarantee recovery,
144 so the state _must_ be reset.
145 To ensure compression success
146 whenever `dst` buffer size cannot be made >= LZ4_compressBound(),
147 consider using LZ4_compress_HC_continue_destSize().
148
149 Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
150 it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
151 Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
152
153 After completing a streaming compression,
154 it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
155 just by resetting it, using LZ4_resetStreamHC_fast().
156*/
157
158LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel); /* v1.9.0+ */
159LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
160
162 const char* src, char* dst,
163 int srcSize, int maxDstSize);
164
176 const char* src, char* dst,
177 int* srcSizePtr, int targetDstSize);
178
180
181
182
183/*^**********************************************
184 * !!!!!! STATIC LINKING ONLY !!!!!!
185 ***********************************************/
186
187/*-******************************************************************
188 * PRIVATE DEFINITIONS :
189 * Do not use these definitions directly.
190 * They are merely exposed to allow static allocation of `LZ4_streamHC_t`.
191 * Declare an `LZ4_streamHC_t` directly, rather than any type below.
192 * Even then, only do so in the context of static linking, as definitions may change between versions.
193 ********************************************************************/
194
195#define LZ4HC_DICTIONARY_LOGSIZE 16
196#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
197#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
198
199#define LZ4HC_HASH_LOG 15
200#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
201#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
202
203
204/* Never ever use these definitions directly !
205 * Declare or allocate an LZ4_streamHC_t instead.
206**/
209{
212 const LZ4_byte* end; /* next block here to continue on current prefix */
213 const LZ4_byte* prefixStart; /* Indexes relative to this position */
214 const LZ4_byte* dictStart; /* alternate reference for extDict */
215 LZ4_u32 dictLimit; /* below that point, need extDict */
216 LZ4_u32 lowLimit; /* below that point, no more dict */
217 LZ4_u32 nextToUpdate; /* index from which to continue dictionary update */
219 LZ4_i8 favorDecSpeed; /* favor decompression speed if this flag set,
220 otherwise, favor compression ratio */
221 LZ4_i8 dirty; /* stream has to be fully reset if this flag is set */
223};
224
225#define LZ4_STREAMHC_MINSIZE 262200 /* static size, for inter-version compatibility */
229}; /* previously typedef'd to LZ4_streamHC_t */
230
231/* LZ4_streamHC_t :
232 * This structure allows static allocation of LZ4 HC streaming state.
233 * This can be used to allocate statically on stack, or as part of a larger structure.
234 *
235 * Such state **must** be initialized using LZ4_initStreamHC() before first use.
236 *
237 * Note that invoking LZ4_initStreamHC() is not required when
238 * the state was created using LZ4_createStreamHC() (which is recommended).
239 * Using the normal builder, a newly created state is automatically initialized.
240 *
241 * Static allocation shall only be used in combination with static linking.
242 */
243
244/* LZ4_initStreamHC() : v1.9.0+
245 * Required before first use of a statically allocated LZ4_streamHC_t.
246 * Before v1.9.0 : use LZ4_resetStreamHC() instead
247 */
248LZ4LIB_API LZ4_streamHC_t* LZ4_initStreamHC(void* buffer, size_t size);
249
250/* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
251 * The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
252 * which is now the recommended function to start a new stream of blocks,
253 * but cannot be used to initialize a memory segment containing arbitrary garbage data.
254 *
255 * It is recommended to switch to LZ4_initStreamHC().
256 * LZ4_resetStreamHC() will generate deprecation warnings in a future version.
257 */
258LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
259
260
261#if defined (__cplusplus)
262}
263#endif
264
265#endif /* LZ4_HC_H_19834876238432 */
266
267
268/*-**************************************************
269 * !!!!! STATIC LINKING ONLY !!!!!
270 * Following definitions are considered experimental.
271 * They should not be linked from DLL,
272 * as there is no guarantee of API stability yet.
273 * Prototypes will be promoted to "stable" status
274 * after successful usage in real-life scenarios.
275 ***************************************************/
276#ifdef LZ4_HC_STATIC_LINKING_ONLY /* protection macro */
277#ifndef LZ4_HC_SLO_098092834
278#define LZ4_HC_SLO_098092834
279
280#define LZ4_STATIC_LINKING_ONLY /* LZ4LIB_STATIC_API */
281#include "lz4.h"
282
283#if defined (__cplusplus)
284extern "C" {
285#endif
286
293 LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
294
301
326 LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
327
340 void* state,
341 const char* src, char* dst,
342 int srcSize, int dstCapacity,
343 int compressionLevel);
344
373
374#if defined (__cplusplus)
375}
376#endif
377
378#endif /* LZ4_HC_SLO_098092834 */
379#endif /* LZ4_HC_STATIC_LINKING_ONLY */
#define LZ4LIB_API
Definition lz4.h:84
unsigned short LZ4_u16
Definition lz4.h:652
signed char LZ4_i8
Definition lz4.h:650
unsigned char LZ4_byte
Definition lz4.h:651
unsigned int LZ4_u32
Definition lz4.h:653
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
char int srcSize
Definition lz4.h:709
char int int maxDstSize
Definition lz4.h:735
char * dst
Definition lz4.h:735
void LZ4_favorDecompressionSpeed(LZ4_streamHC_t *LZ4_streamHCPtr, int favor)
Definition lz4hc.cpp:1069
void LZ4_attach_HC_dictionary(LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream)
Definition lz4hc.cpp:1097
int LZ4_compress_HC_extStateHC_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition lz4hc.cpp:949
void LZ4_setCompressionLevel(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
Definition lz4hc.cpp:1061
#define LZ4_STREAMHC_MINSIZE
Definition lz4hc.h:225
LZ4LIB_API int LZ4_sizeofStateHC(void)
Definition lz4hc.cpp:935
LZ4LIB_API int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition lz4hc.cpp:1169
#define LZ4HC_MAXD
Definition lz4hc.h:196
LZ4LIB_API int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary, int dictSize)
Definition lz4hc.cpp:1076
#define LZ4HC_HASHTABLESIZE
Definition lz4hc.h:200
LZ4LIB_API int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.cpp:1161
LZ4LIB_API LZ4_streamHC_t * LZ4_createStreamHC(void)
Definition lz4hc.cpp:1002
LZ4LIB_API int LZ4_saveDictHC(LZ4_streamHC_t *streamHCPtr, char *safeBuffer, int maxDictSize)
Definition lz4hc.cpp:1181
LZ4LIB_API int LZ4_freeStreamHC(LZ4_streamHC_t *streamHCPtr)
Definition lz4hc.cpp:1011
LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t *streamHCPtr, int compressionLevel)
Definition lz4hc.cpp:1043
LZ4LIB_API int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition lz4hc.cpp:968
LZ4LIB_API int LZ4_compress_HC_destSize(void *stateHC, const char *src, char *dst, int *srcSizePtr, int targetDstSize, int compressionLevel)
Definition lz4hc.cpp:986
LZ4LIB_API void LZ4_resetStreamHC(LZ4_streamHC_t *streamHCPtr, int compressionLevel)
Definition lz4hc.cpp:1037
LZ4LIB_API LZ4_streamHC_t * LZ4_initStreamHC(void *buffer, size_t size)
Definition lz4hc.cpp:1021
LZ4LIB_API int LZ4_compress_HC_extStateHC(void *stateHC, const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
Definition lz4hc.cpp:961
Definition lz4hc.h:209
LZ4_u32 dictLimit
Definition lz4hc.h:215
const LZ4_byte * prefixStart
Definition lz4hc.h:213
const LZ4HC_CCtx_internal * dictCtx
Definition lz4hc.h:222
LZ4_u32 nextToUpdate
Definition lz4hc.h:217
LZ4_i8 dirty
Definition lz4hc.h:221
short compressionLevel
Definition lz4hc.h:218
const LZ4_byte * end
Definition lz4hc.h:212
const LZ4_byte * dictStart
Definition lz4hc.h:214
LZ4_i8 favorDecSpeed
Definition lz4hc.h:219
LZ4_u32 hashTable[LZ4HC_HASHTABLESIZE]
Definition lz4hc.h:210
LZ4_u32 lowLimit
Definition lz4hc.h:216
LZ4_u16 chainTable[LZ4HC_MAXD]
Definition lz4hc.h:211
Definition lz4hc.h:226
LZ4HC_CCtx_internal internal_donotuse
Definition lz4hc.h:228
char minStateSize[LZ4_STREAMHC_MINSIZE]
Definition lz4hc.h:227