Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
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#if defined (__cplusplus)
38extern "C" {
39#endif
40
41/* --- Dependency --- */
42/* note : lz4hc requires lz4.h/lz4.c for compilation */
43#include "lz4.h" /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
44
45
46/* --- Useful constants --- */
47#define LZ4HC_CLEVEL_MIN 2
48#define LZ4HC_CLEVEL_DEFAULT 9
49#define LZ4HC_CLEVEL_OPT_MIN 10
50#define LZ4HC_CLEVEL_MAX 12
51
52
53/*-************************************
54 * Block Compression
55 **************************************/
66LZ4LIB_API int LZ4_compress_HC (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
67
68
69/* Note :
70 * Decompression functions are provided within "lz4.h" (BSD license)
71 */
72
73
80LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
81
82
91LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
92 const char* src, char* dst,
93 int* srcSizePtr, int targetDstSize,
95
96
97/*-************************************
98 * Streaming Compression
99 * Bufferless synchronous API
100 **************************************/
101 typedef union LZ4_streamHC_u LZ4_streamHC_t; /* incomplete type (defined later) */
102
111
112/*
113 These functions compress data in successive blocks of any size,
114 using previous blocks as dictionary, to improve compression ratio.
115 One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
116 There is an exception for ring buffers, which can be smaller than 64 KB.
117 Ring-buffer scenario is automatically detected and handled within LZ4_compress_HC_continue().
118
119 Before starting compression, state must be allocated and properly initialized.
120 LZ4_createStreamHC() does both, though compression level is set to LZ4HC_CLEVEL_DEFAULT.
121
122 Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
123 or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
124 LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
125 which is automatically the case when state is created using LZ4_createStreamHC().
126
127 After reset, a first "fictional block" can be designated as initial dictionary,
128 using LZ4_loadDictHC() (Optional).
129 Note: In order for LZ4_loadDictHC() to create the correct data structure,
130 it is essential to set the compression level _before_ loading the dictionary.
131
132 Invoke LZ4_compress_HC_continue() to compress each successive block.
133 The number of blocks is unlimited.
134 Previous input blocks, including initial dictionary when present,
135 must remain accessible and unmodified during compression.
136
137 It's allowed to update compression level anytime between blocks,
138 using LZ4_setCompressionLevel() (experimental).
139
140 @dst buffer should be sized to handle worst case scenarios
141 (see LZ4_compressBound(), it ensures compression success).
142 In case of failure, the API does not guarantee recovery,
143 so the state _must_ be reset.
144 To ensure compression success
145 whenever @dst buffer size cannot be made >= LZ4_compressBound(),
146 consider using LZ4_compress_HC_continue_destSize().
147
148 Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
149 it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
150 Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
151
152 After completing a streaming compression,
153 it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
154 just by resetting it, using LZ4_resetStreamHC_fast().
155*/
156
157LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel); /* v1.9.0+ */
158LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
159
161 const char* src, char* dst,
162 int srcSize, int maxDstSize);
163
175 const char* src, char* dst,
176 int* srcSizePtr, int targetDstSize);
177
178LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
179
180
205LZ4LIB_API void
207 const LZ4_streamHC_t* dictionary_stream);
208
209
210/*^**********************************************
211 * !!!!!! STATIC LINKING ONLY !!!!!!
212 ***********************************************/
213
214/*-******************************************************************
215 * PRIVATE DEFINITIONS :
216 * Do not use these definitions directly.
217 * They are merely exposed to allow static allocation of `LZ4_streamHC_t`.
218 * Declare an `LZ4_streamHC_t` directly, rather than any type below.
219 * Even then, only do so in the context of static linking, as definitions may change between versions.
220 ********************************************************************/
221
222#define LZ4HC_DICTIONARY_LOGSIZE 16
223#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
224#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
225
226#define LZ4HC_HASH_LOG 15
227#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
228#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
229
230
231/* Never ever use these definitions directly !
232 * Declare or allocate an LZ4_streamHC_t instead.
233**/
236{
239 const LZ4_byte* end; /* next block here to continue on current prefix */
240 const LZ4_byte* prefixStart; /* Indexes relative to this position */
241 const LZ4_byte* dictStart; /* alternate reference for extDict */
242 LZ4_u32 dictLimit; /* below that point, need extDict */
243 LZ4_u32 lowLimit; /* below that point, no more history */
244 LZ4_u32 nextToUpdate; /* index from which to continue dictionary update */
245 short compressionLevel;
246 LZ4_i8 favorDecSpeed; /* favor decompression speed if this flag set,
247 otherwise, favor compression ratio */
248 LZ4_i8 dirty; /* stream has to be fully reset if this flag is set */
250};
251
252#define LZ4_STREAMHC_MINSIZE 262200 /* static size, for inter-version compatibility */
253union LZ4_streamHC_u {
256}; /* previously typedef'd to LZ4_streamHC_t */
257
258/* LZ4_streamHC_t :
259 * This structure allows static allocation of LZ4 HC streaming state.
260 * This can be used to allocate statically on stack, or as part of a larger structure.
261 *
262 * Such state **must** be initialized using LZ4_initStreamHC() before first use.
263 *
264 * Note that invoking LZ4_initStreamHC() is not required when
265 * the state was created using LZ4_createStreamHC() (which is recommended).
266 * Using the normal builder, a newly created state is automatically initialized.
267 *
268 * Static allocation shall only be used in combination with static linking.
269 */
270
271/* LZ4_initStreamHC() : v1.9.0+
272 * Required before first use of a statically allocated LZ4_streamHC_t.
273 * Before v1.9.0 : use LZ4_resetStreamHC() instead
274 */
275LZ4LIB_API LZ4_streamHC_t* LZ4_initStreamHC(void* buffer, size_t size);
276
277
278/*-************************************
279* Deprecated Functions
280**************************************/
281/* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
282
283/* deprecated compression functions */
284LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
294
295/* Obsolete streaming functions; degraded functionality; do not use!
296 *
297 * In order to perform streaming compression, these functions depended on data
298 * that is no longer tracked in the state. They have been preserved as well as
299 * possible: using them will still produce a correct output. However, use of
300 * LZ4_slideInputBufferHC() will truncate the history of the stream, rather
301 * than preserve a window-sized chunk of history.
302 */
303#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
304LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
305LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
306#endif
307LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
308LZ4_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);
312
313
314/* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
315 * The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
316 * which is now the recommended function to start a new stream of blocks,
317 * but cannot be used to initialize a memory segment containing arbitrary garbage data.
318 *
319 * It is recommended to switch to LZ4_initStreamHC().
320 * LZ4_resetStreamHC() will generate deprecation warnings in a future version.
321 */
323
324
325#if defined (__cplusplus)
326}
327#endif
328
329#endif /* LZ4_HC_H_19834876238432 */
330
331
332/*-**************************************************
333 * !!!!! STATIC LINKING ONLY !!!!!
334 * Following definitions are considered experimental.
335 * They should not be linked from DLL,
336 * as there is no guarantee of API stability yet.
337 * Prototypes will be promoted to "stable" status
338 * after successful usage in real-life scenarios.
339 ***************************************************/
340#ifdef LZ4_HC_STATIC_LINKING_ONLY /* protection macro */
341#ifndef LZ4_HC_SLO_098092834
342#define LZ4_HC_SLO_098092834
343
344#define LZ4_STATIC_LINKING_ONLY /* LZ4LIB_STATIC_API */
345#include "lz4.h"
346
347#if defined (__cplusplus)
348extern "C" {
349#endif
350
356LZ4LIB_STATIC_API void LZ4_setCompressionLevel(
357 LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
358
363LZ4LIB_STATIC_API void LZ4_favorDecompressionSpeed(
364 LZ4_streamHC_t* LZ4_streamHCPtr, int favor);
365
389LZ4LIB_STATIC_API void LZ4_resetStreamHC_fast(
390 LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
391
403LZ4LIB_STATIC_API int LZ4_compress_HC_extStateHC_fastReset (
404 void* state,
405 const char* src, char* dst,
406 int srcSize, int dstCapacity,
407 int compressionLevel);
408
409#if defined (__cplusplus)
410}
411#endif
412
413#endif /* LZ4_HC_SLO_098092834 */
414#endif /* LZ4_HC_STATIC_LINKING_ONLY */
#define LZ4LIB_API
Definition lz4.h:97
char * dst
Definition lz4.h:833
char int srcSize
Definition lz4.h:806
const char * src
Definition lz4.h:866
char int int maxDstSize
Definition lz4.h:833
unsigned short LZ4_u16
Definition lz4.h:708
signed char LZ4_i8
Definition lz4.h:706
unsigned char LZ4_byte
Definition lz4.h:707
unsigned int LZ4_u32
Definition lz4.h:709
#define LZ4_DEPRECATED(message)
Definition lz4.h:801
int LZ4_compressHC2_withStateHC(void *state, const char *src, char *dst, int srcSize, int cLevel)
Definition lz4hc.c:2174
void LZ4_favorDecompressionSpeed(LZ4_streamHC_t *LZ4_streamHCPtr, int favor)
Definition lz4hc.c:1640
int LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.c:2177
int LZ4_resetStreamStateHC(void *state, char *inputBuffer)
Definition lz4hc.c:2185
char * LZ4_slideInputBufferHC(void *LZ4HC_Data)
Definition lz4hc.c:2220
int LZ4_freeHC(void *LZ4HC_Data)
Definition lz4hc.c:2202
int LZ4_compressHC2_limitedOutput_continue(void *LZ4HC_Data, const char *src, char *dst, int srcSize, int dstCapacity, int cLevel)
Definition lz4hc.c:2215
int LZ4_compressHC2_continue(void *LZ4HC_Data, const char *src, char *dst, int srcSize, int cLevel)
Definition lz4hc.c:2210
void * LZ4_createHC(const char *inputBuffer)
Definition lz4hc.c:2194
int LZ4_sizeofStreamStateHC(void)
Definition lz4hc.c:2181
int LZ4_compressHC2(const char *src, char *dst, int srcSize, int cLevel)
Definition lz4hc.c:2170
int LZ4_compressHC_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.c:2169
int LZ4_compressHC_withStateHC(void *state, const char *src, char *dst, int srcSize)
Definition lz4hc.c:2172
int LZ4_compressHC_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.c:2173
int LZ4_compressHC2_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
Definition lz4hc.c:2175
int LZ4_compress_HC_extStateHC_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition lz4hc.c:1521
void LZ4_setCompressionLevel(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
Definition lz4hc.c:1632
int LZ4_compressHC_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize)
Definition lz4hc.c:2176
int LZ4_compressHC2_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
Definition lz4hc.c:2171
int LZ4_compressHC(const char *src, char *dst, int srcSize)
Definition lz4hc.c:2168
char * dest
Definition lz4hc.h:284
char int int maxOutputSize
Definition lz4hc.h:285
LZ4LIB_API int LZ4_sizeofStateHC(void)
Definition lz4hc.c:1507
LZ4LIB_API int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition lz4hc.c:1752
LZ4LIB_API int LZ4_loadDictHC(LZ4_streamHC_t *streamHCPtr, const char *dictionary, int dictSize)
Definition lz4hc.c:1647
char * inputBuffer
Definition lz4hc.h:311
char int inputSize
Definition lz4hc.h:284
LZ4LIB_API int LZ4_compress_HC_continue(LZ4_streamHC_t *streamHCPtr, const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.c:1743
LZ4LIB_API LZ4_streamHC_t * LZ4_createStreamHC(void)
Definition lz4hc.c:1575
LZ4LIB_API int LZ4_saveDictHC(LZ4_streamHC_t *streamHCPtr, char *safeBuffer, int maxDictSize)
Definition lz4hc.c:1763
LZ4LIB_API int LZ4_freeStreamHC(LZ4_streamHC_t *streamHCPtr)
Definition lz4hc.c:1584
LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t *streamHCPtr, int compressionLevel)
Definition lz4hc.c:1616
LZ4LIB_API int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition lz4hc.c:1540
LZ4LIB_API int LZ4_compress_HC_destSize(void *stateHC, const char *src, char *dst, int *srcSizePtr, int targetDstSize, int compressionLevel)
Definition lz4hc.c:1559
LZ4LIB_API void LZ4_resetStreamHC(LZ4_streamHC_t *streamHCPtr, int compressionLevel)
Definition lz4hc.c:1610
char int int compressionLevel
Definition lz4hc.h:286
LZ4LIB_API LZ4_streamHC_t * LZ4_initStreamHC(void *buffer, size_t size)
Definition lz4hc.c:1594
const char * source
Definition lz4hc.h:288
LZ4LIB_API int LZ4_compress_HC_extStateHC(void *stateHC, const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
Definition lz4hc.c:1533
LZ4LIB_API void LZ4_attach_HC_dictionary(LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream)
Definition lz4hc.c:1675
#define LZ4_STREAMHC_MINSIZE
Definition lz4hc.h:252
#define LZ4HC_MAXD
Definition lz4hc.h:223
#define LZ4HC_HASHTABLESIZE
Definition lz4hc.h:227
Definition lz4hc.h:236
LZ4_i8 dirty
Definition lz4hc.h:248
LZ4_u32 hashTable[LZ4HC_HASHTABLESIZE]
Definition lz4hc.h:237
LZ4_i8 favorDecSpeed
Definition lz4hc.h:246
const LZ4HC_CCtx_internal * dictCtx
Definition lz4hc.h:249
const LZ4_byte * dictStart
Definition lz4hc.h:241
LZ4_u16 chainTable[LZ4HC_MAXD]
Definition lz4hc.h:238
LZ4_u32 nextToUpdate
Definition lz4hc.h:244
LZ4_u32 dictLimit
Definition lz4hc.h:242
LZ4_u32 lowLimit
Definition lz4hc.h:243
short compressionLevel
Definition lz4hc.h:245
const LZ4_byte * prefixStart
Definition lz4hc.h:240
const LZ4_byte * end
Definition lz4hc.h:239
Definition zstd_decompress.c:306
Definition lz4hc.h:253
LZ4HC_CCtx_internal internal_donotuse
Definition lz4hc.h:255
char minStateSize[LZ4_STREAMHC_MINSIZE]
Definition lz4hc.h:254
size_t size
Definition platform.h:559
#define const
Definition zconf.h:230
const void size_t dictSize
Definition zbuff.h:76
void size_t const void size_t * srcSizePtr
Definition zbuff.h:78