xref: /aosp_15_r20/external/lz4/lib/lz4hc.h (revision 27162e4e17433d5aa7cb38e7b6a433a09405fc7f)
1*27162e4eSAndroid Build Coastguard Worker /*
2*27162e4eSAndroid Build Coastguard Worker    LZ4 HC - High Compression Mode of LZ4
3*27162e4eSAndroid Build Coastguard Worker    Header File
4*27162e4eSAndroid Build Coastguard Worker    Copyright (C) 2011-2020, Yann Collet.
5*27162e4eSAndroid Build Coastguard Worker    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6*27162e4eSAndroid Build Coastguard Worker 
7*27162e4eSAndroid Build Coastguard Worker    Redistribution and use in source and binary forms, with or without
8*27162e4eSAndroid Build Coastguard Worker    modification, are permitted provided that the following conditions are
9*27162e4eSAndroid Build Coastguard Worker    met:
10*27162e4eSAndroid Build Coastguard Worker 
11*27162e4eSAndroid Build Coastguard Worker        * Redistributions of source code must retain the above copyright
12*27162e4eSAndroid Build Coastguard Worker    notice, this list of conditions and the following disclaimer.
13*27162e4eSAndroid Build Coastguard Worker        * Redistributions in binary form must reproduce the above
14*27162e4eSAndroid Build Coastguard Worker    copyright notice, this list of conditions and the following disclaimer
15*27162e4eSAndroid Build Coastguard Worker    in the documentation and/or other materials provided with the
16*27162e4eSAndroid Build Coastguard Worker    distribution.
17*27162e4eSAndroid Build Coastguard Worker 
18*27162e4eSAndroid Build Coastguard Worker    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*27162e4eSAndroid Build Coastguard Worker    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*27162e4eSAndroid Build Coastguard Worker    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*27162e4eSAndroid Build Coastguard Worker    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*27162e4eSAndroid Build Coastguard Worker    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*27162e4eSAndroid Build Coastguard Worker    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*27162e4eSAndroid Build Coastguard Worker    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*27162e4eSAndroid Build Coastguard Worker    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*27162e4eSAndroid Build Coastguard Worker    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*27162e4eSAndroid Build Coastguard Worker    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*27162e4eSAndroid Build Coastguard Worker    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*27162e4eSAndroid Build Coastguard Worker 
30*27162e4eSAndroid Build Coastguard Worker    You can contact the author at :
31*27162e4eSAndroid Build Coastguard Worker    - LZ4 source repository : https://github.com/lz4/lz4
32*27162e4eSAndroid Build Coastguard Worker    - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
33*27162e4eSAndroid Build Coastguard Worker */
34*27162e4eSAndroid Build Coastguard Worker #ifndef LZ4_HC_H_19834876238432
35*27162e4eSAndroid Build Coastguard Worker #define LZ4_HC_H_19834876238432
36*27162e4eSAndroid Build Coastguard Worker 
37*27162e4eSAndroid Build Coastguard Worker #if defined (__cplusplus)
38*27162e4eSAndroid Build Coastguard Worker extern "C" {
39*27162e4eSAndroid Build Coastguard Worker #endif
40*27162e4eSAndroid Build Coastguard Worker 
41*27162e4eSAndroid Build Coastguard Worker /* --- Dependency --- */
42*27162e4eSAndroid Build Coastguard Worker /* note : lz4hc requires lz4.h/lz4.c for compilation */
43*27162e4eSAndroid Build Coastguard Worker #include "lz4.h"   /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
44*27162e4eSAndroid Build Coastguard Worker 
45*27162e4eSAndroid Build Coastguard Worker 
46*27162e4eSAndroid Build Coastguard Worker /* --- Useful constants --- */
47*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_CLEVEL_MIN         2
48*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_CLEVEL_DEFAULT     9
49*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_CLEVEL_OPT_MIN    10
50*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_CLEVEL_MAX        12
51*27162e4eSAndroid Build Coastguard Worker 
52*27162e4eSAndroid Build Coastguard Worker 
53*27162e4eSAndroid Build Coastguard Worker /*-************************************
54*27162e4eSAndroid Build Coastguard Worker  *  Block Compression
55*27162e4eSAndroid Build Coastguard Worker  **************************************/
56*27162e4eSAndroid Build Coastguard Worker /*! LZ4_compress_HC() :
57*27162e4eSAndroid Build Coastguard Worker  *  Compress data from `src` into `dst`, using the powerful but slower "HC" algorithm.
58*27162e4eSAndroid Build Coastguard Worker  * `dst` must be already allocated.
59*27162e4eSAndroid Build Coastguard Worker  *  Compression is guaranteed to succeed if `dstCapacity >= LZ4_compressBound(srcSize)` (see "lz4.h")
60*27162e4eSAndroid Build Coastguard Worker  *  Max supported `srcSize` value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
61*27162e4eSAndroid Build Coastguard Worker  * `compressionLevel` : any value between 1 and LZ4HC_CLEVEL_MAX will work.
62*27162e4eSAndroid Build Coastguard Worker  *                      Values > LZ4HC_CLEVEL_MAX behave the same as LZ4HC_CLEVEL_MAX.
63*27162e4eSAndroid Build Coastguard Worker  * @return : the number of bytes written into 'dst'
64*27162e4eSAndroid Build Coastguard Worker  *           or 0 if compression fails.
65*27162e4eSAndroid Build Coastguard Worker  */
66*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_compress_HC (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
67*27162e4eSAndroid Build Coastguard Worker 
68*27162e4eSAndroid Build Coastguard Worker 
69*27162e4eSAndroid Build Coastguard Worker /* Note :
70*27162e4eSAndroid Build Coastguard Worker  *   Decompression functions are provided within "lz4.h" (BSD license)
71*27162e4eSAndroid Build Coastguard Worker  */
72*27162e4eSAndroid Build Coastguard Worker 
73*27162e4eSAndroid Build Coastguard Worker 
74*27162e4eSAndroid Build Coastguard Worker /*! LZ4_compress_HC_extStateHC() :
75*27162e4eSAndroid Build Coastguard Worker  *  Same as LZ4_compress_HC(), but using an externally allocated memory segment for `state`.
76*27162e4eSAndroid Build Coastguard Worker  * `state` size is provided by LZ4_sizeofStateHC().
77*27162e4eSAndroid Build Coastguard Worker  *  Memory segment must be aligned on 8-bytes boundaries (which a normal malloc() should do properly).
78*27162e4eSAndroid Build Coastguard Worker  */
79*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_sizeofStateHC(void);
80*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
81*27162e4eSAndroid Build Coastguard Worker 
82*27162e4eSAndroid Build Coastguard Worker 
83*27162e4eSAndroid Build Coastguard Worker /*! LZ4_compress_HC_destSize() : v1.9.0+
84*27162e4eSAndroid Build Coastguard Worker  *  Will compress as much data as possible from `src`
85*27162e4eSAndroid Build Coastguard Worker  *  to fit into `targetDstSize` budget.
86*27162e4eSAndroid Build Coastguard Worker  *  Result is provided in 2 parts :
87*27162e4eSAndroid Build Coastguard Worker  * @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)
88*27162e4eSAndroid Build Coastguard Worker  *           or 0 if compression fails.
89*27162e4eSAndroid Build Coastguard Worker  * `srcSizePtr` : on success, *srcSizePtr is updated to indicate how much bytes were read from `src`
90*27162e4eSAndroid Build Coastguard Worker  */
91*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
92*27162e4eSAndroid Build Coastguard Worker                                   const char* src, char* dst,
93*27162e4eSAndroid Build Coastguard Worker                                         int* srcSizePtr, int targetDstSize,
94*27162e4eSAndroid Build Coastguard Worker                                         int compressionLevel);
95*27162e4eSAndroid Build Coastguard Worker 
96*27162e4eSAndroid Build Coastguard Worker 
97*27162e4eSAndroid Build Coastguard Worker /*-************************************
98*27162e4eSAndroid Build Coastguard Worker  *  Streaming Compression
99*27162e4eSAndroid Build Coastguard Worker  *  Bufferless synchronous API
100*27162e4eSAndroid Build Coastguard Worker  **************************************/
101*27162e4eSAndroid Build Coastguard Worker  typedef union LZ4_streamHC_u LZ4_streamHC_t;   /* incomplete type (defined later) */
102*27162e4eSAndroid Build Coastguard Worker 
103*27162e4eSAndroid Build Coastguard Worker /*! LZ4_createStreamHC() and LZ4_freeStreamHC() :
104*27162e4eSAndroid Build Coastguard Worker  *  These functions create and release memory for LZ4 HC streaming state.
105*27162e4eSAndroid Build Coastguard Worker  *  Newly created states are automatically initialized.
106*27162e4eSAndroid Build Coastguard Worker  *  A same state can be used multiple times consecutively,
107*27162e4eSAndroid Build Coastguard Worker  *  starting with LZ4_resetStreamHC_fast() to start a new stream of blocks.
108*27162e4eSAndroid Build Coastguard Worker  */
109*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API LZ4_streamHC_t* LZ4_createStreamHC(void);
110*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int             LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
111*27162e4eSAndroid Build Coastguard Worker 
112*27162e4eSAndroid Build Coastguard Worker /*
113*27162e4eSAndroid Build Coastguard Worker   These functions compress data in successive blocks of any size,
114*27162e4eSAndroid Build Coastguard Worker   using previous blocks as dictionary, to improve compression ratio.
115*27162e4eSAndroid Build Coastguard Worker   One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
116*27162e4eSAndroid Build Coastguard Worker   There is an exception for ring buffers, which can be smaller than 64 KB.
117*27162e4eSAndroid Build Coastguard Worker   Ring-buffer scenario is automatically detected and handled within LZ4_compress_HC_continue().
118*27162e4eSAndroid Build Coastguard Worker 
119*27162e4eSAndroid Build Coastguard Worker   Before starting compression, state must be allocated and properly initialized.
120*27162e4eSAndroid Build Coastguard Worker   LZ4_createStreamHC() does both, though compression level is set to LZ4HC_CLEVEL_DEFAULT.
121*27162e4eSAndroid Build Coastguard Worker 
122*27162e4eSAndroid Build Coastguard Worker   Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
123*27162e4eSAndroid Build Coastguard Worker   or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
124*27162e4eSAndroid Build Coastguard Worker   LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
125*27162e4eSAndroid Build Coastguard Worker   which is automatically the case when state is created using LZ4_createStreamHC().
126*27162e4eSAndroid Build Coastguard Worker 
127*27162e4eSAndroid Build Coastguard Worker   After reset, a first "fictional block" can be designated as initial dictionary,
128*27162e4eSAndroid Build Coastguard Worker   using LZ4_loadDictHC() (Optional).
129*27162e4eSAndroid Build Coastguard Worker   Note: In order for LZ4_loadDictHC() to create the correct data structure,
130*27162e4eSAndroid Build Coastguard Worker   it is essential to set the compression level _before_ loading the dictionary.
131*27162e4eSAndroid Build Coastguard Worker 
132*27162e4eSAndroid Build Coastguard Worker   Invoke LZ4_compress_HC_continue() to compress each successive block.
133*27162e4eSAndroid Build Coastguard Worker   The number of blocks is unlimited.
134*27162e4eSAndroid Build Coastguard Worker   Previous input blocks, including initial dictionary when present,
135*27162e4eSAndroid Build Coastguard Worker   must remain accessible and unmodified during compression.
136*27162e4eSAndroid Build Coastguard Worker 
137*27162e4eSAndroid Build Coastguard Worker   It's allowed to update compression level anytime between blocks,
138*27162e4eSAndroid Build Coastguard Worker   using LZ4_setCompressionLevel() (experimental).
139*27162e4eSAndroid Build Coastguard Worker 
140*27162e4eSAndroid Build Coastguard Worker  @dst buffer should be sized to handle worst case scenarios
141*27162e4eSAndroid Build Coastguard Worker   (see LZ4_compressBound(), it ensures compression success).
142*27162e4eSAndroid Build Coastguard Worker   In case of failure, the API does not guarantee recovery,
143*27162e4eSAndroid Build Coastguard Worker   so the state _must_ be reset.
144*27162e4eSAndroid Build Coastguard Worker   To ensure compression success
145*27162e4eSAndroid Build Coastguard Worker   whenever @dst buffer size cannot be made >= LZ4_compressBound(),
146*27162e4eSAndroid Build Coastguard Worker   consider using LZ4_compress_HC_continue_destSize().
147*27162e4eSAndroid Build Coastguard Worker 
148*27162e4eSAndroid Build Coastguard Worker   Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
149*27162e4eSAndroid Build Coastguard Worker   it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
150*27162e4eSAndroid Build Coastguard Worker   Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
151*27162e4eSAndroid Build Coastguard Worker 
152*27162e4eSAndroid Build Coastguard Worker   After completing a streaming compression,
153*27162e4eSAndroid Build Coastguard Worker   it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
154*27162e4eSAndroid Build Coastguard Worker   just by resetting it, using LZ4_resetStreamHC_fast().
155*27162e4eSAndroid Build Coastguard Worker */
156*27162e4eSAndroid Build Coastguard Worker 
157*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel);   /* v1.9.0+ */
158*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int  LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
159*27162e4eSAndroid Build Coastguard Worker 
160*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr,
161*27162e4eSAndroid Build Coastguard Worker                                    const char* src, char* dst,
162*27162e4eSAndroid Build Coastguard Worker                                          int srcSize, int maxDstSize);
163*27162e4eSAndroid Build Coastguard Worker 
164*27162e4eSAndroid Build Coastguard Worker /*! LZ4_compress_HC_continue_destSize() : v1.9.0+
165*27162e4eSAndroid Build Coastguard Worker  *  Similar to LZ4_compress_HC_continue(),
166*27162e4eSAndroid Build Coastguard Worker  *  but will read as much data as possible from `src`
167*27162e4eSAndroid Build Coastguard Worker  *  to fit into `targetDstSize` budget.
168*27162e4eSAndroid Build Coastguard Worker  *  Result is provided into 2 parts :
169*27162e4eSAndroid Build Coastguard Worker  * @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)
170*27162e4eSAndroid Build Coastguard Worker  *           or 0 if compression fails.
171*27162e4eSAndroid Build Coastguard Worker  * `srcSizePtr` : on success, *srcSizePtr will be updated to indicate how much bytes were read from `src`.
172*27162e4eSAndroid Build Coastguard Worker  *           Note that this function may not consume the entire input.
173*27162e4eSAndroid Build Coastguard Worker  */
174*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr,
175*27162e4eSAndroid Build Coastguard Worker                                            const char* src, char* dst,
176*27162e4eSAndroid Build Coastguard Worker                                                  int* srcSizePtr, int targetDstSize);
177*27162e4eSAndroid Build Coastguard Worker 
178*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
179*27162e4eSAndroid Build Coastguard Worker 
180*27162e4eSAndroid Build Coastguard Worker 
181*27162e4eSAndroid Build Coastguard Worker /*! LZ4_attach_HC_dictionary() : stable since v1.10.0
182*27162e4eSAndroid Build Coastguard Worker  *  This API allows for the efficient re-use of a static dictionary many times.
183*27162e4eSAndroid Build Coastguard Worker  *
184*27162e4eSAndroid Build Coastguard Worker  *  Rather than re-loading the dictionary buffer into a working context before
185*27162e4eSAndroid Build Coastguard Worker  *  each compression, or copying a pre-loaded dictionary's LZ4_streamHC_t into a
186*27162e4eSAndroid Build Coastguard Worker  *  working LZ4_streamHC_t, this function introduces a no-copy setup mechanism,
187*27162e4eSAndroid Build Coastguard Worker  *  in which the working stream references the dictionary stream in-place.
188*27162e4eSAndroid Build Coastguard Worker  *
189*27162e4eSAndroid Build Coastguard Worker  *  Several assumptions are made about the state of the dictionary stream.
190*27162e4eSAndroid Build Coastguard Worker  *  Currently, only streams which have been prepared by LZ4_loadDictHC() should
191*27162e4eSAndroid Build Coastguard Worker  *  be expected to work.
192*27162e4eSAndroid Build Coastguard Worker  *
193*27162e4eSAndroid Build Coastguard Worker  *  Alternatively, the provided dictionary stream pointer may be NULL, in which
194*27162e4eSAndroid Build Coastguard Worker  *  case any existing dictionary stream is unset.
195*27162e4eSAndroid Build Coastguard Worker  *
196*27162e4eSAndroid Build Coastguard Worker  *  A dictionary should only be attached to a stream without any history (i.e.,
197*27162e4eSAndroid Build Coastguard Worker  *  a stream that has just been reset).
198*27162e4eSAndroid Build Coastguard Worker  *
199*27162e4eSAndroid Build Coastguard Worker  *  The dictionary will remain attached to the working stream only for the
200*27162e4eSAndroid Build Coastguard Worker  *  current stream session. Calls to LZ4_resetStreamHC(_fast) will remove the
201*27162e4eSAndroid Build Coastguard Worker  *  dictionary context association from the working stream. The dictionary
202*27162e4eSAndroid Build Coastguard Worker  *  stream (and source buffer) must remain in-place / accessible / unchanged
203*27162e4eSAndroid Build Coastguard Worker  *  through the lifetime of the stream session.
204*27162e4eSAndroid Build Coastguard Worker  */
205*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API void
206*27162e4eSAndroid Build Coastguard Worker LZ4_attach_HC_dictionary(LZ4_streamHC_t* working_stream,
207*27162e4eSAndroid Build Coastguard Worker                    const LZ4_streamHC_t* dictionary_stream);
208*27162e4eSAndroid Build Coastguard Worker 
209*27162e4eSAndroid Build Coastguard Worker 
210*27162e4eSAndroid Build Coastguard Worker /*^**********************************************
211*27162e4eSAndroid Build Coastguard Worker  * !!!!!!   STATIC LINKING ONLY   !!!!!!
212*27162e4eSAndroid Build Coastguard Worker  ***********************************************/
213*27162e4eSAndroid Build Coastguard Worker 
214*27162e4eSAndroid Build Coastguard Worker /*-******************************************************************
215*27162e4eSAndroid Build Coastguard Worker  * PRIVATE DEFINITIONS :
216*27162e4eSAndroid Build Coastguard Worker  * Do not use these definitions directly.
217*27162e4eSAndroid Build Coastguard Worker  * They are merely exposed to allow static allocation of `LZ4_streamHC_t`.
218*27162e4eSAndroid Build Coastguard Worker  * Declare an `LZ4_streamHC_t` directly, rather than any type below.
219*27162e4eSAndroid Build Coastguard Worker  * Even then, only do so in the context of static linking, as definitions may change between versions.
220*27162e4eSAndroid Build Coastguard Worker  ********************************************************************/
221*27162e4eSAndroid Build Coastguard Worker 
222*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_DICTIONARY_LOGSIZE 16
223*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
224*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
225*27162e4eSAndroid Build Coastguard Worker 
226*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_HASH_LOG 15
227*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
228*27162e4eSAndroid Build Coastguard Worker #define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
229*27162e4eSAndroid Build Coastguard Worker 
230*27162e4eSAndroid Build Coastguard Worker 
231*27162e4eSAndroid Build Coastguard Worker /* Never ever use these definitions directly !
232*27162e4eSAndroid Build Coastguard Worker  * Declare or allocate an LZ4_streamHC_t instead.
233*27162e4eSAndroid Build Coastguard Worker **/
234*27162e4eSAndroid Build Coastguard Worker typedef struct LZ4HC_CCtx_internal LZ4HC_CCtx_internal;
235*27162e4eSAndroid Build Coastguard Worker struct LZ4HC_CCtx_internal
236*27162e4eSAndroid Build Coastguard Worker {
237*27162e4eSAndroid Build Coastguard Worker     LZ4_u32 hashTable[LZ4HC_HASHTABLESIZE];
238*27162e4eSAndroid Build Coastguard Worker     LZ4_u16 chainTable[LZ4HC_MAXD];
239*27162e4eSAndroid Build Coastguard Worker     const LZ4_byte* end;     /* next block here to continue on current prefix */
240*27162e4eSAndroid Build Coastguard Worker     const LZ4_byte* prefixStart;  /* Indexes relative to this position */
241*27162e4eSAndroid Build Coastguard Worker     const LZ4_byte* dictStart; /* alternate reference for extDict */
242*27162e4eSAndroid Build Coastguard Worker     LZ4_u32 dictLimit;       /* below that point, need extDict */
243*27162e4eSAndroid Build Coastguard Worker     LZ4_u32 lowLimit;        /* below that point, no more history */
244*27162e4eSAndroid Build Coastguard Worker     LZ4_u32 nextToUpdate;    /* index from which to continue dictionary update */
245*27162e4eSAndroid Build Coastguard Worker     short   compressionLevel;
246*27162e4eSAndroid Build Coastguard Worker     LZ4_i8  favorDecSpeed;   /* favor decompression speed if this flag set,
247*27162e4eSAndroid Build Coastguard Worker                                 otherwise, favor compression ratio */
248*27162e4eSAndroid Build Coastguard Worker     LZ4_i8  dirty;           /* stream has to be fully reset if this flag is set */
249*27162e4eSAndroid Build Coastguard Worker     const LZ4HC_CCtx_internal* dictCtx;
250*27162e4eSAndroid Build Coastguard Worker };
251*27162e4eSAndroid Build Coastguard Worker 
252*27162e4eSAndroid Build Coastguard Worker #define LZ4_STREAMHC_MINSIZE  262200  /* static size, for inter-version compatibility */
253*27162e4eSAndroid Build Coastguard Worker union LZ4_streamHC_u {
254*27162e4eSAndroid Build Coastguard Worker     char minStateSize[LZ4_STREAMHC_MINSIZE];
255*27162e4eSAndroid Build Coastguard Worker     LZ4HC_CCtx_internal internal_donotuse;
256*27162e4eSAndroid Build Coastguard Worker }; /* previously typedef'd to LZ4_streamHC_t */
257*27162e4eSAndroid Build Coastguard Worker 
258*27162e4eSAndroid Build Coastguard Worker /* LZ4_streamHC_t :
259*27162e4eSAndroid Build Coastguard Worker  * This structure allows static allocation of LZ4 HC streaming state.
260*27162e4eSAndroid Build Coastguard Worker  * This can be used to allocate statically on stack, or as part of a larger structure.
261*27162e4eSAndroid Build Coastguard Worker  *
262*27162e4eSAndroid Build Coastguard Worker  * Such state **must** be initialized using LZ4_initStreamHC() before first use.
263*27162e4eSAndroid Build Coastguard Worker  *
264*27162e4eSAndroid Build Coastguard Worker  * Note that invoking LZ4_initStreamHC() is not required when
265*27162e4eSAndroid Build Coastguard Worker  * the state was created using LZ4_createStreamHC() (which is recommended).
266*27162e4eSAndroid Build Coastguard Worker  * Using the normal builder, a newly created state is automatically initialized.
267*27162e4eSAndroid Build Coastguard Worker  *
268*27162e4eSAndroid Build Coastguard Worker  * Static allocation shall only be used in combination with static linking.
269*27162e4eSAndroid Build Coastguard Worker  */
270*27162e4eSAndroid Build Coastguard Worker 
271*27162e4eSAndroid Build Coastguard Worker /* LZ4_initStreamHC() : v1.9.0+
272*27162e4eSAndroid Build Coastguard Worker  * Required before first use of a statically allocated LZ4_streamHC_t.
273*27162e4eSAndroid Build Coastguard Worker  * Before v1.9.0 : use LZ4_resetStreamHC() instead
274*27162e4eSAndroid Build Coastguard Worker  */
275*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API LZ4_streamHC_t* LZ4_initStreamHC(void* buffer, size_t size);
276*27162e4eSAndroid Build Coastguard Worker 
277*27162e4eSAndroid Build Coastguard Worker 
278*27162e4eSAndroid Build Coastguard Worker /*-************************************
279*27162e4eSAndroid Build Coastguard Worker *  Deprecated Functions
280*27162e4eSAndroid Build Coastguard Worker **************************************/
281*27162e4eSAndroid Build Coastguard Worker /* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
282*27162e4eSAndroid Build Coastguard Worker 
283*27162e4eSAndroid Build Coastguard Worker /* deprecated compression functions */
284*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC               (const char* source, char* dest, int inputSize);
285*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
286*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2              (const char* source, char* dest, int inputSize, int compressionLevel);
287*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
288*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC               (void* state, const char* source, char* dest, int inputSize);
289*27162e4eSAndroid Build Coastguard Worker 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);
290*27162e4eSAndroid Build Coastguard Worker 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);
291*27162e4eSAndroid Build Coastguard Worker 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);
292*27162e4eSAndroid Build Coastguard Worker 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);
293*27162e4eSAndroid Build Coastguard Worker 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);
294*27162e4eSAndroid Build Coastguard Worker 
295*27162e4eSAndroid Build Coastguard Worker /* Obsolete streaming functions; degraded functionality; do not use!
296*27162e4eSAndroid Build Coastguard Worker  *
297*27162e4eSAndroid Build Coastguard Worker  * In order to perform streaming compression, these functions depended on data
298*27162e4eSAndroid Build Coastguard Worker  * that is no longer tracked in the state. They have been preserved as well as
299*27162e4eSAndroid Build Coastguard Worker  * possible: using them will still produce a correct output. However, use of
300*27162e4eSAndroid Build Coastguard Worker  * LZ4_slideInputBufferHC() will truncate the history of the stream, rather
301*27162e4eSAndroid Build Coastguard Worker  * than preserve a window-sized chunk of history.
302*27162e4eSAndroid Build Coastguard Worker  */
303*27162e4eSAndroid Build Coastguard Worker #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
304*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
305*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API   int   LZ4_freeHC (void* LZ4HC_Data);
306*27162e4eSAndroid Build Coastguard Worker #endif
307*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API     char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
308*27162e4eSAndroid Build Coastguard Worker 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);
309*27162e4eSAndroid Build Coastguard Worker 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);
310*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int   LZ4_sizeofStreamStateHC(void);
311*27162e4eSAndroid Build Coastguard Worker LZ4_DEPRECATED("use LZ4_initStreamHC() instead") LZ4LIB_API  int   LZ4_resetStreamStateHC(void* state, char* inputBuffer);
312*27162e4eSAndroid Build Coastguard Worker 
313*27162e4eSAndroid Build Coastguard Worker 
314*27162e4eSAndroid Build Coastguard Worker /* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
315*27162e4eSAndroid Build Coastguard Worker  * The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
316*27162e4eSAndroid Build Coastguard Worker  * which is now the recommended function to start a new stream of blocks,
317*27162e4eSAndroid Build Coastguard Worker  * but cannot be used to initialize a memory segment containing arbitrary garbage data.
318*27162e4eSAndroid Build Coastguard Worker  *
319*27162e4eSAndroid Build Coastguard Worker  * It is recommended to switch to LZ4_initStreamHC().
320*27162e4eSAndroid Build Coastguard Worker  * LZ4_resetStreamHC() will generate deprecation warnings in a future version.
321*27162e4eSAndroid Build Coastguard Worker  */
322*27162e4eSAndroid Build Coastguard Worker LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
323*27162e4eSAndroid Build Coastguard Worker 
324*27162e4eSAndroid Build Coastguard Worker 
325*27162e4eSAndroid Build Coastguard Worker #if defined (__cplusplus)
326*27162e4eSAndroid Build Coastguard Worker }
327*27162e4eSAndroid Build Coastguard Worker #endif
328*27162e4eSAndroid Build Coastguard Worker 
329*27162e4eSAndroid Build Coastguard Worker #endif /* LZ4_HC_H_19834876238432 */
330*27162e4eSAndroid Build Coastguard Worker 
331*27162e4eSAndroid Build Coastguard Worker 
332*27162e4eSAndroid Build Coastguard Worker /*-**************************************************
333*27162e4eSAndroid Build Coastguard Worker  * !!!!!     STATIC LINKING ONLY     !!!!!
334*27162e4eSAndroid Build Coastguard Worker  * Following definitions are considered experimental.
335*27162e4eSAndroid Build Coastguard Worker  * They should not be linked from DLL,
336*27162e4eSAndroid Build Coastguard Worker  * as there is no guarantee of API stability yet.
337*27162e4eSAndroid Build Coastguard Worker  * Prototypes will be promoted to "stable" status
338*27162e4eSAndroid Build Coastguard Worker  * after successful usage in real-life scenarios.
339*27162e4eSAndroid Build Coastguard Worker  ***************************************************/
340*27162e4eSAndroid Build Coastguard Worker #ifdef LZ4_HC_STATIC_LINKING_ONLY   /* protection macro */
341*27162e4eSAndroid Build Coastguard Worker #ifndef LZ4_HC_SLO_098092834
342*27162e4eSAndroid Build Coastguard Worker #define LZ4_HC_SLO_098092834
343*27162e4eSAndroid Build Coastguard Worker 
344*27162e4eSAndroid Build Coastguard Worker #define LZ4_STATIC_LINKING_ONLY   /* LZ4LIB_STATIC_API */
345*27162e4eSAndroid Build Coastguard Worker #include "lz4.h"
346*27162e4eSAndroid Build Coastguard Worker 
347*27162e4eSAndroid Build Coastguard Worker #if defined (__cplusplus)
348*27162e4eSAndroid Build Coastguard Worker extern "C" {
349*27162e4eSAndroid Build Coastguard Worker #endif
350*27162e4eSAndroid Build Coastguard Worker 
351*27162e4eSAndroid Build Coastguard Worker /*! LZ4_setCompressionLevel() : v1.8.0+ (experimental)
352*27162e4eSAndroid Build Coastguard Worker  *  It's possible to change compression level
353*27162e4eSAndroid Build Coastguard Worker  *  between successive invocations of LZ4_compress_HC_continue*()
354*27162e4eSAndroid Build Coastguard Worker  *  for dynamic adaptation.
355*27162e4eSAndroid Build Coastguard Worker  */
356*27162e4eSAndroid Build Coastguard Worker LZ4LIB_STATIC_API void LZ4_setCompressionLevel(
357*27162e4eSAndroid Build Coastguard Worker     LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
358*27162e4eSAndroid Build Coastguard Worker 
359*27162e4eSAndroid Build Coastguard Worker /*! LZ4_favorDecompressionSpeed() : v1.8.2+ (experimental)
360*27162e4eSAndroid Build Coastguard Worker  *  Opt. Parser will favor decompression speed over compression ratio.
361*27162e4eSAndroid Build Coastguard Worker  *  Only applicable to levels >= LZ4HC_CLEVEL_OPT_MIN.
362*27162e4eSAndroid Build Coastguard Worker  */
363*27162e4eSAndroid Build Coastguard Worker LZ4LIB_STATIC_API void LZ4_favorDecompressionSpeed(
364*27162e4eSAndroid Build Coastguard Worker     LZ4_streamHC_t* LZ4_streamHCPtr, int favor);
365*27162e4eSAndroid Build Coastguard Worker 
366*27162e4eSAndroid Build Coastguard Worker /*! LZ4_resetStreamHC_fast() : v1.9.0+
367*27162e4eSAndroid Build Coastguard Worker  *  When an LZ4_streamHC_t is known to be in a internally coherent state,
368*27162e4eSAndroid Build Coastguard Worker  *  it can often be prepared for a new compression with almost no work, only
369*27162e4eSAndroid Build Coastguard Worker  *  sometimes falling back to the full, expensive reset that is always required
370*27162e4eSAndroid Build Coastguard Worker  *  when the stream is in an indeterminate state (i.e., the reset performed by
371*27162e4eSAndroid Build Coastguard Worker  *  LZ4_resetStreamHC()).
372*27162e4eSAndroid Build Coastguard Worker  *
373*27162e4eSAndroid Build Coastguard Worker  *  LZ4_streamHCs are guaranteed to be in a valid state when:
374*27162e4eSAndroid Build Coastguard Worker  *  - returned from LZ4_createStreamHC()
375*27162e4eSAndroid Build Coastguard Worker  *  - reset by LZ4_resetStreamHC()
376*27162e4eSAndroid Build Coastguard Worker  *  - memset(stream, 0, sizeof(LZ4_streamHC_t))
377*27162e4eSAndroid Build Coastguard Worker  *  - the stream was in a valid state and was reset by LZ4_resetStreamHC_fast()
378*27162e4eSAndroid Build Coastguard Worker  *  - the stream was in a valid state and was then used in any compression call
379*27162e4eSAndroid Build Coastguard Worker  *    that returned success
380*27162e4eSAndroid Build Coastguard Worker  *  - the stream was in an indeterminate state and was used in a compression
381*27162e4eSAndroid Build Coastguard Worker  *    call that fully reset the state (LZ4_compress_HC_extStateHC()) and that
382*27162e4eSAndroid Build Coastguard Worker  *    returned success
383*27162e4eSAndroid Build Coastguard Worker  *
384*27162e4eSAndroid Build Coastguard Worker  *  Note:
385*27162e4eSAndroid Build Coastguard Worker  *  A stream that was last used in a compression call that returned an error
386*27162e4eSAndroid Build Coastguard Worker  *  may be passed to this function. However, it will be fully reset, which will
387*27162e4eSAndroid Build Coastguard Worker  *  clear any existing history and settings from the context.
388*27162e4eSAndroid Build Coastguard Worker  */
389*27162e4eSAndroid Build Coastguard Worker LZ4LIB_STATIC_API void LZ4_resetStreamHC_fast(
390*27162e4eSAndroid Build Coastguard Worker     LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
391*27162e4eSAndroid Build Coastguard Worker 
392*27162e4eSAndroid Build Coastguard Worker /*! LZ4_compress_HC_extStateHC_fastReset() :
393*27162e4eSAndroid Build Coastguard Worker  *  A variant of LZ4_compress_HC_extStateHC().
394*27162e4eSAndroid Build Coastguard Worker  *
395*27162e4eSAndroid Build Coastguard Worker  *  Using this variant avoids an expensive initialization step. It is only safe
396*27162e4eSAndroid Build Coastguard Worker  *  to call if the state buffer is known to be correctly initialized already
397*27162e4eSAndroid Build Coastguard Worker  *  (see above comment on LZ4_resetStreamHC_fast() for a definition of
398*27162e4eSAndroid Build Coastguard Worker  *  "correctly initialized"). From a high level, the difference is that this
399*27162e4eSAndroid Build Coastguard Worker  *  function initializes the provided state with a call to
400*27162e4eSAndroid Build Coastguard Worker  *  LZ4_resetStreamHC_fast() while LZ4_compress_HC_extStateHC() starts with a
401*27162e4eSAndroid Build Coastguard Worker  *  call to LZ4_resetStreamHC().
402*27162e4eSAndroid Build Coastguard Worker  */
403*27162e4eSAndroid Build Coastguard Worker LZ4LIB_STATIC_API int LZ4_compress_HC_extStateHC_fastReset (
404*27162e4eSAndroid Build Coastguard Worker     void* state,
405*27162e4eSAndroid Build Coastguard Worker     const char* src, char* dst,
406*27162e4eSAndroid Build Coastguard Worker     int srcSize, int dstCapacity,
407*27162e4eSAndroid Build Coastguard Worker     int compressionLevel);
408*27162e4eSAndroid Build Coastguard Worker 
409*27162e4eSAndroid Build Coastguard Worker #if defined (__cplusplus)
410*27162e4eSAndroid Build Coastguard Worker }
411*27162e4eSAndroid Build Coastguard Worker #endif
412*27162e4eSAndroid Build Coastguard Worker 
413*27162e4eSAndroid Build Coastguard Worker #endif   /* LZ4_HC_SLO_098092834 */
414*27162e4eSAndroid Build Coastguard Worker #endif   /* LZ4_HC_STATIC_LINKING_ONLY */
415