ROOTANA
Loading...
Searching...
No Matches
mlz4hc.h
Go to the documentation of this file.
1/*
2 LZ4 HC - High Compression Mode of LZ4
3 Header File
4 Copyright (C) 2011-2015, 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/Cyan4973/lz4
32 - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
33*/
34#pragma once
35
36
37//#if defined (__cplusplus)
38//extern "C" {
39//#endif
40
41/*****************************
42* Includes
43*****************************/
44#include <stddef.h> /* size_t */
45
46
47/**************************************
48* Block Compression
49**************************************/
50int MLZ4_compress_HC (const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
51/*
52MLZ4_compress_HC :
53 Destination buffer 'dst' must be already allocated.
54 Compression completion is guaranteed if 'dst' buffer is sized to handle worst circumstances (data not compressible)
55 Worst size evaluation is provided by function MLZ4_compressBound() (see "lz4.h")
56 srcSize : Max supported value is MLZ4_MAX_INPUT_SIZE (see "lz4.h")
57 compressionLevel : Recommended values are between 4 and 9, although any value between 0 and 16 will work.
58 0 means "use default value" (see lz4hc.c).
59 Values >16 behave the same as 16.
60 return : the number of bytes written into buffer 'dst'
61 or 0 if compression fails.
62*/
63
64
65/* Note :
66 Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
67*/
68
69
70int MLZ4_sizeofStateHC(void);
71int MLZ4_compress_HC_extStateHC(void* state, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
72/*
73MLZ4_compress_HC_extStateHC() :
74 Use this function if you prefer to manually allocate memory for compression tables.
75 To know how much memory must be allocated for the compression tables, use :
76 int MLZ4_sizeofStateHC();
77
78 Allocated memory must be aligned on 8-bytes boundaries (which a normal malloc() will do properly).
79
80 The allocated memory can then be provided to the compression functions using 'void* state' parameter.
81 MLZ4_compress_HC_extStateHC() is equivalent to previously described function.
82 It just uses externally allocated memory for stateHC.
83*/
84
85
86/**************************************
87* Streaming Compression
88**************************************/
89#define MLZ4_STREAMHCSIZE 262192
90#define MLZ4_STREAMHCSIZE_SIZET (MLZ4_STREAMHCSIZE / sizeof(size_t))
91typedef struct { size_t table[MLZ4_STREAMHCSIZE_SIZET]; } MLZ4_streamHC_t;
92/*
93 MLZ4_streamHC_t
94 This structure allows static allocation of LZ4 HC streaming state.
95 State must then be initialized using MLZ4_resetStreamHC() before first use.
96
97 Static allocation should only be used in combination with static linking.
98 If you want to use LZ4 as a DLL, please use construction functions below, which are future-proof.
99*/
100
101
103int MLZ4_freeStreamHC (MLZ4_streamHC_t* streamHCPtr);
104/*
105 These functions create and release memory for LZ4 HC streaming state.
106 Newly created states are already initialized.
107 Existing state space can be re-used anytime using MLZ4_resetStreamHC().
108 If you use LZ4 as a DLL, use these functions instead of static structure allocation,
109 to avoid size mismatch between different versions.
110*/
111
113int MLZ4_loadDictHC (MLZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
114
115int MLZ4_compress_HC_continue (MLZ4_streamHC_t* streamHCPtr, const char* src, char* dst, int srcSize, int maxDstSize);
116
117int MLZ4_saveDictHC (MLZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
118
119/*
120 These functions compress data in successive blocks of any size, using previous blocks as dictionary.
121 One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
122 There is an exception for ring buffers, which can be smaller 64 KB.
123 Such case is automatically detected and correctly handled by MLZ4_compress_HC_continue().
124
125 Before starting compression, state must be properly initialized, using MLZ4_resetStreamHC().
126 A first "fictional block" can then be designated as initial dictionary, using MLZ4_loadDictHC() (Optional).
127
128 Then, use MLZ4_compress_HC_continue() to compress each successive block.
129 It works like MLZ4_compress_HC(), but use previous memory blocks as dictionary to improve compression.
130 Previous memory blocks (including initial dictionary when present) must remain accessible and unmodified during compression.
131 As a reminder, size 'dst' buffer to handle worst cases, using MLZ4_compressBound(), to ensure success of compression operation.
132
133 If, for any reason, previous data blocks can't be preserved unmodified in memory during next compression block,
134 you must save it to a safer memory space, using MLZ4_saveDictHC().
135 Return value of MLZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer'.
136*/
137
138
139
140/**************************************
141* Deprecated Functions
142**************************************/
143/* Deprecate Warnings */
144/* Should these warnings messages be a problem,
145 it is generally possible to disable them,
146 with -Wno-deprecated-declarations for gcc
147 or _CRT_SECURE_NO_WARNINGS in Visual for example.
148 You can also define MLZ4_DEPRECATE_WARNING_DEFBLOCK. */
149#ifndef MLZ4_DEPRECATE_WARNING_DEFBLOCK
150# define MLZ4_DEPRECATE_WARNING_DEFBLOCK
151# define MLZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
152# if (MLZ4_GCC_VERSION >= 405) || defined(__clang__)
153# define MLZ4_DEPRECATED(message) __attribute__((deprecated(message)))
154# elif (MLZ4_GCC_VERSION >= 301)
155# define MLZ4_DEPRECATED(message) __attribute__((deprecated))
156# elif defined(_MSC_VER)
157# define MLZ4_DEPRECATED(message) __declspec(deprecated(message))
158# else
159# pragma message("WARNING: You need to implement MLZ4_DEPRECATED for this compiler")
160# define MLZ4_DEPRECATED(message)
161# endif
162#endif // MLZ4_DEPRECATE_WARNING_DEFBLOCK
163
164/* compression functions */
165/* these functions are planned to trigger warning messages by r131 approximately */
166int MLZ4_compressHC (const char* source, char* dest, int inputSize);
167int MLZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
168int MLZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
170int MLZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
171int MLZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
172int MLZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
173int MLZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
174int MLZ4_compressHC_continue (MLZ4_streamHC_t* MLZ4_streamHCPtr, const char* source, char* dest, int inputSize);
175int MLZ4_compressHC_limitedOutput_continue (MLZ4_streamHC_t* MLZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
176
177/* Streaming functions following the older model; should no longer be used */
178MLZ4_DEPRECATED("use MLZ4_createStreamHC() instead") void* MLZ4_createHC (char* inputBuffer);
179MLZ4_DEPRECATED("use MLZ4_saveDictHC() instead") char* MLZ4_slideInputBufferHC (void* LZ4HC_Data);
180MLZ4_DEPRECATED("use MLZ4_freeStreamHC() instead") int MLZ4_freeHC (void* LZ4HC_Data);
181MLZ4_DEPRECATED("use MLZ4_compress_HC_continue() instead") int MLZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
185
186
187//#if defined (__cplusplus)
188//}
189//#endif
char int int maxDstSize
Definition mlz4.h:354
char * dst
Definition mlz4.h:354
int MLZ4_compressHC_limitedOutput(const char *source, char *dest, int inputSize, int maxOutputSize)
Definition lz4hc.cxx:678
const char * source
Definition mlz4hc.h:181
int MLZ4_compressHC_limitedOutput_continue(MLZ4_streamHC_t *MLZ4_streamHCPtr, const char *source, char *dest, int inputSize, int maxOutputSize)
Definition lz4hc.cxx:686
MLZ4_streamHC_t * MLZ4_createStreamHC(void)
Definition lz4hc.cxx:562
#define MLZ4_DEPRECATED(message)
Definition mlz4hc.h:160
const char char int int maxOutputSize
Definition mlz4hc.h:182
int MLZ4_compressHC2(const char *source, char *dest, int inputSize, int compressionLevel)
Definition lz4hc.cxx:679
int MLZ4_saveDictHC(MLZ4_streamHC_t *streamHCPtr, char *safeBuffer, int maxDictSize)
Definition lz4hc.cxx:652
int MLZ4_compressHC_limitedOutput_withStateHC(void *state, const char *source, char *dest, int inputSize, int maxOutputSize)
Definition lz4hc.cxx:682
int MLZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
Definition lz4hc.cxx:540
void MLZ4_resetStreamHC(MLZ4_streamHC_t *streamHCPtr, int compressionLevel)
Definition lz4hc.cxx:567
int MLZ4_compressHC2_limitedOutput(const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel)
Definition lz4hc.cxx:680
int MLZ4_compressHC_withStateHC(void *state, const char *source, char *dest, int inputSize)
Definition lz4hc.cxx:681
#define MLZ4_STREAMHCSIZE_SIZET
Definition mlz4hc.h:90
char * inputBuffer
Definition mlz4hc.h:184
int MLZ4_compressHC_continue(MLZ4_streamHC_t *MLZ4_streamHCPtr, const char *source, char *dest, int inputSize)
Definition lz4hc.cxx:685
const char char int inputSize
Definition mlz4hc.h:181
int MLZ4_sizeofStateHC(void)
Definition lz4hc.cxx:538
const char char int int compressionLevel
Definition mlz4hc.h:181
int MLZ4_compress_HC_continue(MLZ4_streamHC_t *streamHCPtr, const char *src, char *dst, int srcSize, int maxDstSize)
Definition lz4hc.cxx:641
int MLZ4_compress_HC(const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
Definition lz4hc.cxx:550
int MLZ4_compressHC2_withStateHC(void *state, const char *source, char *dest, int inputSize, int compressionLevel)
Definition lz4hc.cxx:683
const char char * dest
Definition mlz4hc.h:181
int MLZ4_compressHC(const char *source, char *dest, int inputSize)
Definition lz4hc.cxx:677
int MLZ4_loadDictHC(MLZ4_streamHC_t *streamHCPtr, const char *dictionary, int dictSize)
Definition lz4hc.cxx:574
int MLZ4_compressHC2_limitedOutput_withStateHC(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel)
Definition lz4hc.cxx:684
int MLZ4_freeStreamHC(MLZ4_streamHC_t *streamHCPtr)
Definition lz4hc.cxx:563
int MLZ4_compressHC2_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int compressionLevel)
Definition lz4hc.cxx:716
char * MLZ4_slideInputBufferHC(void *LZ4HC_Data)
Definition lz4hc.cxx:726
int MLZ4_resetStreamStateHC(void *state, char *inputBuffer)
Definition lz4hc.cxx:693
int MLZ4_freeHC(void *LZ4HC_Data)
Definition lz4hc.cxx:710
int MLZ4_sizeofStreamStateHC(void)
Definition lz4hc.cxx:691
void * MLZ4_createHC(char *inputBuffer)
Definition lz4hc.cxx:701
int MLZ4_compressHC2_limitedOutput_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel)
Definition lz4hc.cxx:721