GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
lz4.h
Go to the documentation of this file.
1 /*
2  * LZ4 - Fast LZ compression algorithm
3  * Header File
4  * Copyright (C) 2011-2017, Yann Collet.
5 
6  BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are
10  met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above
15  copyright notice, this list of conditions and the following disclaimer
16  in the documentation and/or other materials provided with the
17  distribution.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31  You can contact the author at :
32  - LZ4 homepage : http://www.lz4.org
33  - LZ4 source repository : https://github.com/lz4/lz4
34 */
35 #if defined (__cplusplus)
36 extern "C" {
37 #endif
38 
39 #ifndef LZ4_H_2983827168210
40 #define LZ4_H_2983827168210
41 
42 /* --- Dependency --- */
43 #include <stddef.h> /* size_t */
44 
45 
46 /**
47  Introduction
48 
49  LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core,
50  scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
51  multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
52 
53  The LZ4 compression library provides in-memory compression and decompression functions.
54  Compression can be done in:
55  - a single step (described as Simple Functions)
56  - a single step, reusing a context (described in Advanced Functions)
57  - unbounded multiple steps (described as Streaming compression)
58 
59  lz4.h provides block compression functions. It gives full buffer control to user.
60  Decompressing an lz4-compressed block also requires metadata (such as compressed size).
61  Each application is free to encode such metadata in whichever way it wants.
62 
63  An additional format, called LZ4 frame specification (doc/lz4_Frame_format.md),
64  take care of encoding standard metadata alongside LZ4-compressed blocks.
65  If your application requires interoperability, it's recommended to use it.
66  A library is provided to take care of it, see lz4frame.h.
67 */
68 
69 /*^***************************************************************
70 * Export parameters
71 *****************************************************************/
72 /*
73 * LZ4_DLL_EXPORT :
74 * Enable exporting of functions when building a Windows DLL
75 * LZ4LIB_VISIBILITY :
76 * Control library symbols visibility.
77 */
78 #ifndef LZ4LIB_VISIBILITY
79 # if defined(__GNUC__) && (__GNUC__ >= 4)
80 # define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
81 # else
82 # define LZ4LIB_VISIBILITY
83 # endif
84 #endif
85 #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
86 # define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
87 #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
88 # define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows generating better code, saving a function pointer load from the IAT and an indirect jump.*/
89 #else
90 # define LZ4LIB_API LZ4LIB_VISIBILITY
91 #endif
92 
93 /*------ Version ------*/
94 #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
95 #define LZ4_VERSION_MINOR 8 /* for new (non-breaking) interface capabilities */
96 #define LZ4_VERSION_RELEASE 2 /* for tweaks, bug-fixes, or development */
97 
98 #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
99 
100 #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
101 #define LZ4_QUOTE(str) #str
102 #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
103 #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
104 
105 LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version */
106 LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; unseful to check dll version */
107 
108 
109 /*-************************************
110 * Tuning parameter
111 **************************************/
112 /*!
113  * LZ4_MEMORY_USAGE :
114  * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
115  * Increasing memory usage improves compression ratio
116  * Reduced memory usage may improve speed, thanks to cache effect
117  * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
118  */
119 #ifndef LZ4_MEMORY_USAGE
120 # define LZ4_MEMORY_USAGE 14
121 #endif
122 
123 /*-************************************
124 * Simple Functions
125 **************************************/
126 /*! LZ4_compress_default() :
127  Compresses 'srcSize' bytes from buffer 'src'
128  into already allocated 'dst' buffer of size 'dstCapacity'.
129  Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
130  It also runs faster, so it's a recommended setting.
131  If the function cannot compress 'src' into a more limited 'dst' budget,
132  compression stops *immediately*, and the function result is zero.
133  Note : as a consequence, 'dst' content is not valid.
134  Note 2 : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
135  srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
136  dstCapacity : size of buffer 'dst' (which must be already allocated)
137  return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
138  or 0 if compression fails */
139 LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
140 
141 /*! LZ4_decompress_safe() :
142  compressedSize : is the exact complete size of the compressed block.
143  dstCapacity : is the size of destination buffer, which must be already allocated.
144  return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
145  If destination buffer is not large enough, decoding will stop and output an error code (negative value).
146  If the source stream is detected malformed, the function will stop decoding and return a negative result.
147  This function is protected against malicious data packets.
148 */
149 LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
150 
151 
152 /*-************************************
153 * Advanced Functions
154 **************************************/
155 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
156 #define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
157 
158 /*!
159 LZ4_compressBound() :
160  Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
161  This function is primarily useful for memory allocation purposes (destination buffer size).
162  Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
163  Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
164  inputSize : max supported value is LZ4_MAX_INPUT_SIZE
165  return : maximum output size in a "worst case" scenario
166  or 0, if input size is incorrect (too large or negative)
167 */
169 
170 /*!
171 LZ4_compress_fast() :
172  Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
173  The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
174  It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
175  An acceleration value of "1" is the same as regular LZ4_compress_default()
176  Values <= 0 will be replaced by ACCELERATION_DEFAULT (currently == 1, see lz4.c).
177 */
178 LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
179 
180 
181 /*!
182 LZ4_compress_fast_extState() :
183  Same compression function, just using an externally allocated memory space to store compression state.
184  Use LZ4_sizeofState() to know how much memory must be allocated,
185  and allocate it on 8-bytes boundaries (using malloc() typically).
186  Then, provide it as 'void* state' to compression function.
187 */
188 LZ4LIB_API int LZ4_sizeofState(void);
189 LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
190 
191 
192 /*!
193 LZ4_compress_destSize() :
194  Reverse the logic : compresses as much data as possible from 'src' buffer
195  into already allocated buffer 'dst' of size 'targetDestSize'.
196  This function either compresses the entire 'src' content into 'dst' if it's large enough,
197  or fill 'dst' buffer completely with as much data as possible from 'src'.
198  *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
199  New value is necessarily <= old value.
200  return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
201  or 0 if compression fails
202 */
203 LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
204 
205 
206 /*!
207 LZ4_decompress_fast() : **unsafe!**
208 This function is a bit faster than LZ4_decompress_safe(),
209 but it may misbehave on malformed input because it doesn't perform full validation of compressed data.
210  originalSize : is the uncompressed size to regenerate
211  Destination buffer must be already allocated, and its size must be >= 'originalSize' bytes.
212  return : number of bytes read from source buffer (== compressed size).
213  If the source stream is detected malformed, the function stops decoding and return a negative result.
214  note : This function is only usable if the originalSize of uncompressed data is known in advance.
215  The caller should also check that all the compressed input has been consumed properly,
216  i.e. that the return value matches the size of the buffer with compressed input.
217  The function never writes past the output buffer. However, since it doesn't know its 'src' size,
218  it may read past the intended input. Also, because match offsets are not validated during decoding,
219  reads from 'src' may underflow. Use this function in trusted environment **only**.
220 */
221 LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
222 
223 /*!
224 LZ4_decompress_safe_partial() :
225  This function decompress a compressed block of size 'srcSize' at position 'src'
226  into destination buffer 'dst' of size 'dstCapacity'.
227  The function will decompress a minimum of 'targetOutputSize' bytes, and stop after that.
228  However, it's not accurate, and may write more than 'targetOutputSize' (but always <= dstCapacity).
229  @return : the number of bytes decoded in the destination buffer (necessarily <= dstCapacity)
230  Note : this number can also be < targetOutputSize, if compressed block contains less data.
231  Therefore, always control how many bytes were decoded.
232  If source stream is detected malformed, function returns a negative result.
233  This function is protected against malicious data packets.
234 */
235 LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
236 
237 
238 /*-*********************************************
239 * Streaming Compression Functions
240 ***********************************************/
241 typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
242 
243 /*! LZ4_createStream() and LZ4_freeStream() :
244  * LZ4_createStream() will allocate and initialize an `LZ4_stream_t` structure.
245  * LZ4_freeStream() releases its memory.
246  */
248 LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
249 
250 /*! LZ4_resetStream() :
251  * An LZ4_stream_t structure can be allocated once and re-used multiple times.
252  * Use this function to start compressing a new stream.
253  */
254 LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
255 
256 /*! LZ4_loadDict() :
257  * Use this function to load a static dictionary into LZ4_stream_t.
258  * Any previous data will be forgotten, only 'dictionary' will remain in memory.
259  * Loading a size of 0 is allowed, and is the same as reset.
260  * @return : dictionary size, in bytes (necessarily <= 64 KB)
261  */
262 LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
263 
264 /*! LZ4_compress_fast_continue() :
265  * Compress 'src' content using data from previously compressed blocks, for better compression ratio.
266  * 'dst' buffer must be already allocated.
267  * If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
268  *
269  * Important : The previous 64KB of compressed data is assumed to remain present and unmodified in memory!
270  *
271  * Special 1 : When input is a double-buffer, they can have any size, including < 64 KB.
272  * Make sure that buffers are separated by at least one byte.
273  * This way, each block only depends on previous block.
274  * Special 2 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
275  *
276  * @return : size of compressed block
277  * or 0 if there is an error (typically, cannot fit into 'dst').
278  * After an error, the stream status is invalid, it can only be reset or freed.
279  */
280 LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
281 
282 /*! LZ4_saveDict() :
283  * If last 64KB data cannot be guaranteed to remain available at its current memory location,
284  * save it into a safer place (char* safeBuffer).
285  * This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
286  * but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
287  * @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
288  */
289 LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
290 
291 
292 /*-**********************************************
293 * Streaming Decompression Functions
294 * Bufferless synchronous API
295 ************************************************/
296 typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
297 
298 /*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
299  * creation / destruction of streaming decompression tracking context.
300  * A tracking context can be re-used multiple times.
301  */
304 
305 /*! LZ4_setStreamDecode() :
306  * An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
307  * Use this function to start decompression of a new stream of blocks.
308  * A dictionary can optionnally be set. Use NULL or size 0 for a reset order.
309  * Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
310  * @return : 1 if OK, 0 if error
311  */
312 LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
313 
314 /*! LZ4_decoderRingBufferSize() : v1.8.2
315  * Note : in a ring buffer scenario (optional),
316  * blocks are presumed decompressed next to each other
317  * up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
318  * at which stage it resumes from beginning of ring buffer.
319  * When setting such a ring buffer for streaming decompression,
320  * provides the minimum size of this ring buffer
321  * to be compatible with any source respecting maxBlockSize condition.
322  * @return : minimum ring buffer size,
323  * or 0 if there is an error (invalid maxBlockSize).
324  */
325 LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
326 #define LZ4_DECODER_RING_BUFFER_SIZE(mbs) (65536 + 14 + (mbs)) /* for static allocation; mbs presumed valid */
327 
328 /*! LZ4_decompress_*_continue() :
329  * These decoding functions allow decompression of consecutive blocks in "streaming" mode.
330  * A block is an unsplittable entity, it must be presented entirely to a decompression function.
331  * Decompression functions only accepts one block at a time.
332  * The last 64KB of previously decoded data *must* remain available and unmodified at the memory position where they were decoded.
333  * If less than 64KB of data has been decoded, all the data must be present.
334  *
335  * Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
336  * - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
337  * maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
338  * In which case, encoding and decoding buffers do not need to be synchronized.
339  * Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
340  * - Synchronized mode :
341  * Decompression buffer size is _exactly_ the same as compression buffer size,
342  * and follows exactly same update rule (block boundaries at same positions),
343  * and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
344  * _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
345  * - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
346  * In which case, encoding and decoding buffers do not need to be synchronized,
347  * and encoding ring buffer can have any size, including small ones ( < 64 KB).
348  *
349  * Whenever these conditions are not possible,
350  * save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
351  * then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
352 */
353 LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
354 LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
355 
356 
357 /*! LZ4_decompress_*_usingDict() :
358  * These decoding functions work the same as
359  * a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue()
360  * They are stand-alone, and don't need an LZ4_streamDecode_t structure.
361  * Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
362  */
363 LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
364 LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
365 
366 
367 /*^**********************************************
368  * !!!!!! STATIC LINKING ONLY !!!!!!
369  ***********************************************/
370 
371 /*-************************************
372  * Unstable declarations
373  **************************************
374  * Declarations in this section should be considered unstable.
375  * Use at your own peril, etc., etc.
376  * They may be removed in the future.
377  * Their signatures may change.
378  **************************************/
379 
380 #ifdef LZ4_STATIC_LINKING_ONLY
381 
382 /*! LZ4_resetStream_fast() :
383  * Use this, like LZ4_resetStream(), to prepare a context for a new chain of
384  * calls to a streaming API (e.g., LZ4_compress_fast_continue()).
385  *
386  * Note:
387  * Using this in advance of a non- streaming-compression function is redundant,
388  * and potentially bad for performance, since they all perform their own custom
389  * reset internally.
390  *
391  * Differences from LZ4_resetStream():
392  * When an LZ4_stream_t is known to be in a internally coherent state,
393  * it can often be prepared for a new compression with almost no work, only
394  * sometimes falling back to the full, expensive reset that is always required
395  * when the stream is in an indeterminate state (i.e., the reset performed by
396  * LZ4_resetStream()).
397  *
398  * LZ4_streams are guaranteed to be in a valid state when:
399  * - returned from LZ4_createStream()
400  * - reset by LZ4_resetStream()
401  * - memset(stream, 0, sizeof(LZ4_stream_t)), though this is discouraged
402  * - the stream was in a valid state and was reset by LZ4_resetStream_fast()
403  * - the stream was in a valid state and was then used in any compression call
404  * that returned success
405  * - the stream was in an indeterminate state and was used in a compression
406  * call that fully reset the state (e.g., LZ4_compress_fast_extState()) and
407  * that returned success
408  *
409  * When a stream isn't known to be in a valid state, it is not safe to pass to
410  * any fastReset or streaming function. It must first be cleansed by the full
411  * LZ4_resetStream().
412  */
414 
415 /*! LZ4_compress_fast_extState_fastReset() :
416  * A variant of LZ4_compress_fast_extState().
417  *
418  * Using this variant avoids an expensive initialization step. It is only safe
419  * to call if the state buffer is known to be correctly initialized already
420  * (see above comment on LZ4_resetStream_fast() for a definition of "correctly
421  * initialized"). From a high level, the difference is that this function
422  * initializes the provided state with a call to something like
423  * LZ4_resetStream_fast() while LZ4_compress_fast_extState() starts with a
424  * call to LZ4_resetStream().
425  */
426 LZ4LIB_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
427 
428 /*! LZ4_attach_dictionary() :
429  * This is an experimental API that allows for the efficient use of a
430  * static dictionary many times.
431  *
432  * Rather than re-loading the dictionary buffer into a working context before
433  * each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
434  * working LZ4_stream_t, this function introduces a no-copy setup mechanism,
435  * in which the working stream references the dictionary stream in-place.
436  *
437  * Several assumptions are made about the state of the dictionary stream.
438  * Currently, only streams which have been prepared by LZ4_loadDict() should
439  * be expected to work.
440  *
441  * Alternatively, the provided dictionary stream pointer may be NULL, in which
442  * case any existing dictionary stream is unset.
443  *
444  * If a dictionary is provided, it replaces any pre-existing stream history.
445  * The dictionary contents are the only history that can be referenced and
446  * logically immediately precede the data compressed in the first subsequent
447  * compression call.
448  *
449  * The dictionary will only remain attached to the working stream through the
450  * first compression call, at the end of which it is cleared. The dictionary
451  * stream (and source buffer) must remain in-place / accessible / unchanged
452  * through the completion of the first compression call on the stream.
453  */
454 LZ4LIB_API void LZ4_attach_dictionary(LZ4_stream_t *working_stream, const LZ4_stream_t *dictionary_stream);
455 
456 #endif
457 
458 /*-************************************
459  * Private definitions
460  **************************************
461  * Do not use these definitions.
462  * They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
463  * Using these definitions will expose code to API and/or ABI break in future versions of the library.
464  **************************************/
465 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
466 #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
467 #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
468 
469 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
470 #include <stdint.h>
471 
473 struct LZ4_stream_t_internal {
474  uint32_t hashTable[LZ4_HASH_SIZE_U32];
475  uint32_t currentOffset;
476  uint16_t initCheck;
477  uint16_t tableType;
478  const uint8_t* dictionary;
480  uint32_t dictSize;
481 };
482 
483 typedef struct {
484  const uint8_t* externalDict;
485  size_t extDictSize;
486  const uint8_t* prefixEnd;
487  size_t prefixSize;
489 
490 #else
491 
495  unsigned int currentOffset;
496  unsigned short initCheck;
497  unsigned short tableType;
498  const unsigned char* dictionary;
500  unsigned int dictSize;
501 };
502 
503 typedef struct {
504  const unsigned char* externalDict;
505  size_t extDictSize;
506  const unsigned char* prefixEnd;
507  size_t prefixSize;
509 
510 #endif
511 
512 /*!
513  * LZ4_stream_t :
514  * information structure to track an LZ4 stream.
515  * init this structure before first use.
516  * note : only use in association with static linking !
517  * this definition is not API/ABI safe,
518  * it may change in a future version !
519  */
520 #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
521 #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
523  unsigned long long table[LZ4_STREAMSIZE_U64];
525 } ; /* previously typedef'd to LZ4_stream_t */
526 
527 
528 /*!
529  * LZ4_streamDecode_t :
530  * information structure to track an LZ4 stream during decompression.
531  * init this structure using LZ4_setStreamDecode (or memset()) before first use
532  * note : only use in association with static linking !
533  * this definition is not API/ABI safe,
534  * and may change in a future version !
535  */
536 #define LZ4_STREAMDECODESIZE_U64 4
537 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
539  unsigned long long table[LZ4_STREAMDECODESIZE_U64];
541 } ; /* previously typedef'd to LZ4_streamDecode_t */
542 
543 
544 /*-************************************
545 * Obsolete Functions
546 **************************************/
547 
548 /*! Deprecation warnings
549  Should deprecation warnings be a problem,
550  it is generally possible to disable them,
551  typically with -Wno-deprecated-declarations for gcc
552  or _CRT_SECURE_NO_WARNINGS in Visual.
553  Otherwise, it's also possible to define LZ4_DISABLE_DEPRECATE_WARNINGS */
554 #ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
555 # define LZ4_DEPRECATED(message) /* disable deprecation warnings */
556 #else
557 # define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
558 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
559 # define LZ4_DEPRECATED(message) [[deprecated(message)]]
560 # elif (LZ4_GCC_VERSION >= 405) || defined(__clang__)
561 # define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
562 # elif (LZ4_GCC_VERSION >= 301)
563 # define LZ4_DEPRECATED(message) __attribute__((deprecated))
564 # elif defined(_MSC_VER)
565 # define LZ4_DEPRECATED(message) __declspec(deprecated(message))
566 # else
567 # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
568 # define LZ4_DEPRECATED(message)
569 # endif
570 #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
571 
572 /* Obsolete compression functions */
573 LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* source, char* dest, int sourceSize);
574 LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize);
575 LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
576 LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
577 LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
578 LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
579 
580 /* Obsolete decompression functions */
581 LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
582 LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
583 
584 /* Obsolete streaming functions; degraded functionality; do not use!
585  *
586  * In order to perform streaming compression, these functions depended on data
587  * that is no longer tracked in the state. They have been preserved as well as
588  * possible: using them will still produce a correct output. However, they don't
589  * actually retain any history between compression calls. The compression ratio
590  * achieved will therefore be no better than compressing each chunk
591  * independently.
592  */
593 LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
595 LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
596 LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
597 
598 /* Obsolete streaming decoding functions */
601 
602 #endif /* LZ4_H_2983827168210 */
603 
604 
605 #if defined (__cplusplus)
606 }
607 #endif
void * LZ4_create(char *inputBuffer)
Definition: lz4.c:1903
LZ4_streamDecode_t_internal internal_donotuse
Definition: lz4.h:540
int LZ4_compress_limitedOutput(const char *source, char *dest, int inputSize, int maxOutputSize)
Definition: lz4.c:1852
#define LZ4LIB_API
Definition: lz4.h:90
LZ4LIB_API int LZ4_compress_default(const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:1084
LZ4LIB_API int LZ4_decompress_safe_usingDict(const char *src, char *dst, int srcSize, int dstCapcity, const char *dictStart, int dictSize)
Definition: lz4.c:1828
LZ4LIB_API int LZ4_compress_fast_extState(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:997
#define LZ4_HASH_SIZE_U32
Definition: lz4.h:467
unsigned int currentOffset
Definition: lz4.h:495
LZ4LIB_API int LZ4_sizeofState(void)
Definition: lz4.c:496
LZ4LIB_API void LZ4_resetStream(LZ4_stream_t *streamPtr)
Definition: lz4.c:1157
char int outputSize
Definition: lz4.h:581
int LZ4_resetStreamState(void *state, char *inputBuffer)
Definition: lz4.c:1896
int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize, int maxOutputSize)
Definition: lz4.c:1887
#define LZ4_STREAMSIZE_U64
Definition: lz4.h:520
int LZ4_compress_limitedOutput_continue(LZ4_stream_t *LZ4_stream, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:1868
char * LZ4_slideInputBuffer(void *state)
Definition: lz4.c:1909
#define LZ4_STREAMDECODESIZE_U64
Definition: lz4.h:536
char * dst
Definition: lz4.h:599
const unsigned char * prefixEnd
Definition: lz4.h:506
unsigned short tableType
Definition: lz4.h:497
int LZ4_uncompress(const char *source, char *dest, int outputSize)
Definition: lz4.c:1883
char int int maxDstSize
Definition: lz4.h:599
char int isize
Definition: lz4.h:582
int LZ4_decompress_fast_withPrefix64k(const char *source, char *dest, int originalSize)
Definition: lz4.c:1632
const unsigned char * externalDict
Definition: lz4.h:504
unsigned short initCheck
Definition: lz4.h:496
unsigned int hashTable[LZ4_HASH_SIZE_U32]
Definition: lz4.h:494
char int compressedSize
Definition: lz4.h:599
char int int maxOutputSize
Definition: lz4.h:574
char * inputBuffer
Definition: lz4.h:595
int LZ4_compress_withState(void *state, const char *src, char *dst, int srcSize)
Definition: lz4.c:1864
char int originalSize
Definition: lz4.h:600
void LZ4_attach_dictionary(LZ4_stream_t *working_stream, const LZ4_stream_t *dictionary_stream)
Definition: lz4.c:1219
LZ4LIB_API int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int maxDictSize)
Definition: lz4.c:1355
LZ4_FORCE_O2_GCC_PPC64LE int LZ4_decompress_safe_withPrefix64k(const char *source, char *dest, int compressedSize, int maxOutputSize)
Definition: lz4.c:1624
LZ4LIB_API int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1255
LZ4LIB_API int LZ4_decompress_fast(const char *src, char *dst, int originalSize)
Definition: lz4.c:1614
#define LZ4_DEPRECATED(message)
Definition: lz4.h:568
unsigned int dictSize
Definition: lz4.h:500
char int sourceSize
Definition: lz4.h:573
LZ4LIB_API int LZ4_freeStream(LZ4_stream_t *streamPtr)
Definition: lz4.c:1167
LZ4LIB_API LZ4_stream_t * LZ4_createStream(void)
Definition: lz4.c:1147
LZ4LIB_API const char * LZ4_versionString(void)
Definition: lz4.c:494
LZ4_stream_t_internal internal_donotuse
Definition: lz4.h:524
int LZ4_compress_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize)
Definition: lz4.c:1872
const char * source
Definition: lz4.h:575
LZ4LIB_API int LZ4_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity)
Definition: lz4.c:1598
LZ4LIB_API int LZ4_versionNumber(void)
Definition: lz4.c:493
int LZ4_compress_limitedOutput_withState(void *state, const char *src, char *dst, int srcSize, int dstSize)
Definition: lz4.c:1860
LZ4LIB_API int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition: lz4.c:1123
const LZ4_stream_t_internal * dictCtx
Definition: lz4.h:499
LZ4LIB_API int LZ4_compress_fast(const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1065
const char char int inputSize
Definition: lz4.h:575
LZ4LIB_API int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int originalSize)
Definition: lz4.c:1787
char * dest
Definition: lz4.h:573
int LZ4_sizeofStreamState()
Definition: lz4.c:1894
LZ4LIB_API LZ4_streamDecode_t * LZ4_createStreamDecode(void)
Definition: lz4.c:1691
int LZ4_compress(const char *source, char *dest, int inputSize)
Definition: lz4.c:1856
LZ4LIB_API int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, int dictSize)
Definition: lz4.c:1177
LZ4LIB_API int LZ4_decompress_safe_partial(const char *src, char *dst, int srcSize, int targetOutputSize, int dstCapacity)
Definition: lz4.c:1606
const unsigned char * dictionary
Definition: lz4.h:498
LZ4LIB_API int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
Definition: lz4.c:1710
struct state state
Definition: parser.c:103
void LZ4_resetStream_fast(LZ4_stream_t *ctx)
Definition: lz4.c:1163
int LZ4_compress_fast_extState_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1028
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize)
Definition: lz4.c:1731
LZ4LIB_API int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
Definition: lz4.c:1697
LZ4LIB_API int LZ4_decompress_fast_usingDict(const char *src, char *dst, int originalSize, const char *dictStart, int dictSize)
Definition: lz4.c:1840
LZ4LIB_API int LZ4_compressBound(int inputSize)
Definition: lz4.c:495
LZ4LIB_API int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:1747