benchmark silo added
[c11concurrency-benchmarks.git] / silo / third-party / lz4 / lz4.h
diff --git a/silo/third-party/lz4/lz4.h b/silo/third-party/lz4/lz4.h
new file mode 100644 (file)
index 0000000..70c1c4a
--- /dev/null
@@ -0,0 +1,200 @@
+/*\r
+   LZ4 - Fast LZ compression algorithm\r
+   Header File\r
+   Copyright (C) 2011-2013, Yann Collet.\r
+   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
+\r
+   Redistribution and use in source and binary forms, with or without\r
+   modification, are permitted provided that the following conditions are\r
+   met:\r
+\r
+       * Redistributions of source code must retain the above copyright\r
+   notice, this list of conditions and the following disclaimer.\r
+       * Redistributions in binary form must reproduce the above\r
+   copyright notice, this list of conditions and the following disclaimer\r
+   in the documentation and/or other materials provided with the\r
+   distribution.\r
+\r
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+   You can contact the author at :\r
+   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\r
+   - LZ4 source repository : http://code.google.com/p/lz4/\r
+*/\r
+#pragma once\r
+\r
+#if defined (__cplusplus)\r
+extern "C" {\r
+#endif\r
+\r
+\r
+//**************************************\r
+// Compiler Options\r
+//**************************************\r
+#if defined(_MSC_VER) && !defined(__cplusplus)   // Visual Studio\r
+#  define inline __inline           // Visual C is not C99, but supports some kind of inline\r
+#endif\r
+\r
+\r
+//****************************\r
+// Simple Functions\r
+//****************************\r
+\r
+int LZ4_compress        (const char* source, char* dest, int inputSize);\r
+int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);\r
+\r
+/*\r
+LZ4_compress() :\r
+    Compresses 'inputSize' bytes from 'source' into 'dest'.\r
+    Destination buffer must be already allocated,\r
+    and must be sized to handle worst cases situations (input data not compressible)\r
+    Worst case size evaluation is provided by function LZ4_compressBound()\r
+    inputSize : Max supported value is ~1.9GB\r
+    return : the number of bytes written in buffer dest\r
+             or 0 if the compression fails\r
+\r
+LZ4_decompress_safe() :\r
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
+             If the source stream is detected malformed, the function will stop decoding and return a negative result.\r
+             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
+*/\r
+\r
+\r
+//****************************\r
+// Advanced Functions\r
+//****************************\r
+\r
+static inline int LZ4_compressBound(int isize)   { return ((isize) + ((isize)/255) + 16); }\r
+#define           LZ4_COMPRESSBOUND(    isize)            ((isize) + ((isize)/255) + 16)\r
+\r
+/*\r
+LZ4_compressBound() :\r
+    Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)\r
+    primarily useful for memory allocation of output buffer.\r
+    inline function is recommended for the general case,\r
+    macro is also provided when result needs to be evaluated at compilation (such as table size allocation).\r
+\r
+    isize  : is the input size. Max supported value is ~1.9GB\r
+    return : maximum output size in a "worst case" scenario\r
+    note : this function is limited by "int" range (2^31-1)\r
+*/\r
+\r
+static inline int\r
+LZ4_compressBoundInv(int bound)\r
+{\r
+  if (bound < 16)\r
+    return 0;\r
+  return 255 * (bound - 16) / 256;\r
+}\r
+\r
+/*\r
+LZ4_compressBoundInv() :\r
+    Given a output buffer size b, returns the maximum number of bytes\r
+    which can be compressed and still guarantee compressed output <= b\r
+\r
+    returns 0 if bound is too small to compress anything useful\r
+*/\r
+\r
+int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);\r
+\r
+/*\r
+LZ4_compress_limitedOutput() :\r
+    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.\r
+    If it cannot achieve it, compression will stop, and result of the function will be zero.\r
+    This function never writes outside of provided output buffer.\r
+\r
+    inputSize  : Max supported value is ~1.9GB\r
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
+    return : the number of bytes written in buffer 'dest'\r
+             or 0 if the compression fails\r
+*/\r
+\r
+\r
+int LZ4_decompress_fast (const char* source, char* dest, int outputSize);\r
+\r
+/*\r
+LZ4_decompress_fast() :\r
+    outputSize : is the original (uncompressed) size\r
+    return : the number of bytes read from the source buffer (in other words, the compressed size)\r
+             If the source stream is malformed, the function will stop decoding and return a negative result.\r
+    note : This function is a bit faster than LZ4_decompress_safe()\r
+           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
+           Use this function preferably into a trusted environment (data to decode comes from a trusted source).\r
+           Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.\r
+*/\r
+\r
+int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);\r
+\r
+/*\r
+LZ4_decompress_safe_partial() :\r
+    This function decompress a compressed block of size 'inputSize' at position 'source'\r
+    into output buffer 'dest' of size 'maxOutputSize'.\r
+    The function stops decompressing operation as soon as 'targetOutputSize' has been reached,\r
+    reducing decompression time.\r
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
+       Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.\r
+             Always control how many bytes were decoded.\r
+             If the source stream is malformed, the function will stop decoding and return a negative result.\r
+             This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets\r
+*/\r
+\r
+\r
+int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);\r
+int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);\r
+\r
+/*\r
+*_withPrefix64k() :\r
+    These decoding functions work the same as their "normal name" versions,\r
+    but will potentially use up to 64KB of data in front of 'char* dest'.\r
+    These functions are used for decoding inter-dependant blocks.\r
+*/\r
+\r
+//****************************\r
+// Exposed Functions\r
+//****************************\r
+\r
+void*    LZ4_create();\r
+unsigned LZ4_create_size();\r
+int      LZ4_free(void* ctx);\r
+\r
+int LZ4_compress_heap(\r
+                 void* ctx,\r
+                 const char* source,\r
+                 char* dest,\r
+                 int inputSize);\r
+\r
+int LZ4_compress_heap_limitedOutput(\r
+                 void* ctx,\r
+                 const char* source,\r
+                 char* dest,\r
+                 int inputSize,\r
+                 int maxOutputSize);\r
+\r
+//****************************\r
+// Obsolete Functions\r
+//****************************\r
+\r
+static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }\r
+static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }\r
+\r
+/*\r
+These functions are deprecated and should no longer be used.\r
+They are provided here for compatibility with existing user programs.\r
+*/\r
+\r
+\r
+\r
+#if defined (__cplusplus)\r
+}\r
+#endif\r