benchmark silo added
[c11concurrency-benchmarks.git] / silo / third-party / lz4 / lz4.h
1 /*\r
2    LZ4 - Fast LZ compression algorithm\r
3    Header File\r
4    Copyright (C) 2011-2013, Yann Collet.\r
5    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
6 \r
7    Redistribution and use in source and binary forms, with or without\r
8    modification, are permitted provided that the following conditions are\r
9    met:\r
10 \r
11        * Redistributions of source code must retain the above copyright\r
12    notice, this list of conditions and the following disclaimer.\r
13        * Redistributions in binary form must reproduce the above\r
14    copyright notice, this list of conditions and the following disclaimer\r
15    in the documentation and/or other materials provided with the\r
16    distribution.\r
17 \r
18    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
19    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
20    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
21    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
22    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
26    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
28    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29 \r
30    You can contact the author at :\r
31    - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\r
32    - LZ4 source repository : http://code.google.com/p/lz4/\r
33 */\r
34 #pragma once\r
35 \r
36 #if defined (__cplusplus)\r
37 extern "C" {\r
38 #endif\r
39 \r
40 \r
41 //**************************************\r
42 // Compiler Options\r
43 //**************************************\r
44 #if defined(_MSC_VER) && !defined(__cplusplus)   // Visual Studio\r
45 #  define inline __inline           // Visual C is not C99, but supports some kind of inline\r
46 #endif\r
47 \r
48 \r
49 //****************************\r
50 // Simple Functions\r
51 //****************************\r
52 \r
53 int LZ4_compress        (const char* source, char* dest, int inputSize);\r
54 int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);\r
55 \r
56 /*\r
57 LZ4_compress() :\r
58     Compresses 'inputSize' bytes from 'source' into 'dest'.\r
59     Destination buffer must be already allocated,\r
60     and must be sized to handle worst cases situations (input data not compressible)\r
61     Worst case size evaluation is provided by function LZ4_compressBound()\r
62     inputSize : Max supported value is ~1.9GB\r
63     return : the number of bytes written in buffer dest\r
64              or 0 if the compression fails\r
65 \r
66 LZ4_decompress_safe() :\r
67     maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
68     return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
69              If the source stream is detected malformed, the function will stop decoding and return a negative result.\r
70              This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets\r
71 */\r
72 \r
73 \r
74 //****************************\r
75 // Advanced Functions\r
76 //****************************\r
77 \r
78 static inline int LZ4_compressBound(int isize)   { return ((isize) + ((isize)/255) + 16); }\r
79 #define           LZ4_COMPRESSBOUND(    isize)            ((isize) + ((isize)/255) + 16)\r
80 \r
81 /*\r
82 LZ4_compressBound() :\r
83     Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)\r
84     primarily useful for memory allocation of output buffer.\r
85     inline function is recommended for the general case,\r
86     macro is also provided when result needs to be evaluated at compilation (such as table size allocation).\r
87 \r
88     isize  : is the input size. Max supported value is ~1.9GB\r
89     return : maximum output size in a "worst case" scenario\r
90     note : this function is limited by "int" range (2^31-1)\r
91 */\r
92 \r
93 static inline int\r
94 LZ4_compressBoundInv(int bound)\r
95 {\r
96   if (bound < 16)\r
97     return 0;\r
98   return 255 * (bound - 16) / 256;\r
99 }\r
100 \r
101 /*\r
102 LZ4_compressBoundInv() :\r
103     Given a output buffer size b, returns the maximum number of bytes\r
104     which can be compressed and still guarantee compressed output <= b\r
105 \r
106     returns 0 if bound is too small to compress anything useful\r
107 */\r
108 \r
109 int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);\r
110 \r
111 /*\r
112 LZ4_compress_limitedOutput() :\r
113     Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.\r
114     If it cannot achieve it, compression will stop, and result of the function will be zero.\r
115     This function never writes outside of provided output buffer.\r
116 \r
117     inputSize  : Max supported value is ~1.9GB\r
118     maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
119     return : the number of bytes written in buffer 'dest'\r
120              or 0 if the compression fails\r
121 */\r
122 \r
123 \r
124 int LZ4_decompress_fast (const char* source, char* dest, int outputSize);\r
125 \r
126 /*\r
127 LZ4_decompress_fast() :\r
128     outputSize : is the original (uncompressed) size\r
129     return : the number of bytes read from the source buffer (in other words, the compressed size)\r
130              If the source stream is malformed, the function will stop decoding and return a negative result.\r
131     note : This function is a bit faster than LZ4_decompress_safe()\r
132            This function never writes outside of output buffers, and never read before input buffer, but may read beyond input buffer (since it doesn't know its size) in case of malicious data packet.\r
133            Use this function preferably into a trusted environment (data to decode comes from a trusted source).\r
134            Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.\r
135 */\r
136 \r
137 int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);\r
138 \r
139 /*\r
140 LZ4_decompress_safe_partial() :\r
141     This function decompress a compressed block of size 'inputSize' at position 'source'\r
142     into output buffer 'dest' of size 'maxOutputSize'.\r
143     The function stops decompressing operation as soon as 'targetOutputSize' has been reached,\r
144     reducing decompression time.\r
145     return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
146        Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.\r
147              Always control how many bytes were decoded.\r
148              If the source stream is malformed, the function will stop decoding and return a negative result.\r
149              This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets\r
150 */\r
151 \r
152 \r
153 int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);\r
154 int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);\r
155 \r
156 /*\r
157 *_withPrefix64k() :\r
158     These decoding functions work the same as their "normal name" versions,\r
159     but will potentially use up to 64KB of data in front of 'char* dest'.\r
160     These functions are used for decoding inter-dependant blocks.\r
161 */\r
162 \r
163 //****************************\r
164 // Exposed Functions\r
165 //****************************\r
166 \r
167 void*    LZ4_create();\r
168 unsigned LZ4_create_size();\r
169 int      LZ4_free(void* ctx);\r
170 \r
171 int LZ4_compress_heap(\r
172                  void* ctx,\r
173                  const char* source,\r
174                  char* dest,\r
175                  int inputSize);\r
176 \r
177 int LZ4_compress_heap_limitedOutput(\r
178                  void* ctx,\r
179                  const char* source,\r
180                  char* dest,\r
181                  int inputSize,\r
182                  int maxOutputSize);\r
183 \r
184 //****************************\r
185 // Obsolete Functions\r
186 //****************************\r
187 \r
188 static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }\r
189 static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }\r
190 \r
191 /*\r
192 These functions are deprecated and should no longer be used.\r
193 They are provided here for compatibility with existing user programs.\r
194 */\r
195 \r
196 \r
197 \r
198 #if defined (__cplusplus)\r
199 }\r
200 #endif\r