VR-Vantage 3.2 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2016, 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)
38 extern "C" {
39 #endif
40 
41 /* --- Dependency --- */
42 /* note : lz4hc is not an independent module, it requires lz4.h/lz4.c for proper compilation */
43 #include "lz4.h" /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
44 
45 
46 /* --- Useful constants --- */
47 #define LZ4HC_CLEVEL_MIN 3
48 #define LZ4HC_CLEVEL_DEFAULT 9
49 #define LZ4HC_CLEVEL_OPT_MIN 11
50 #define LZ4HC_CLEVEL_MAX 12
51 
52 
53 /*-************************************
54  * Block Compression
55  **************************************/
66 // VRV_PATCH_BEGIN
67 // This is renamed to avoid ambiguity with the system LZ4 library. A namespace is
68 // not sufficient for this purpose due to the C linkage. Why the system library
69 // was ever being used is not fully understood, but if that is ever solved, this
70 // renaming can be undone.
71 LZ4LIB_API int LZ4_compress_HCStatic (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
72 // VRV_PATCH_END
73 
74 /* Note :
75  * Decompression functions are provided within "lz4.h" (BSD license)
76  */
77 
78 
84 LZ4LIB_API int LZ4_compress_HC_extStateHC(void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
86 
87 
88 /*-************************************
89  * Streaming Compression
90  * Bufferless synchronous API
91  **************************************/
92  typedef union LZ4_streamHC_u LZ4_streamHC_t; /* incomplete type (defined later) */
93 
101 LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
102 
104 LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
105 
106 LZ4LIB_API int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr, const char* src, char* dst, int srcSize, int maxDstSize);
107 
108 LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
109 
110 /*
111  These functions compress data in successive blocks of any size, using previous blocks as dictionary.
112  One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
113  There is an exception for ring buffers, which can be smaller than 64 KB.
114  Ring buffers scenario is automatically detected and handled by LZ4_compress_HC_continue().
115 
116  Before starting compression, state must be properly initialized, using LZ4_resetStreamHC().
117  A first "fictional block" can then be designated as initial dictionary, using LZ4_loadDictHC() (Optional).
118 
119  Then, use LZ4_compress_HC_continue() to compress each successive block.
120  Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
121  'dst' buffer should be sized to handle worst case scenarios, using LZ4_compressBound(), to ensure operation success.
122 
123  If, for any reason, previous data blocks can't be preserved unmodified in memory during next compression block,
124  you must save it to a safer memory space, using LZ4_saveDictHC().
125  Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer'.
126 */
127 
128 
129 /*-******************************************
130  * !!!!! STATIC LINKING ONLY !!!!!
131  *******************************************/
132 
133  /*-*************************************
134  * PRIVATE DEFINITIONS :
135  * Do not use these definitions.
136  * They are exposed to allow static allocation of `LZ4_streamHC_t`.
137  * Using these definitions makes the code vulnerable to potential API break when upgrading LZ4
138  **************************************/
139 #define LZ4HC_DICTIONARY_LOGSIZE 17
140 #define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
141 #define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
142 
143 #define LZ4HC_HASH_LOG 15
144 #define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
145 #define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
146 
147 
148 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
149 #include <stdint.h>
150 
151 typedef struct
152 {
153  uint32_t hashTable[LZ4HC_HASHTABLESIZE];
154  uint16_t chainTable[LZ4HC_MAXD];
155  const uint8_t* end; /* next block here to continue on current prefix */
156  const uint8_t* base; /* All index relative to this position */
157  const uint8_t* dictBase; /* alternate base for extDict */
158  uint8_t* inputBuffer; /* deprecated */
159  uint32_t dictLimit; /* below that point, need extDict */
160  uint32_t lowLimit; /* below that point, no more dict */
161  uint32_t nextToUpdate; /* index from which to continue dictionary update */
162  uint32_t searchNum; /* only for optimal parser */
163  uint32_t compressionLevel;
165 
166 #else
167 
168 typedef struct
169 {
170  unsigned int hashTable[LZ4HC_HASHTABLESIZE];
171  unsigned short chainTable[LZ4HC_MAXD];
172  const unsigned char* end; /* next block here to continue on current prefix */
173  const unsigned char* base; /* All index relative to this position */
174  const unsigned char* dictBase; /* alternate base for extDict */
175  unsigned char* inputBuffer; /* deprecated */
176  unsigned int dictLimit; /* below that point, need extDict */
177  unsigned int lowLimit; /* below that point, no more dict */
178  unsigned int nextToUpdate; /* index from which to continue dictionary update */
179  unsigned int searchNum; /* only for optimal parser */
180  unsigned int compressionLevel;
182 
183 #endif
184 
185 #define LZ4_STREAMHCSIZE (4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 56) /* 393268 */
186 #define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
190 }; /* previously typedef'd to LZ4_streamHC_t */
191 /*
192  LZ4_streamHC_t :
193  This structure allows static allocation of LZ4 HC streaming state.
194  State must be initialized using LZ4_resetStreamHC() before first use.
195 
196  Static allocation shall only be used in combination with static linking.
197  When invoking LZ4 from a DLL, use create/free functions instead, which are API and ABI stable.
198 */
199 
200 
201 /*-************************************
202 * Deprecated Functions
203 **************************************/
204 /* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
205 
206 /* deprecated compression functions */
207 /* these functions will trigger warning messages in future releases */
208 LZ4_DEPRECATED("use LZ4_compress_HC() instead") int LZ4_compressHC (const char* source, char* dest, int inputSize);
209 LZ4_DEPRECATED("use LZ4_compress_HC() instead") int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
210 LZ4_DEPRECATED("use LZ4_compress_HC() instead") int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
211 LZ4_DEPRECATED("use LZ4_compress_HC() instead") int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
212 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
213 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
214 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
215 LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
216 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
217 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
218 
219 /* Deprecated Streaming functions using older model; should no longer be used */
220 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") void* LZ4_createHC (char* inputBuffer);
221 LZ4_DEPRECATED("use LZ4_saveDictHC() instead") char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
222 LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") int LZ4_freeHC (void* LZ4HC_Data);
223 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
224 LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
225 LZ4_DEPRECATED("use LZ4_createStreamHC() instead") int LZ4_sizeofStreamStateHC(void);
226 LZ4_DEPRECATED("use LZ4_resetStreamHC() instead") int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
227 
228 
229 #if defined (__cplusplus)
230 }
231 #endif
232 
233 #endif /* LZ4_HC_H_19834876238432 */


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