]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/native/lz4.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.fastlz / native / lz4.h
diff --git a/bundles/org.simantics.fastlz/native/lz4.h b/bundles/org.simantics.fastlz/native/lz4.h
new file mode 100644 (file)
index 0000000..ebd62b6
--- /dev/null
@@ -0,0 +1,120 @@
+/*\r
+   LZ4 - Fast LZ compression algorithm\r
+   Header File\r
+   Copyright (C) 2011-2012, 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
+// Simple Functions\r
+//****************************\r
+\r
+int LZ4_compress   (const char* source, char* dest, int isize);\r
+int LZ4_uncompress (const char* source, char* dest, int osize);\r
+\r
+/*\r
+LZ4_compress() :\r
+       isize  : is the input size. Max supported value is ~1.9GB\r
+       return : the number of bytes written in buffer dest\r
+                        or 0 if the compression fails (if LZ4_COMPRESSMIN is set)\r
+       note : destination buffer must be already allocated.\r
+               destination buffer must be sized to handle worst cases situations (input data not compressible)\r
+               worst case size evaluation is provided by function LZ4_compressBound()\r
+\r
+LZ4_uncompress() :\r
+       osize  : is the output size, therefore the original size\r
+       return : the number of bytes read in the source buffer\r
+                        If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
+                        This function never writes beyond dest + osize, and is therefore protected against malicious data packets\r
+       note : destination buffer must be already allocated\r
+*/\r
+\r
+\r
+//****************************\r
+// Advanced Functions\r
+//****************************\r
+\r
+int LZ4_compressBound(int isize);\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
+\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
+\r
+int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);\r
+\r
+/*\r
+LZ4_uncompress_unknownOutputSize() :\r
+       isize  : is the input size, therefore the compressed size\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 malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction\r
+                        This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets\r
+       note   : Destination buffer must be already allocated.\r
+                This version is slightly slower than LZ4_uncompress()\r
+*/\r
+\r
+\r
+int LZ4_compressCtx(void** ctx, const char* source,  char* dest, int isize);\r
+int LZ4_compress64kCtx(void** ctx, const char* source,  char* dest, int isize);\r
+\r
+/*\r
+LZ4_compressCtx() :\r
+       This function explicitly handles the CTX memory structure.\r
+       It avoids allocating/deallocating memory between each call, improving performance when malloc is heavily invoked.\r
+       This function is only useful when memory is allocated into the heap (HASH_LOG value beyond STACK_LIMIT)\r
+       Performance difference will be noticeable only when repetitively calling the compression function over many small segments.\r
+       Note : by default, memory is allocated into the stack, therefore "malloc" is not invoked.\r
+LZ4_compress64kCtx() :\r
+       Same as LZ4_compressCtx(), but specific to small inputs (<64KB).\r
+       isize *Must* be <64KB, otherwise the output will be corrupted.\r
+\r
+       On first call : provide a *ctx=NULL; It will be automatically allocated.\r
+       On next calls : reuse the same ctx pointer.\r
+       Use different pointers for different threads when doing multi-threading.\r
+\r
+*/\r
+\r
+\r
+#if defined (__cplusplus)\r
+}\r
+#endif\r