return true;\r
}\r
\r
- private static ByteBuffer ensureBufferSize(ByteBuffer buffer, int minCapacity) {\r
+ private ByteBuffer ensureBufferSize(ByteBuffer buffer, int minCapacity) {\r
int oldCapacity = buffer != null ? buffer.capacity() : 0;\r
if (buffer == null || oldCapacity < minCapacity) {\r
int newCapacity = grow(oldCapacity, minCapacity);\r
//System.out.println("ensureBufferSize(" + oldCapacity + ", " + minCapacity + "), new capacity " + newCapacity);\r
- buffer = ByteBuffer.allocateDirect(newCapacity);\r
+ buffer = allocateBuffer(newCapacity);\r
}\r
return buffer;\r
}\r
\r
+ protected ByteBuffer allocateBuffer(int capacity) {\r
+ return ByteBuffer.allocateDirect(capacity);\r
+ }\r
+ \r
/**\r
* @param oldCapacity current capacity of a buffer\r
* @param minCapacity\r
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-THE SOFTWARE.\r
-\r
-\r
-LZ4 native/lz4{,hc}.{c,h}\r
----------------------------------------------------------------------\r
- LZ4 - Fast LZ compression algorithm\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
+THE SOFTWARE.
\ No newline at end of file
The native/ -directory contains the sources for the\r
-native parts of the FastLZ and LZ4 compressions algorithms.\r
+native parts of the FastLZ compression algorithm.\r
\r
To compile in the native libraries follow these instructions:\r
\r
== Windows ==\r
\r
-* Install MS Visual Studio 2010 with C++ support and Microsoft SDK 7.1 to get 64-bit compiler\r
-* Open native/vs2010/fastlz.sln in visual studio\r
+* Install MS Visual Studio 2012 with C++ support and Microsoft Platform SDK for Windows Server 2003 R2 to get 64-bit compiler\r
+* Open native/vs2012/fastlz.sln in Visual Studio 2012\r
* Select ''Batch Build'' from the solution context menu, select Win32 + x64 Release and press ''Rebuild''\r
* The build will copy the resulting fastlz-windows-{x86,x86_64}.dll into src/\r
\r
+++ /dev/null
-OS := $(shell uname)
-
-ifeq ($(OS),Linux)
- OUTPUT32 = lz4demo32
- OUTPUT64 = lz4demo64
-else
- OUTPUT32 = LZ4Demo32.exe
- OUTPUT64 = LZ4Demo64.exe
-endif
-
-all: lz4demo64 lz4demo32
-
-lz4demo64: lz4.c lz4.h lz4hc.c lz4hc.h bench.c lz4demo.c
- gcc -O3 -I. -std=c99 -Wall -W -Wundef -Wno-implicit-function-declaration lz4hc.c lz4.c bench.c lz4demo.c -o $(OUTPUT64)
-
-lz4demo32: lz4.c lz4.h lz4hc.c lz4hc.h bench.c lz4demo.c
- gcc -m32 -Os -march=native -I. -std=c99 -Wall -W -Wundef -Wno-implicit-function-declaration lz4hc.c lz4.c bench.c lz4demo.c -o $(OUTPUT32)
-
-clean:
- rm -f core *.o $(OUTPUT32) $(OUTPUT64)
@rem ***************************************************************************\r
@echo off\r
\r
-cl /O2 /Oi /GL /I "%JAVA_HOME%/include/win32" /I "%JAVA_HOME%/include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "VC64_EXPORTS" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /EHsc /LD /Gy /GS- /W3 /nologo /c /Zi /TC /errorReport:prompt fastlz.c lz4.c lz4hc.c jniWrapper.c\r
+cl /O2 /Oi /GL /I "%JAVA_HOME%/include/win32" /I "%JAVA_HOME%/include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "VC64_EXPORTS" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /EHsc /LD /Gy /GS- /W3 /nologo /c /Zi /TC /errorReport:prompt fastlz.c jniWrapper.c\r
\r
-link /OUT:"..\src\fastlz-windows-x86_64.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"..\fastlz-windows-x86_64.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"fastlz-windows-x86_64.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X64 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fastlz.obj lz4.obj lz4hc.obj jniWrapper.obj \r
+link /OUT:"..\src\fastlz-windows-x86_64.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"..\fastlz-windows-x86_64.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"fastlz-windows-x86_64.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X64 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fastlz.obj jniWrapper.obj \r
@rem ***************************************************************************\r
@echo off\r
\r
-cl /O2 /Oi /GL /I "%JAVA_HOME%/include/win32" /I "%JAVA_HOME%/include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /EHsc /LD /Gy /GS- /W3 /nologo /c /Zi /TC /errorReport:prompt fastlz.c lz4.c lz4hc.c jniWrapper.c\r
+cl /O2 /Oi /GL /I "%JAVA_HOME%/include/win32" /I "%JAVA_HOME%/include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /EHsc /LD /Gy /GS- /W3 /nologo /c /Zi /TC /errorReport:prompt fastlz.c jniWrapper.c\r
\r
-link /OUT:"..\src\fastlz-windows-x86.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"..\fastlz-windows-x86.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"fastlz-windows-x86.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fastlz.obj lz4.obj lz4hc.obj jniWrapper.obj \r
+link /OUT:"..\src\fastlz-windows-x86.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"..\fastlz-windows-x86.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"fastlz-windows-x86.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib fastlz.obj jniWrapper.obj \r
@rem Contributors:\r
@rem VTT Technical Research Centre of Finland - initial API and implementation\r
@rem ***************************************************************************\r
-rem gcc -mno-cygwin "-I$jdk/include" "-I$jdk$jdk/include/win32" -Wl,--add-stdcall-alias -shared -o ../src/fastlz-windows-x86.dll fastlz.c lz4.c lz4hc.c jniWrapper.c\r
-gcc -mno-cygwin "-I%JAVA_HOME%/include" "-I%JAVA_HOME%/include/win32" -Wl,--add-stdcall-alias -shared -o ../src/fastlz-windows-x86.dll fastlz.c lz4.c lz4hc.c jniWrapper.c\r
+rem gcc -mno-cygwin "-I$jdk/include" "-I$jdk$jdk/include/win32" -Wl,--add-stdcall-alias -shared -o ../src/fastlz-windows-x86.dll fastlz.c jniWrapper.c\r
+gcc -mno-cygwin "-I%JAVA_HOME%/include" "-I%JAVA_HOME%/include/win32" -Wl,--add-stdcall-alias -shared -o ../src/fastlz-windows-x86.dll fastlz.c jniWrapper.c\r
gcc -o fastlz_test.exe fastlz.c fastlz_read.c fastlz_write.c fastlz_test.c\r
case $kernel in
darwin*)
- output="${output}.jnilib"
+ output="${output}.dylib"
;;
*)
output="${output}.so"
echo "Output library: $output"
echo "Compiler options: $options"
-gcc ${options} -o ${output} fastlz.c lz4.c lz4hc.c jniWrapper.c
+gcc ${options} -o ${output} fastlz.c jniWrapper.c
size=`ls -l $output | cut -d " " -f 5`
echo "library size before stripping: $size"
\r
}\r
\r
-JNIEXPORT jint JNICALL Java_org_simantics_fastlz_LZ4_compress(JNIEnv* env, jclass clazz, \r
- jobject input, jint inputOffset, jint length, \r
- jobject output, jint outputOffset) {\r
- void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset;\r
- void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset;\r
- return LZ4_compress(inputAddress, outputAddress, length);\r
-}\r
-\r
-JNIEXPORT jint JNICALL Java_org_simantics_fastlz_LZ4_decompress(JNIEnv* env, jclass clazz, \r
- jobject input, jint inputOffset, jint length, \r
- jobject output, jint outputOffset, jint maxout) {\r
- void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset;\r
- void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset;\r
- return LZ4_uncompress_unknownOutputSize(inputAddress, outputAddress, length, maxout);\r
-}\r
-\r
-JNIEXPORT jint JNICALL Java_org_simantics_fastlz_LZ4_decompressCluster(JNIEnv* env, jclass clazz, jobject deflated, jint deflatedSize, jint inflatedSize, jobjectArray arrays) {\r
-\r
- static char *inflateBuffer = 0;\r
- static int inflateBufferSize = 0;\r
-\r
- int ll, il, bl;\r
-\r
- jlongArray longs;\r
- jintArray ints;\r
- jbyteArray bytes;\r
-\r
- char *input = (char*)(*env)->GetDirectBufferAddress(env, deflated);\r
- char *address;\r
-\r
- if(inflateBufferSize < inflatedSize) {\r
- if(!inflateBuffer) {\r
- if(inflatedSize < INITIAL_SIZE) inflatedSize = INITIAL_SIZE;\r
- inflateBuffer = malloc(inflatedSize);\r
- inflateBufferSize = inflatedSize;\r
- } else {\r
- if(inflateBuffer) free(inflateBuffer);\r
- inflateBuffer = malloc(inflatedSize);\r
- inflateBufferSize = inflatedSize;\r
- }\r
- }\r
-\r
- address = inflateBuffer;\r
-\r
- LZ4_uncompress_unknownOutputSize(input, inflateBuffer, deflatedSize, inflateBufferSize);\r
-\r
- ll = *(int *)address;\r
- longs = (*env)->NewLongArray(env, ll);\r
- (*env)->SetLongArrayRegion(env, longs, 0, ll, (const jlong *)(address + 4));\r
- (*env)->SetObjectArrayElement(env, arrays, 0, longs);\r
-\r
- address += 4 + 8 * ll;\r
-\r
- il = *(int *)address;\r
- ints = (*env)->NewIntArray(env, il);\r
- (*env)->SetIntArrayRegion(env, ints, 0, il, (const jint *)(address + 4));\r
- (*env)->SetObjectArrayElement(env, arrays, 1, ints);\r
-\r
- address += 4 * il + 4;\r
-\r
- bl = *(int *)address;\r
- bytes = (*env)->NewByteArray(env, bl);\r
- (*env)->SetByteArrayRegion(env, bytes, 0, bl, (const jbyte *)(address + 4));\r
- (*env)->SetObjectArrayElement(env, arrays, 2, bytes);\r
-\r
- return 0;\r
-\r
-}\r
+++ /dev/null
-/*\r
- LZ4 - Fast LZ compression algorithm\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
-\r
-//**************************************\r
-// Tuning parameters\r
-//**************************************\r
-// COMPRESSIONLEVEL :\r
-// Increasing this value improves compression ratio\r
-// Lowering this value reduces memory usage\r
-// Reduced memory usage typically improves speed, due to cache effect (ex : L1 32KB for Intel, L1 64KB for AMD)\r
-// Memory usage formula : N->2^(N+2) Bytes (examples : 12 -> 16KB ; 17 -> 512KB)\r
-#define COMPRESSIONLEVEL 12\r
-\r
-// NOTCOMPRESSIBLE_CONFIRMATION :\r
-// Decreasing this value will make the algorithm skip faster data segments considered "incompressible"\r
-// This may decrease compression ratio dramatically, but will be faster on incompressible data\r
-// Increasing this value will make the algorithm search more before declaring a segment "incompressible"\r
-// This could improve compression a bit, but will be slower on incompressible data\r
-// The default value (6) is recommended\r
-#define NOTCOMPRESSIBLE_CONFIRMATION 6\r
-\r
-// LZ4_COMPRESSMIN :\r
-// Compression function will *fail* if it is not successful at compressing input by at least LZ4_COMPRESSMIN bytes\r
-// Since the compression function stops working prematurely, it results in a speed gain\r
-// The output however is unusable. Compression function result will be zero.\r
-// Default : 0 = disabled\r
-#define LZ4_COMPRESSMIN 0\r
-\r
-// BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE :\r
-// This will provide a boost to performance for big endian cpu, but the resulting compressed stream will be incompatible with little-endian CPU.\r
-// You can set this option to 1 in situations where data will stay within closed environment\r
-// This option is useless on Little_Endian CPU (such as x86)\r
-//#define BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE 1\r
-\r
-\r
-\r
-//**************************************\r
-// CPU Feature Detection\r
-//**************************************\r
-// 32 or 64 bits ?\r
-#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(__ppc64__) || defined(_WIN64) || defined(__LP64__) || defined(_LP64) ) // Detects 64 bits mode\r
-# define LZ4_ARCH64 1\r
-#else\r
-# define LZ4_ARCH64 0\r
-#endif\r
-\r
-// Little Endian or Big Endian ?\r
-// Note : overwrite the below #define if you know your architecture endianess\r
-#if (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(_ARCH_PPC) || defined(__PPC__) || defined(__PPC) || defined(PPC) || defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || ((defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) )\r
-# define LZ4_BIG_ENDIAN 1\r
-#else\r
-// Little Endian assumed. PDP Endian and other very rare endian format are unsupported.\r
-#endif\r
-\r
-// Unaligned memory access is automatically enabled for "common" CPU, such as x86.\r
-// For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected\r
-// If you know your target CPU supports unaligned memory access, you may want to force this option manually to improve performance\r
-#if defined(__ARM_FEATURE_UNALIGNED)\r
-# define LZ4_FORCE_UNALIGNED_ACCESS 1\r
-#endif\r
-\r
-// Define this parameter if your target system or compiler does not support hardware bit count\r
-#if defined(_MSC_VER) && defined(_WIN32_WCE) // Visual Studio for Windows CE does not support Hardware bit count\r
-# define LZ4_FORCE_SW_BITCOUNT\r
-#endif\r
-\r
-\r
-//**************************************\r
-// Compiler Options\r
-//**************************************\r
-#if __STDC_VERSION__ >= 199901L // C99\r
-/* "restrict" is a known keyword */\r
-#else\r
-# define restrict // Disable restrict\r
-#endif\r
-\r
-#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)\r
-\r
-#ifdef _MSC_VER // Visual Studio\r
-# define inline __forceinline // Visual is not C99, but supports some kind of inline\r
-# if LZ4_ARCH64 // 64-bit\r
-# pragma intrinsic(_BitScanForward64) // For Visual 2005\r
-# pragma intrinsic(_BitScanReverse64) // For Visual 2005\r
-# else\r
-# pragma intrinsic(_BitScanForward) // For Visual 2005\r
-# pragma intrinsic(_BitScanReverse) // For Visual 2005\r
-# endif\r
-#endif\r
-\r
-#ifdef _MSC_VER\r
-# define lz4_bswap16(x) _byteswap_ushort(x)\r
-#else\r
-# define lz4_bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))\r
-#endif\r
-\r
-#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)\r
-# define expect(expr,value) (__builtin_expect ((expr),(value)) )\r
-#else\r
-# define expect(expr,value) (expr)\r
-#endif\r
-\r
-#define likely(expr) expect((expr) != 0, 1)\r
-#define unlikely(expr) expect((expr) != 0, 0)\r
-\r
-\r
-//**************************************\r
-// Includes\r
-//**************************************\r
-#include <stdlib.h> // for malloc\r
-#include <string.h> // for memset\r
-#include "lz4.h"\r
-\r
-\r
-//**************************************\r
-// Basic Types\r
-//**************************************\r
-#if defined(_MSC_VER) // Visual Studio does not support 'stdint' natively\r
-# define BYTE unsigned __int8\r
-# define U16 unsigned __int16\r
-# define U32 unsigned __int32\r
-# define S32 __int32\r
-# define U64 unsigned __int64\r
-#else\r
-# include <stdint.h>\r
-# define BYTE uint8_t\r
-# define U16 uint16_t\r
-# define U32 uint32_t\r
-# define S32 int32_t\r
-# define U64 uint64_t\r
-#endif\r
-\r
-#ifndef LZ4_FORCE_UNALIGNED_ACCESS\r
-# pragma pack(push, 1)\r
-#endif\r
-\r
-typedef struct _U16_S { U16 v; } U16_S;\r
-typedef struct _U32_S { U32 v; } U32_S;\r
-typedef struct _U64_S { U64 v; } U64_S;\r
-\r
-#ifndef LZ4_FORCE_UNALIGNED_ACCESS\r
-# pragma pack(pop)\r
-#endif\r
-\r
-#define A64(x) (((U64_S *)(x))->v)\r
-#define A32(x) (((U32_S *)(x))->v)\r
-#define A16(x) (((U16_S *)(x))->v)\r
-\r
-\r
-//**************************************\r
-// Constants\r
-//**************************************\r
-#define MINMATCH 4\r
-\r
-#define HASH_LOG COMPRESSIONLEVEL\r
-#define HASHTABLESIZE (1 << HASH_LOG)\r
-#define HASH_MASK (HASHTABLESIZE - 1)\r
-\r
-#define SKIPSTRENGTH (NOTCOMPRESSIBLE_CONFIRMATION>2?NOTCOMPRESSIBLE_CONFIRMATION:2)\r
-#define STACKLIMIT 13\r
-#define HEAPMODE (HASH_LOG>STACKLIMIT) // Defines if memory is allocated into the stack (local variable), or into the heap (malloc()).\r
-#define COPYLENGTH 8\r
-#define LASTLITERALS 5\r
-#define MFLIMIT (COPYLENGTH+MINMATCH)\r
-#define MINLENGTH (MFLIMIT+1)\r
-\r
-#define MAXD_LOG 16\r
-#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)\r
-\r
-#define ML_BITS 4\r
-#define ML_MASK ((1U<<ML_BITS)-1)\r
-#define RUN_BITS (8-ML_BITS)\r
-#define RUN_MASK ((1U<<RUN_BITS)-1)\r
-\r
-\r
-//**************************************\r
-// Architecture-specific macros\r
-//**************************************\r
-#if LZ4_ARCH64 // 64-bit\r
-# define STEPSIZE 8\r
-# define UARCH U64\r
-# define AARCH A64\r
-# define LZ4_COPYSTEP(s,d) A64(d) = A64(s); d+=8; s+=8;\r
-# define LZ4_COPYPACKET(s,d) LZ4_COPYSTEP(s,d)\r
-# define LZ4_SECURECOPY(s,d,e) if (d<e) LZ4_WILDCOPY(s,d,e)\r
-# define HTYPE U32\r
-# define INITBASE(base) const BYTE* const base = ip\r
-#else // 32-bit\r
-# define STEPSIZE 4\r
-# define UARCH U32\r
-# define AARCH A32\r
-# define LZ4_COPYSTEP(s,d) A32(d) = A32(s); d+=4; s+=4;\r
-# define LZ4_COPYPACKET(s,d) LZ4_COPYSTEP(s,d); LZ4_COPYSTEP(s,d);\r
-# define LZ4_SECURECOPY LZ4_WILDCOPY\r
-# define HTYPE const BYTE*\r
-# define INITBASE(base) const int base = 0\r
-#endif\r
-\r
-#if (defined(LZ4_BIG_ENDIAN) && !defined(BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE))\r
-# define LZ4_READ_LITTLEENDIAN_16(d,s,p) { U16 v = A16(p); v = lz4_bswap16(v); d = (s) - v; }\r
-# define LZ4_WRITE_LITTLEENDIAN_16(p,i) { U16 v = (U16)(i); v = lz4_bswap16(v); A16(p) = v; p+=2; }\r
-#else // Little Endian\r
-# define LZ4_READ_LITTLEENDIAN_16(d,s,p) { d = (s) - A16(p); }\r
-# define LZ4_WRITE_LITTLEENDIAN_16(p,v) { A16(p) = v; p+=2; }\r
-#endif\r
-\r
-\r
-//**************************************\r
-// Local structures\r
-//**************************************\r
-struct refTables\r
-{\r
- HTYPE hashTable[HASHTABLESIZE];\r
-};\r
-\r
-\r
-//**************************************\r
-// Macros\r
-//**************************************\r
-#define LZ4_HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))\r
-#define LZ4_HASH_VALUE(p) LZ4_HASH_FUNCTION(A32(p))\r
-#define LZ4_WILDCOPY(s,d,e) do { LZ4_COPYPACKET(s,d) } while (d<e);\r
-#define LZ4_BLINDCOPY(s,d,l) { BYTE* e=(d)+l; LZ4_WILDCOPY(s,d,e); d=e; }\r
-\r
-\r
-//****************************\r
-// Private functions\r
-//****************************\r
-#if LZ4_ARCH64\r
-\r
-inline static int LZ4_NbCommonBytes (register U64 val)\r
-{\r
-#if defined(LZ4_BIG_ENDIAN)\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanReverse64( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_clzll(val) >> 3);\r
- #else\r
- int r;\r
- if (!(val>>32)) { r=4; } else { r=0; val>>=32; }\r
- if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }\r
- r += (!val);\r
- return r;\r
- #endif\r
-#else\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanForward64( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_ctzll(val) >> 3);\r
- #else\r
- static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };\r
- return DeBruijnBytePos[((U64)((val & -val) * 0x0218A392CDABBD3F)) >> 58];\r
- #endif\r
-#endif\r
-}\r
-\r
-#else\r
-\r
-inline static int LZ4_NbCommonBytes (register U32 val)\r
-{\r
-#if defined(LZ4_BIG_ENDIAN)\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanReverse( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_clz(val) >> 3);\r
- #else\r
- int r;\r
- if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }\r
- r += (!val);\r
- return r;\r
- #endif\r
-#else\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanForward( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_ctz(val) >> 3);\r
- #else\r
- static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };\r
- return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];\r
- #endif\r
-#endif\r
-}\r
-\r
-#endif\r
-\r
-\r
-//****************************\r
-// Public functions\r
-//****************************\r
-\r
-int LZ4_compressBound(int isize)\r
-{\r
- return (isize + (isize/255) + 16);\r
-}\r
-\r
-\r
-\r
-//******************************\r
-// Compression functions\r
-//******************************\r
-\r
-int LZ4_compressCtx(void** ctx,\r
- const char* source,\r
- char* dest,\r
- int isize)\r
-{\r
-#if HEAPMODE\r
- struct refTables *srt = (struct refTables *) (*ctx);\r
- HTYPE* HashTable;\r
-#else\r
- HTYPE HashTable[HASHTABLESIZE] = {0};\r
-#endif\r
-\r
- const BYTE* ip = (BYTE*) source;\r
- INITBASE(base);\r
- const BYTE* anchor = ip;\r
- const BYTE* const iend = ip + isize;\r
- const BYTE* const mflimit = iend - MFLIMIT;\r
-#define matchlimit (iend - LASTLITERALS)\r
-\r
- BYTE* op = (BYTE*) dest;\r
-\r
- int len, length;\r
- const int skipStrength = SKIPSTRENGTH;\r
- U32 forwardH;\r
-\r
-\r
- // Init\r
- if (isize<MINLENGTH) goto _last_literals;\r
-#if HEAPMODE\r
- if (*ctx == NULL)\r
- {\r
- srt = (struct refTables *) malloc ( sizeof(struct refTables) );\r
- *ctx = (void*) srt;\r
- }\r
- HashTable = (HTYPE*)(srt->hashTable);\r
- memset((void*)HashTable, 0, sizeof(srt->hashTable));\r
-#else\r
- (void) ctx;\r
-#endif\r
-\r
-\r
- // First Byte\r
- HashTable[LZ4_HASH_VALUE(ip)] = ip - base;\r
- ip++; forwardH = LZ4_HASH_VALUE(ip);\r
-\r
- // Main Loop\r
- for ( ; ; )\r
- {\r
- int findMatchAttempts = (1U << skipStrength) + 3;\r
- const BYTE* forwardIp = ip;\r
- const BYTE* ref;\r
- BYTE* token;\r
-\r
- // Find a match\r
- do {\r
- U32 h = forwardH;\r
- int step = findMatchAttempts++ >> skipStrength;\r
- ip = forwardIp;\r
- forwardIp = ip + step;\r
-\r
- if unlikely(forwardIp > mflimit) { goto _last_literals; }\r
-\r
- forwardH = LZ4_HASH_VALUE(forwardIp);\r
- ref = base + HashTable[h];\r
- HashTable[h] = ip - base;\r
-\r
- } while ((ref < ip - MAX_DISTANCE) || (A32(ref) != A32(ip)));\r
-\r
- // Catch up\r
- while ((ip>anchor) && (ref>(BYTE*)source) && unlikely(ip[-1]==ref[-1])) { ip--; ref--; }\r
-\r
- // Encode Literal length\r
- length = ip - anchor;\r
- token = op++;\r
- if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *op++ = 255; *op++ = (BYTE)len; }\r
- else *token = (length<<ML_BITS);\r
-\r
- // Copy Literals\r
- LZ4_BLINDCOPY(anchor, op, length);\r
-\r
-_next_match:\r
- // Encode Offset\r
- LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);\r
-\r
- // Start Counting\r
- ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified\r
- anchor = ip;\r
- while likely(ip<matchlimit-(STEPSIZE-1))\r
- {\r
- UARCH diff = AARCH(ref) ^ AARCH(ip);\r
- if (!diff) { ip+=STEPSIZE; ref+=STEPSIZE; continue; }\r
- ip += LZ4_NbCommonBytes(diff);\r
- goto _endCount;\r
- }\r
- if (LZ4_ARCH64) if ((ip<(matchlimit-3)) && (A32(ref) == A32(ip))) { ip+=4; ref+=4; }\r
- if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }\r
- if ((ip<matchlimit) && (*ref == *ip)) ip++;\r
-_endCount:\r
-\r
- // Encode MatchLength\r
- len = (ip - anchor);\r
- if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }\r
- else *token += len;\r
-\r
- // Test end of chunk\r
- if (ip > mflimit) { anchor = ip; break; }\r
-\r
- // Fill table\r
- HashTable[LZ4_HASH_VALUE(ip-2)] = ip - 2 - base;\r
-\r
- // Test next position\r
- ref = base + HashTable[LZ4_HASH_VALUE(ip)];\r
- HashTable[LZ4_HASH_VALUE(ip)] = ip - base;\r
- if ((ref > ip - (MAX_DISTANCE + 1)) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }\r
-\r
- // Prepare next loop\r
- anchor = ip++;\r
- forwardH = LZ4_HASH_VALUE(ip);\r
- }\r
-\r
-_last_literals:\r
- // Encode Last Literals\r
- {\r
- int lastRun = iend - anchor;\r
- if ((LZ4_COMPRESSMIN>0) && (((op - (BYTE*)dest) + lastRun + 1 + ((lastRun-15)/255)) > isize - LZ4_COMPRESSMIN)) return 0;\r
- if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }\r
- else *op++ = (lastRun<<ML_BITS);\r
- memcpy(op, anchor, iend - anchor);\r
- op += iend-anchor;\r
- }\r
-\r
- // End\r
- return (int) (((char*)op)-dest);\r
-}\r
-\r
-\r
-\r
-// Note : this function is valid only if isize < LZ4_64KLIMIT\r
-#define LZ4_64KLIMIT ((1<<16) + (MFLIMIT-1))\r
-#define HASHLOG64K (HASH_LOG+1)\r
-#define HASH64KTABLESIZE (1U<<HASHLOG64K)\r
-#define LZ4_HASH64K_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASHLOG64K))\r
-#define LZ4_HASH64K_VALUE(p) LZ4_HASH64K_FUNCTION(A32(p))\r
-int LZ4_compress64kCtx(void** ctx,\r
- const char* source,\r
- char* dest,\r
- int isize)\r
-{\r
-#if HEAPMODE\r
- struct refTables *srt = (struct refTables *) (*ctx);\r
- U16* HashTable;\r
-#else\r
- U16 HashTable[HASH64KTABLESIZE] = {0};\r
-#endif\r
-\r
- const BYTE* ip = (BYTE*) source;\r
- const BYTE* anchor = ip;\r
- const BYTE* const base = ip;\r
- const BYTE* const iend = ip + isize;\r
- const BYTE* const mflimit = iend - MFLIMIT;\r
-#define matchlimit (iend - LASTLITERALS)\r
-\r
- BYTE* op = (BYTE*) dest;\r
-\r
- int len, length;\r
- const int skipStrength = SKIPSTRENGTH;\r
- U32 forwardH;\r
-\r
-\r
- // Init\r
- if (isize<MINLENGTH) goto _last_literals;\r
-#if HEAPMODE\r
- if (*ctx == NULL)\r
- {\r
- srt = (struct refTables *) malloc ( sizeof(struct refTables) );\r
- *ctx = (void*) srt;\r
- }\r
- HashTable = (U16*)(srt->hashTable);\r
- memset((void*)HashTable, 0, sizeof(srt->hashTable));\r
-#else\r
- (void) ctx;\r
-#endif\r
-\r
-\r
- // First Byte\r
- ip++; forwardH = LZ4_HASH64K_VALUE(ip);\r
-\r
- // Main Loop\r
- for ( ; ; )\r
- {\r
- int findMatchAttempts = (1U << skipStrength) + 3;\r
- const BYTE* forwardIp = ip;\r
- const BYTE* ref;\r
- BYTE* token;\r
-\r
- // Find a match\r
- do {\r
- U32 h = forwardH;\r
- int step = findMatchAttempts++ >> skipStrength;\r
- ip = forwardIp;\r
- forwardIp = ip + step;\r
-\r
- if (forwardIp > mflimit) { goto _last_literals; }\r
-\r
- forwardH = LZ4_HASH64K_VALUE(forwardIp);\r
- ref = base + HashTable[h];\r
- HashTable[h] = ip - base;\r
-\r
- } while (A32(ref) != A32(ip));\r
-\r
- // Catch up\r
- while ((ip>anchor) && (ref>(BYTE*)source) && (ip[-1]==ref[-1])) { ip--; ref--; }\r
-\r
- // Encode Literal length\r
- length = ip - anchor;\r
- token = op++;\r
- if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *op++ = 255; *op++ = (BYTE)len; }\r
- else *token = (length<<ML_BITS);\r
-\r
- // Copy Literals\r
- LZ4_BLINDCOPY(anchor, op, length);\r
-\r
-_next_match:\r
- // Encode Offset\r
- LZ4_WRITE_LITTLEENDIAN_16(op,ip-ref);\r
-\r
- // Start Counting\r
- ip+=MINMATCH; ref+=MINMATCH; // MinMatch verified\r
- anchor = ip;\r
- while (ip<matchlimit-(STEPSIZE-1))\r
- {\r
- UARCH diff = AARCH(ref) ^ AARCH(ip);\r
- if (!diff) { ip+=STEPSIZE; ref+=STEPSIZE; continue; }\r
- ip += LZ4_NbCommonBytes(diff);\r
- goto _endCount;\r
- }\r
- if (LZ4_ARCH64) if ((ip<(matchlimit-3)) && (A32(ref) == A32(ip))) { ip+=4; ref+=4; }\r
- if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }\r
- if ((ip<matchlimit) && (*ref == *ip)) ip++;\r
-_endCount:\r
-\r
- // Encode MatchLength\r
- len = (ip - anchor);\r
- if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }\r
- else *token += len;\r
-\r
- // Test end of chunk\r
- if (ip > mflimit) { anchor = ip; break; }\r
-\r
- // Fill table\r
- HashTable[LZ4_HASH64K_VALUE(ip-2)] = ip - 2 - base;\r
-\r
- // Test next position\r
- ref = base + HashTable[LZ4_HASH64K_VALUE(ip)];\r
- HashTable[LZ4_HASH64K_VALUE(ip)] = ip - base;\r
- if (A32(ref) == A32(ip)) { token = op++; *token=0; goto _next_match; }\r
-\r
- // Prepare next loop\r
- anchor = ip++;\r
- forwardH = LZ4_HASH64K_VALUE(ip);\r
- }\r
-\r
-_last_literals:\r
- // Encode Last Literals\r
- {\r
- int lastRun = iend - anchor;\r
- if ((LZ4_COMPRESSMIN>0) && (((op - (BYTE*)dest) + lastRun + 1 + ((lastRun-15)/255)) > isize - LZ4_COMPRESSMIN)) return 0;\r
- if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }\r
- else *op++ = (lastRun<<ML_BITS);\r
- memcpy(op, anchor, iend - anchor);\r
- op += iend-anchor;\r
- }\r
-\r
- // End\r
- return (int) (((char*)op)-dest);\r
-}\r
-\r
-\r
-\r
-int LZ4_compress(const char* source,\r
- char* dest,\r
- int isize)\r
-{\r
-#if HEAPMODE\r
- void* ctx = malloc(sizeof(struct refTables));\r
- int result;\r
- if (isize < LZ4_64KLIMIT)\r
- result = LZ4_compress64kCtx(&ctx, source, dest, isize);\r
- else result = LZ4_compressCtx(&ctx, source, dest, isize);\r
- free(ctx);\r
- return result;\r
-#else\r
- if (isize < (int)LZ4_64KLIMIT) return LZ4_compress64kCtx(NULL, source, dest, isize);\r
- return LZ4_compressCtx(NULL, source, dest, isize);\r
-#endif\r
-}\r
-\r
-\r
-\r
-\r
-//****************************\r
-// Decompression functions\r
-//****************************\r
-\r
-// Note : The decoding functions LZ4_uncompress() and LZ4_uncompress_unknownOutputSize()\r
-// are safe against "buffer overflow" attack type.\r
-// They will never write nor read outside of the provided output buffers.\r
-// LZ4_uncompress_unknownOutputSize() also insures that it will never read outside of the input buffer.\r
-// A corrupted input will produce an error result, a negative int, indicating the position of the error within input stream.\r
-\r
-int LZ4_uncompress(const char* source,\r
- char* dest,\r
- int osize)\r
-{\r
- // Local Variables\r
- const BYTE* restrict ip = (const BYTE*) source;\r
- const BYTE* restrict ref;\r
-\r
- BYTE* restrict op = (BYTE*) dest;\r
- BYTE* const oend = op + osize;\r
- BYTE* cpy;\r
-\r
- BYTE token;\r
-\r
- int len, length;\r
- size_t dec[] ={0, 3, 2, 3, 0, 0, 0, 0};\r
-\r
-\r
- // Main Loop\r
- while (1)\r
- {\r
- // get runlength\r
- token = *ip++;\r
- if ((length=(token>>ML_BITS)) == RUN_MASK) { for (;(len=*ip++)==255;length+=255){} length += len; }\r
-\r
- // copy literals\r
- cpy = op+length;\r
- if unlikely(cpy>oend-COPYLENGTH)\r
- {\r
- if (cpy > oend) goto _output_error; // Error : request to write beyond destination buffer\r
- memcpy(op, ip, length);\r
- ip += length;\r
- break; // Necessarily EOF\r
- }\r
- LZ4_WILDCOPY(ip, op, cpy); ip -= (op-cpy); op = cpy;\r
-\r
- // get offset\r
- LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;\r
- if (ref < (BYTE* const)dest) goto _output_error; // Error : offset create reference outside destination buffer\r
-\r
- // get matchlength\r
- if ((length=(token&ML_MASK)) == ML_MASK) { for (;*ip==255;length+=255) {ip++;} length += *ip++; }\r
-\r
- // copy repeated sequence\r
- if unlikely(op-ref<STEPSIZE)\r
- {\r
-#if LZ4_ARCH64\r
- size_t dec2table[]={0, 0, 0, -1, 0, 1, 2, 3};\r
- size_t dec2 = dec2table[op-ref];\r
-#else\r
- const int dec2 = 0;\r
-#endif\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- ref -= dec[op-ref];\r
- A32(op)=A32(ref); op += STEPSIZE-4;\r
- ref -= dec2;\r
- } else { LZ4_COPYSTEP(ref,op); }\r
- cpy = op + length - (STEPSIZE-4);\r
- if (cpy>oend-COPYLENGTH)\r
- {\r
- if (cpy > oend) goto _output_error; // Error : request to write beyond destination buffer\r
- LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH));\r
- while(op<cpy) *op++=*ref++;\r
- op=cpy;\r
- if (op == oend) break; // Check EOF (should never happen, since last 5 bytes are supposed to be literals)\r
- continue;\r
- }\r
- LZ4_SECURECOPY(ref, op, cpy);\r
- op=cpy; // correction\r
- }\r
-\r
- // end of decoding\r
- return (int) (((char*)ip)-source);\r
-\r
- // write overflow error detected\r
-_output_error:\r
- return (int) (-(((char*)ip)-source));\r
-}\r
-\r
-\r
-int LZ4_uncompress_unknownOutputSize(\r
- const char* source,\r
- char* dest,\r
- int isize,\r
- int maxOutputSize)\r
-{\r
- // Local Variables\r
- const BYTE* restrict ip = (const BYTE*) source;\r
- const BYTE* const iend = ip + isize;\r
- const BYTE* restrict ref;\r
-\r
- BYTE* restrict op = (BYTE*) dest;\r
- BYTE* const oend = op + maxOutputSize;\r
- BYTE* cpy;\r
-\r
- size_t dec[] ={0, 3, 2, 3, 0, 0, 0, 0};\r
-\r
-\r
- // Main Loop\r
- while (ip<iend)\r
- {\r
- BYTE token;\r
- int length;\r
-\r
- // get runlength\r
- token = *ip++;\r
- if ((length=(token>>ML_BITS)) == RUN_MASK) { int s=255; while ((ip<iend) && (s==255)) { s=*ip++; length += s; } }\r
-\r
- // copy literals\r
- cpy = op+length;\r
- if ((cpy>oend-COPYLENGTH) || (ip+length>iend-COPYLENGTH))\r
- {\r
- if (cpy > oend) goto _output_error; // Error : request to write beyond destination buffer\r
- if (ip+length > iend) goto _output_error; // Error : request to read beyond source buffer\r
- memcpy(op, ip, length);\r
- op += length;\r
- ip += length;\r
- if (ip<iend) goto _output_error; // Error : LZ4 format violation\r
- break; // Necessarily EOF, due to parsing restrictions\r
- }\r
- LZ4_WILDCOPY(ip, op, cpy); ip -= (op-cpy); op = cpy;\r
-\r
- // get offset\r
- LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;\r
- if (ref < (BYTE* const)dest) goto _output_error; // Error : offset creates reference outside of destination buffer\r
-\r
- // get matchlength\r
- if ((length=(token&ML_MASK)) == ML_MASK) { while (ip<iend) { int s = *ip++; length +=s; if (s==255) continue; break; } }\r
-\r
- // copy repeated sequence\r
- if unlikely(op-ref<STEPSIZE)\r
- {\r
-#if LZ4_ARCH64\r
- size_t dec2table[]={0, 0, 0, -1, 0, 1, 2, 3};\r
- size_t dec2 = dec2table[op-ref];\r
-#else\r
- const int dec2 = 0;\r
-#endif\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- *op++ = *ref++;\r
- ref -= dec[op-ref];\r
- A32(op)=A32(ref); op += STEPSIZE-4;\r
- ref -= dec2;\r
- } else { LZ4_COPYSTEP(ref,op); }\r
- cpy = op + length - (STEPSIZE-4);\r
- if (cpy>oend-COPYLENGTH)\r
- {\r
- if (cpy > oend) goto _output_error; // Error : request to write outside of destination buffer\r
- LZ4_SECURECOPY(ref, op, (oend-COPYLENGTH));\r
- while(op<cpy) *op++=*ref++;\r
- op=cpy;\r
- if (op == oend) break; // Check EOF (should never happen, since last 5 bytes are supposed to be literals)\r
- continue;\r
- }\r
- LZ4_SECURECOPY(ref, op, cpy);\r
- op=cpy; // correction\r
- }\r
-\r
- // end of decoding\r
- return (int) (((char*)op)-dest);\r
-\r
- // write overflow error detected\r
-_output_error:\r
- return (int) (-(((char*)ip)-source));\r
-}\r
-\r
+++ /dev/null
-/*\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
+++ /dev/null
-LZ4 Format Description\r
-Last revised: 2012-02-27\r
-Author : Y. Collet\r
-\r
-\r
-\r
-This small specification intents to provide enough information\r
-to anyone willing to produce LZ4-compatible compressed streams\r
-using any programming language.\r
-\r
-LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.\r
-The most important design principle behind LZ4 is simplicity.\r
-It helps to create an easy to read and maintain source code.\r
-It also helps later on for optimisations, compactness, and speed.\r
-There is no entropy encoder backend nor framing layer.\r
-The latter is assumed to be handled by other parts of the system.\r
-\r
-This document only describes the format,\r
-not how the LZ4 compressor nor decompressor actually work.\r
-The correctness of the decompressor should not depend\r
-on implementation details of the compressor, and vice versa.\r
-\r
-\r
-\r
--- Compressed stream format --\r
-\r
-An LZ4 compressed stream is composed of sequences.\r
-Schematically, a sequence is a suite of literals, followed by a match copy.\r
-\r
-Each sequence starts with a token.\r
-The token is a one byte value, separated into two 4-bits fields.\r
-Therefore each field ranges from 0 to 15.\r
-\r
-\r
-The first field uses the 4 high-bits of the token.\r
-It provides the length of literals to follow.\r
-(Note : a literal is a not-compressed byte).\r
-If the field value is 0, then there is no literal.\r
-If it is 15, then we need to add some more bytes to indicate the full length.\r
-Each additionnal byte then represent a value from 0 to 255,\r
-which is added to the previous value to produce a total length.\r
-When the byte value is 255, another byte is output.\r
-There can be any number of bytes following the token. There is no "size limit".\r
-(Sidenote this is why a not-compressible input stream is expanded by 0.4%).\r
-\r
-Example 1 : A length of 48 will be represented as :\r
-- 15 : value for the 4-bits High field\r
-- 33 : (=48-15) remaining length to reach 48\r
-\r
-Example 2 : A length of 280 will be represented as :\r
-- 15 : value for the 4-bits High field\r
-- 255 : following byte is maxed, since 280-15 >= 255\r
-- 10 : (=280 - 15 - 255) ) remaining length to reach 280\r
-\r
-Example 3 : A length of 15 will be represented as :\r
-- 15 : value for the 4-bits High field\r
-- 0 : (=15-15) yes, the zero must be output\r
-\r
-Following the token and optional length bytes, are the literals themselves.\r
-They are exactly as numerous as previously decoded (length of literals).\r
-It's possible that there are zero literal.\r
-\r
-\r
-Following the literals is the match copy operation.\r
-\r
-It starts by the offset.\r
-This is a 2 bytes value, in little endian format :\r
-the lower byte is the first one in the stream.\r
-\r
-The offset represents the position of the match to be copied from.\r
-1 means "current position - 1 byte".\r
-The maximum offset value is 65535, 65536 cannot be coded.\r
-Note that 0 is an invalid value, not used. \r
-\r
-Then we need to extract the match length.\r
-For this, we use the second token field, the low 4-bits.\r
-Value, obviously, ranges from 0 to 15.\r
-However here, 0 means that the copy operation will be minimal.\r
-The minimum length of a match, called minmatch, is 4. \r
-As a consequence, a 0 value means 4 bytes, and a value of 15 means 19+ bytes.\r
-Similar to literal length, on reaching the highest possible value (15), \r
-we output additional bytes, one at a time, with values ranging from 0 to 255.\r
-They are added to total to provide the final match length.\r
-A 255 value means there is another byte to read and add.\r
-There is no limit to the number of optional bytes that can be output this way.\r
-(This points towards a maximum achievable compression ratio of ~250).\r
-\r
-With the offset and the matchlength,\r
-the decoder can now proceed to copy the data from the already decoded buffer.\r
-On decoding the matchlength, we reach the end of the compressed sequence,\r
-and therefore start another one.\r
-\r
-\r
--- Parsing restrictions --\r
-\r
-There are specific parsing rules to respect in order to remain compatible\r
-with assumptions made by the decoder :\r
-1) The last 5 bytes are always literals\r
-2) The last match must start at least 12 bytes before end of stream\r
-Consequently, a file with less than 13 bytes cannot be compressed.\r
-These rules are in place to ensure that the decoder\r
-will never read beyond the input buffer, nor write beyond the output buffer.\r
-\r
-Note that the last sequence is also incomplete,\r
-and stops right after literals.\r
-\r
-\r
--- Additional notes --\r
-\r
-There is no assumption nor limits to the way the compressor\r
-searches and selects matches within the source stream.\r
-It could be a fast scan, a multi-probe, a full search using BST,\r
-standard hash chains or MMC, well whatever.\r
-\r
-Advanced parsing strategies can also be implemented, such as lazy match,\r
-or full optimal parsing.\r
-\r
-All these trade-off offer distinctive speed/memory/compression advantages.\r
-Whatever the method used by the compressor, its result will be decodable\r
-by any LZ4 decoder if it follows the format specification described above.\r
-\r
+++ /dev/null
-/*\r
- LZ4 HC - High Compression Mode of LZ4\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
-\r
-\r
-//**************************************\r
-// CPU Feature Detection\r
-//**************************************\r
-// 32 or 64 bits ?\r
-#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(__ppc64__) || defined(_WIN64) || defined(__LP64__) || defined(_LP64) ) // Detects 64 bits mode\r
-#define LZ4_ARCH64 1\r
-#else\r
-#define LZ4_ARCH64 0\r
-#endif\r
-\r
-// Little Endian or Big Endian ? \r
-#if (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(_ARCH_PPC) || defined(__PPC__) || defined(__PPC) || defined(PPC) || defined(__powerpc__) || defined(__powerpc) || defined(powerpc) || ((defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) )\r
-#define LZ4_BIG_ENDIAN 1\r
-#else\r
-// Little Endian assumed. PDP Endian and other very rare endian format are unsupported.\r
-#endif\r
-\r
-// Unaligned memory access is automatically enabled for "common" CPU, such as x86.\r
-// For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected\r
-// If you know your target CPU supports unaligned memory access, you may want to force this option manually to improve performance\r
-#if defined(__ARM_FEATURE_UNALIGNED)\r
-#define LZ4_FORCE_UNALIGNED_ACCESS 1\r
-#endif\r
-\r
-\r
-//**************************************\r
-// Compiler Options\r
-//**************************************\r
-#if __STDC_VERSION__ >= 199901L // C99\r
- /* "restrict" is a known keyword */\r
-#else\r
-#define restrict // Disable restrict\r
-#endif\r
-\r
-#ifdef _MSC_VER\r
-#define inline __forceinline // Visual is not C99, but supports some kind of inline\r
-#endif\r
-\r
-#ifdef _MSC_VER // Visual Studio\r
-#define bswap16(x) _byteswap_ushort(x)\r
-#else\r
-#define bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))\r
-#endif\r
-\r
-\r
-//**************************************\r
-// Includes\r
-//**************************************\r
-#include <stdlib.h> // calloc, free\r
-#include <string.h> // memset, memcpy\r
-#include "lz4hc.h"\r
-\r
-#define ALLOCATOR(s) calloc(1,s)\r
-#define FREEMEM free\r
-#define MEM_INIT memset\r
-\r
-\r
-//**************************************\r
-// Basic Types\r
-//**************************************\r
-#if defined(_MSC_VER) // Visual Studio does not support 'stdint' natively\r
-#define BYTE unsigned __int8\r
-#define U16 unsigned __int16\r
-#define U32 unsigned __int32\r
-#define S32 __int32\r
-#define U64 unsigned __int64\r
-#else\r
-#include <stdint.h>\r
-#define BYTE uint8_t\r
-#define U16 uint16_t\r
-#define U32 uint32_t\r
-#define S32 int32_t\r
-#define U64 uint64_t\r
-#endif\r
-\r
-#ifndef LZ4_FORCE_UNALIGNED_ACCESS\r
-#pragma pack(push, 1) \r
-#endif\r
-\r
-typedef struct _U16_S { U16 v; } U16_S;\r
-typedef struct _U32_S { U32 v; } U32_S;\r
-typedef struct _U64_S { U64 v; } U64_S;\r
-\r
-#ifndef LZ4_FORCE_UNALIGNED_ACCESS\r
-#pragma pack(pop) \r
-#endif\r
-\r
-#define A64(x) (((U64_S *)(x))->v)\r
-#define A32(x) (((U32_S *)(x))->v)\r
-#define A16(x) (((U16_S *)(x))->v)\r
-\r
-\r
-//**************************************\r
-// Constants\r
-//**************************************\r
-#define MINMATCH 4\r
-\r
-#define DICTIONARY_LOGSIZE 16\r
-#define MAXD (1<<DICTIONARY_LOGSIZE)\r
-#define MAXD_MASK ((U32)(MAXD - 1))\r
-#define MAX_DISTANCE (MAXD - 1)\r
-\r
-#define HASH_LOG (DICTIONARY_LOGSIZE-1)\r
-#define HASHTABLESIZE (1 << HASH_LOG)\r
-#define HASH_MASK (HASHTABLESIZE - 1)\r
-\r
-#define MAX_NB_ATTEMPTS 256\r
-\r
-#define ML_BITS 4\r
-#define ML_MASK (size_t)((1U<<ML_BITS)-1)\r
-#define RUN_BITS (8-ML_BITS)\r
-#define RUN_MASK ((1U<<RUN_BITS)-1)\r
-\r
-#define COPYLENGTH 8\r
-#define LASTLITERALS 5\r
-#define MFLIMIT (COPYLENGTH+MINMATCH)\r
-#define MINLENGTH (MFLIMIT+1)\r
-#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)\r
-\r
-\r
-//**************************************\r
-// Architecture-specific macros\r
-//**************************************\r
-#if LZ4_ARCH64 // 64-bit\r
-#define STEPSIZE 8\r
-#define LZ4_COPYSTEP(s,d) A64(d) = A64(s); d+=8; s+=8;\r
-#define LZ4_COPYPACKET(s,d) LZ4_COPYSTEP(s,d)\r
-#define UARCH U64\r
-#define AARCH A64\r
-#define HTYPE U32\r
-#define INITBASE(b,s) const BYTE* const b = s\r
-#else // 32-bit\r
-#define STEPSIZE 4\r
-#define LZ4_COPYSTEP(s,d) A32(d) = A32(s); d+=4; s+=4;\r
-#define LZ4_COPYPACKET(s,d) LZ4_COPYSTEP(s,d); LZ4_COPYSTEP(s,d);\r
-#define UARCH U32\r
-#define AARCH A32\r
-#define HTYPE const BYTE*\r
-#define INITBASE(b,s) const int b = 0\r
-#endif\r
-\r
-#if defined(LZ4_BIG_ENDIAN)\r
-#define LZ4_READ_LITTLEENDIAN_16(d,s,p) { U16 v = A16(p); v = bswap16(v); d = (s) - v; }\r
-#define LZ4_WRITE_LITTLEENDIAN_16(p,i) { U16 v = (U16)(i); v = bswap16(v); A16(p) = v; p+=2; }\r
-#else // Little Endian\r
-#define LZ4_READ_LITTLEENDIAN_16(d,s,p) { d = (s) - A16(p); }\r
-#define LZ4_WRITE_LITTLEENDIAN_16(p,v) { A16(p) = v; p+=2; }\r
-#endif\r
-\r
-\r
-//************************************************************\r
-// Local Types\r
-//************************************************************\r
-typedef struct \r
-{\r
- const BYTE* base;\r
- HTYPE hashTable[HASHTABLESIZE];\r
- U16 chainTable[MAXD];\r
- const BYTE* nextToUpdate;\r
-} LZ4HC_Data_Structure;\r
-\r
-\r
-//**************************************\r
-// Macros\r
-//**************************************\r
-#define LZ4_WILDCOPY(s,d,e) do { LZ4_COPYPACKET(s,d) } while (d<e);\r
-#define LZ4_BLINDCOPY(s,d,l) { BYTE* e=d+l; LZ4_WILDCOPY(s,d,e); d=e; }\r
-#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))\r
-#define HASH_VALUE(p) HASH_FUNCTION(*(U32*)(p))\r
-#define HASH_POINTER(p) (HashTable[HASH_VALUE(p)] + base)\r
-#define DELTANEXT(p) chainTable[(size_t)(p) & MAXD_MASK] \r
-#define GETNEXT(p) ((p) - (size_t)DELTANEXT(p))\r
-#define ADD_HASH(p) { size_t delta = (p) - HASH_POINTER(p); if (delta>MAX_DISTANCE) delta = MAX_DISTANCE; DELTANEXT(p) = (U16)delta; HashTable[HASH_VALUE(p)] = (p) - base; }\r
-\r
-\r
-//**************************************\r
-// Private functions\r
-//**************************************\r
-#if LZ4_ARCH64\r
-\r
-inline static int LZ4_NbCommonBytes (register U64 val)\r
-{\r
-#if defined(LZ4_BIG_ENDIAN)\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanReverse64( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_clzll(val) >> 3); \r
- #else\r
- int r;\r
- if (!(val>>32)) { r=4; } else { r=0; val>>=32; }\r
- if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }\r
- r += (!val);\r
- return r;\r
- #endif\r
-#else\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanForward64( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_ctzll(val) >> 3); \r
- #else\r
- static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };\r
- return DeBruijnBytePos[((U64)((val & -val) * 0x0218A392CDABBD3F)) >> 58];\r
- #endif\r
-#endif\r
-}\r
-\r
-#else\r
-\r
-inline static int LZ4_NbCommonBytes (register U32 val)\r
-{\r
-#if defined(LZ4_BIG_ENDIAN)\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanReverse( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_clz(val) >> 3); \r
- #else\r
- int r;\r
- if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }\r
- r += (!val);\r
- return r;\r
- #endif\r
-#else\r
- #if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- unsigned long r = 0;\r
- _BitScanForward( &r, val );\r
- return (int)(r>>3);\r
- #elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)\r
- return (__builtin_ctz(val) >> 3); \r
- #else\r
- static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };\r
- return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];\r
- #endif\r
-#endif\r
-}\r
-\r
-#endif\r
-\r
-\r
-inline static int LZ4HC_Init (LZ4HC_Data_Structure* hc4, const BYTE* base)\r
-{\r
- MEM_INIT((void*)hc4->hashTable, 0, sizeof(hc4->hashTable));\r
- MEM_INIT(hc4->chainTable, 0xFF, sizeof(hc4->chainTable));\r
- hc4->nextToUpdate = base + LZ4_ARCH64;\r
- hc4->base = base;\r
- return 1;\r
-}\r
-\r
-\r
-inline static void* LZ4HC_Create (const BYTE* base)\r
-{\r
- void* hc4 = ALLOCATOR(sizeof(LZ4HC_Data_Structure));\r
-\r
- LZ4HC_Init (hc4, base);\r
- return hc4;\r
-}\r
-\r
-\r
-inline static int LZ4HC_Free (void** LZ4HC_Data)\r
-{\r
- FREEMEM(*LZ4HC_Data);\r
- *LZ4HC_Data = NULL;\r
- return (1);\r
-}\r
-\r
-\r
-inline static void LZ4HC_Insert (LZ4HC_Data_Structure* hc4, const BYTE* ip)\r
-{\r
- U16* chainTable = hc4->chainTable;\r
- HTYPE* HashTable = hc4->hashTable;\r
- INITBASE(base,hc4->base);\r
-\r
- while(hc4->nextToUpdate < ip)\r
- {\r
- ADD_HASH(hc4->nextToUpdate);\r
- hc4->nextToUpdate++;\r
- }\r
-}\r
-\r
-\r
-inline static int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, const BYTE* ip, const BYTE* const matchlimit, const BYTE** matchpos)\r
-{\r
- U16* const chainTable = hc4->chainTable;\r
- HTYPE* const HashTable = hc4->hashTable;\r
- const BYTE* ref;\r
- INITBASE(base,hc4->base);\r
- int nbAttempts=MAX_NB_ATTEMPTS;\r
- int ml=0;\r
-\r
- // HC4 match finder\r
- LZ4HC_Insert(hc4, ip);\r
- ref = HASH_POINTER(ip);\r
- while ((ref > (ip-MAX_DISTANCE)) && (nbAttempts))\r
- {\r
- nbAttempts--;\r
- if (*(ref+ml) == *(ip+ml))\r
- if (*(U32*)ref == *(U32*)ip)\r
- {\r
- const BYTE* reft = ref+MINMATCH;\r
- const BYTE* ipt = ip+MINMATCH;\r
-\r
- while (ipt<matchlimit-(STEPSIZE-1))\r
- {\r
- UARCH diff = AARCH(reft) ^ AARCH(ipt);\r
- if (!diff) { ipt+=STEPSIZE; reft+=STEPSIZE; continue; }\r
- ipt += LZ4_NbCommonBytes(diff);\r
- goto _endCount;\r
- }\r
- if (LZ4_ARCH64) if ((ipt<(matchlimit-3)) && (A32(reft) == A32(ipt))) { ipt+=4; reft+=4; }\r
- if ((ipt<(matchlimit-1)) && (A16(reft) == A16(ipt))) { ipt+=2; reft+=2; }\r
- if ((ipt<matchlimit) && (*reft == *ipt)) ipt++;\r
-_endCount:\r
-\r
- if (ipt-ip > ml) { ml = ipt-ip; *matchpos = ref; }\r
- }\r
- ref = GETNEXT(ref);\r
- }\r
-\r
- return ml;\r
-}\r
-\r
-\r
-inline static int LZ4HC_InsertAndGetWiderMatch (LZ4HC_Data_Structure* hc4, const BYTE* ip, const BYTE* startLimit, const BYTE* matchlimit, int longest, const BYTE** matchpos, const BYTE** startpos)\r
-{\r
- U16* const chainTable = hc4->chainTable;\r
- HTYPE* const HashTable = hc4->hashTable;\r
- INITBASE(base,hc4->base);\r
- const BYTE* ref;\r
- int nbAttempts = MAX_NB_ATTEMPTS;\r
- int delta = ip-startLimit;\r
-\r
- // First Match\r
- LZ4HC_Insert(hc4, ip);\r
- ref = HASH_POINTER(ip);\r
-\r
- while ((ref > ip-MAX_DISTANCE) && (ref >= hc4->base) && (nbAttempts))\r
- {\r
- nbAttempts--;\r
- if (*(startLimit + longest) == *(ref - delta + longest))\r
- if (*(U32*)ref == *(U32*)ip)\r
- {\r
- const BYTE* reft = ref+MINMATCH;\r
- const BYTE* ipt = ip+MINMATCH;\r
- const BYTE* startt = ip;\r
-\r
- while (ipt<matchlimit-(STEPSIZE-1))\r
- {\r
- UARCH diff = AARCH(reft) ^ AARCH(ipt);\r
- if (!diff) { ipt+=STEPSIZE; reft+=STEPSIZE; continue; }\r
- ipt += LZ4_NbCommonBytes(diff);\r
- goto _endCount;\r
- }\r
- if (LZ4_ARCH64) if ((ipt<(matchlimit-3)) && (A32(reft) == A32(ipt))) { ipt+=4; reft+=4; }\r
- if ((ipt<(matchlimit-1)) && (A16(reft) == A16(ipt))) { ipt+=2; reft+=2; }\r
- if ((ipt<matchlimit) && (*reft == *ipt)) ipt++;\r
-_endCount:\r
-\r
- reft = ref;\r
- while ((startt>startLimit) && (reft > hc4->base) && (startt[-1] == reft[-1])) {startt--; reft--;}\r
-\r
- if ((ipt-startt) > longest)\r
- {\r
- longest = ipt-startt;\r
- *matchpos = reft;\r
- *startpos = startt;\r
- }\r
- }\r
- ref = GETNEXT(ref);\r
- }\r
-\r
- return longest;\r
-}\r
-\r
-\r
-inline static int LZ4_encodeSequence(const BYTE** ip, BYTE** op, const BYTE** anchor, int ml, const BYTE* ref)\r
-{\r
- int length, len; \r
- BYTE* token;\r
-\r
- // Encode Literal length\r
- length = *ip - *anchor;\r
- token = (*op)++;\r
- if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *(*op)++ = 255; *(*op)++ = (BYTE)len; } \r
- else *token = (length<<ML_BITS);\r
-\r
- // Copy Literals\r
- LZ4_BLINDCOPY(*anchor, *op, length);\r
-\r
- // Encode Offset\r
- LZ4_WRITE_LITTLEENDIAN_16(*op,*ip-ref);\r
-\r
- // Encode MatchLength\r
- len = (int)(ml-MINMATCH);\r
- if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *(*op)++ = 255; *(*op)++ = 255; } if (len > 254) { len-=255; *(*op)++ = 255; } *(*op)++ = (BYTE)len; } \r
- else *token += len; \r
-\r
- // Prepare next loop\r
- *ip += ml;\r
- *anchor = *ip; \r
-\r
- return 0;\r
-}\r
-\r
-\r
-//****************************\r
-// Compression CODE\r
-//****************************\r
-\r
-int LZ4_compressHCCtx(LZ4HC_Data_Structure* ctx,\r
- const char* source, \r
- char* dest,\r
- int isize)\r
-{ \r
- const BYTE* ip = (const BYTE*) source;\r
- const BYTE* anchor = ip;\r
- const BYTE* const iend = ip + isize;\r
- const BYTE* const mflimit = iend - MFLIMIT;\r
- const BYTE* const matchlimit = (iend - LASTLITERALS);\r
-\r
- BYTE* op = (BYTE*) dest;\r
-\r
- int ml, ml2, ml3, ml0;\r
- const BYTE* ref=NULL;\r
- const BYTE* start2=NULL;\r
- const BYTE* ref2=NULL;\r
- const BYTE* start3=NULL;\r
- const BYTE* ref3=NULL;\r
- const BYTE* start0;\r
- const BYTE* ref0;\r
-\r
- ip++;\r
-\r
- // Main Loop\r
- while (ip < mflimit)\r
- {\r
- ml = LZ4HC_InsertAndFindBestMatch (ctx, ip, matchlimit, (&ref));\r
- if (!ml) { ip++; continue; }\r
-\r
- // saved, in case we would skip too much\r
- start0 = ip;\r
- ref0 = ref;\r
- ml0 = ml;\r
-\r
-_Search2:\r
- if (ip+ml < mflimit)\r
- ml2 = LZ4HC_InsertAndGetWiderMatch(ctx, ip + ml - 2, ip + 1, matchlimit, ml, &ref2, &start2);\r
- else ml2=ml;\r
-\r
- if (ml2 == ml) // No better match\r
- {\r
- LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);\r
- continue;\r
- }\r
-\r
- if (start0 < ip)\r
- {\r
- if (start2 < ip + ml0) // empirical\r
- {\r
- ip = start0;\r
- ref = ref0;\r
- ml = ml0;\r
- }\r
- }\r
-\r
- // Here, start0==ip\r
- if ((start2 - ip) < 3) // First Match too small : removed\r
- {\r
- ml = ml2;\r
- ip = start2;\r
- ref =ref2;\r
- goto _Search2;\r
- }\r
-\r
-_Search3:\r
- // Currently we have :\r
- // ml2 > ml1, and\r
- // ip1+3 <= ip2 (usually < ip1+ml1)\r
- if ((start2 - ip) < OPTIMAL_ML)\r
- {\r
- int correction;\r
- int new_ml = ml;\r
- if (new_ml > OPTIMAL_ML) new_ml = OPTIMAL_ML;\r
- if (ip+new_ml > start2 + ml2 - MINMATCH) new_ml = start2 - ip + ml2 - MINMATCH;\r
- correction = new_ml - (start2 - ip);\r
- if (correction > 0)\r
- {\r
- start2 += correction;\r
- ref2 += correction;\r
- ml2 -= correction;\r
- }\r
- }\r
- // Now, we have start2 = ip+new_ml, with new_ml=min(ml, OPTIMAL_ML=18)\r
-\r
- if (start2 + ml2 < mflimit)\r
- ml3 = LZ4HC_InsertAndGetWiderMatch(ctx, start2 + ml2 - 3, start2, matchlimit, ml2, &ref3, &start3);\r
- else ml3=ml2;\r
-\r
- if (ml3 == ml2) // No better match : 2 sequences to encode\r
- {\r
- // ip & ref are known; Now for ml\r
- if (start2 < ip+ml)\r
- {\r
- if ((start2 - ip) < OPTIMAL_ML)\r
- {\r
- int correction;\r
- if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;\r
- if (ip+ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;\r
- correction = ml - (start2 - ip);\r
- if (correction > 0)\r
- {\r
- start2 += correction;\r
- ref2 += correction;\r
- ml2 -= correction;\r
- }\r
- }\r
- else\r
- {\r
- ml = start2 - ip;\r
- }\r
- }\r
- // Now, encode 2 sequences\r
- LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);\r
- ip = start2;\r
- LZ4_encodeSequence(&ip, &op, &anchor, ml2, ref2);\r
- continue;\r
- }\r
-\r
- if (start3 < ip+ml+3) // Not enough space for match 2 : remove it\r
- {\r
- if (start3 >= (ip+ml)) // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1\r
- {\r
- if (start2 < ip+ml)\r
- {\r
- int correction = (ip+ml) - start2;\r
- start2 += correction;\r
- ref2 += correction;\r
- ml2 -= correction;\r
- if (ml2 < MINMATCH)\r
- {\r
- start2 = start3;\r
- ref2 = ref3;\r
- ml2 = ml3;\r
- }\r
- }\r
-\r
- LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);\r
- ip = start3;\r
- ref = ref3;\r
- ml = ml3;\r
-\r
- start0 = start2;\r
- ref0 = ref2;\r
- ml0 = ml2;\r
- goto _Search2;\r
- }\r
-\r
- start2 = start3;\r
- ref2 = ref3;\r
- ml2 = ml3;\r
- goto _Search3;\r
- }\r
-\r
- // OK, now we have 3 ascending matches; let's write at least the first one\r
- // ip & ref are known; Now for ml\r
- if (start2 < ip+ml)\r
- {\r
- if ((start2 - ip) < (int)ML_MASK)\r
- {\r
- int correction;\r
- if (ml > OPTIMAL_ML) ml = OPTIMAL_ML;\r
- if (ip + ml > start2 + ml2 - MINMATCH) ml = start2 - ip + ml2 - MINMATCH;\r
- correction = ml - (start2 - ip);\r
- if (correction > 0)\r
- {\r
- start2 += correction;\r
- ref2 += correction;\r
- ml2 -= correction;\r
- }\r
- }\r
- else\r
- {\r
- ml = start2 - ip;\r
- }\r
- }\r
- LZ4_encodeSequence(&ip, &op, &anchor, ml, ref);\r
-\r
- ip = start2;\r
- ref = ref2;\r
- ml = ml2;\r
-\r
- start2 = start3;\r
- ref2 = ref3;\r
- ml2 = ml3;\r
-\r
- goto _Search3;\r
-\r
- }\r
-\r
- // Encode Last Literals\r
- {\r
- int lastRun = iend - anchor;\r
- if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; } \r
- else *op++ = (lastRun<<ML_BITS);\r
- memcpy(op, anchor, iend - anchor);\r
- op += iend-anchor;\r
- } \r
-\r
- // End\r
- return (int) (((char*)op)-dest);\r
-}\r
-\r
-\r
-int LZ4_compressHC(const char* source, \r
- char* dest,\r
- int isize)\r
-{\r
- void* ctx = LZ4HC_Create((const BYTE*)source);\r
- int result = LZ4_compressHCCtx(ctx, source, dest, isize);\r
- LZ4HC_Free (&ctx);\r
-\r
- return result;\r
-}\r
-\r
-\r
+++ /dev/null
-/*\r
- LZ4 HC - High Compression Mode of LZ4\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
-\r
-#if defined (__cplusplus)\r
-extern "C" {\r
-#endif\r
-\r
-\r
-int LZ4_compressHC (const char* source, char* dest, int isize);\r
-\r
-/*\r
-LZ4_compressHC :\r
- return : the number of bytes in compressed buffer dest\r
- note : destination buffer must be already allocated. \r
- To avoid any problem, size it to handle worst cases situations (input data not compressible)\r
- Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")\r
-*/\r
-\r
-\r
-/* Note :\r
-Decompression functions are provided within regular LZ4 source code (see "lz4.h") (BSD license)\r
-*/\r
-\r
-\r
-#if defined (__cplusplus)\r
-}\r
-#endif\r
--- /dev/null
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Visual Studio Express 2012 for Windows Desktop\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fastlz", "fastlz.vcxproj", "{2C249AD2-A0AE-4A88-8DCD-71F96133690E}"\r
+EndProject\r
+Global\r
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+ Debug|Win32 = Debug|Win32\r
+ Debug|x64 = Debug|x64\r
+ Release|Win32 = Release|Win32\r
+ Release|x64 = Release|x64\r
+ EndGlobalSection\r
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Debug|Win32.ActiveCfg = Debug|Win32\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Debug|Win32.Build.0 = Debug|Win32\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Debug|x64.ActiveCfg = Debug|x64\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Debug|x64.Build.0 = Debug|x64\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Release|Win32.ActiveCfg = Release|Win32\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Release|Win32.Build.0 = Release|Win32\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Release|x64.ActiveCfg = Release|x64\r
+ {2C249AD2-A0AE-4A88-8DCD-71F96133690E}.Release|x64.Build.0 = Release|x64\r
+ EndGlobalSection\r
+ GlobalSection(SolutionProperties) = preSolution\r
+ HideSolutionNode = FALSE\r
+ EndGlobalSection\r
+EndGlobal\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+ <ItemGroup Label="ProjectConfigurations">\r
+ <ProjectConfiguration Include="Debug|Win32">\r
+ <Configuration>Debug</Configuration>\r
+ <Platform>Win32</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Debug|x64">\r
+ <Configuration>Debug</Configuration>\r
+ <Platform>x64</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Release|Win32">\r
+ <Configuration>Release</Configuration>\r
+ <Platform>Win32</Platform>\r
+ </ProjectConfiguration>\r
+ <ProjectConfiguration Include="Release|x64">\r
+ <Configuration>Release</Configuration>\r
+ <Platform>x64</Platform>\r
+ </ProjectConfiguration>\r
+ </ItemGroup>\r
+ <PropertyGroup Label="Globals">\r
+ <ProjectGuid>{2C249AD2-A0AE-4A88-8DCD-71F96133690E}</ProjectGuid>\r
+ <RootNamespace>fastlz</RootNamespace>\r
+ <Keyword>Win32Proj</Keyword>\r
+ </PropertyGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
+ <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ <WholeProgramOptimization>true</WholeProgramOptimization>\r
+ <PlatformToolset>v110</PlatformToolset>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
+ <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ <PlatformToolset>v110</PlatformToolset>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
+ <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ <WholeProgramOptimization>true</WholeProgramOptimization>\r
+ <PlatformToolset>v110</PlatformToolset>\r
+ </PropertyGroup>\r
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
+ <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+ <CharacterSet>Unicode</CharacterSet>\r
+ <PlatformToolset>v110</PlatformToolset>\r
+ </PropertyGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
+ <ImportGroup Label="ExtensionSettings">\r
+ </ImportGroup>\r
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
+ </ImportGroup>\r
+ <PropertyGroup Label="UserMacros" />\r
+ <PropertyGroup>\r
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>\r
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>\r
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>\r
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>\r
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>\r
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>\r
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>\r
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>\r
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>\r
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>\r
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>\r
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>\r
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>\r
+ </PropertyGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
+ <ClCompile>\r
+ <Optimization>Disabled</Optimization>\r
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FASTLZ_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <MinimalRebuild>true</MinimalRebuild>\r
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+ <PrecompiledHeader>\r
+ </PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r
+ </ClCompile>\r
+ <Link>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ <SubSystem>Windows</SubSystem>\r
+ <TargetMachine>MachineX86</TargetMachine>\r
+ </Link>\r
+ <PostBuildEvent>\r
+ <Command>copy "$(TargetPath)" "$(ProjectDir)..\..\src\fastlz-windows-x86.dll"</Command>\r
+ </PostBuildEvent>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
+ <Midl>\r
+ <TargetEnvironment>X64</TargetEnvironment>\r
+ </Midl>\r
+ <ClCompile>\r
+ <Optimization>Disabled</Optimization>\r
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FASTLZ_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <MinimalRebuild>true</MinimalRebuild>\r
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r
+ <PrecompiledHeader>\r
+ </PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+ </ClCompile>\r
+ <Link>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ <SubSystem>Windows</SubSystem>\r
+ <TargetMachine>MachineX64</TargetMachine>\r
+ </Link>\r
+ <PostBuildEvent>\r
+ <Command>copy "$(TargetPath)" "$(ProjectDir)..\..\src\fastlz-windows-x86_64.dll"</Command>\r
+ </PostBuildEvent>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
+ <ClCompile>\r
+ <Optimization>MaxSpeed</Optimization>\r
+ <IntrinsicFunctions>true</IntrinsicFunctions>\r
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;FASTLZ_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+ <FunctionLevelLinking>true</FunctionLevelLinking>\r
+ <PrecompiledHeader>\r
+ </PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+ </ClCompile>\r
+ <Link>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ <SubSystem>Windows</SubSystem>\r
+ <OptimizeReferences>true</OptimizeReferences>\r
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+ <TargetMachine>MachineX86</TargetMachine>\r
+ </Link>\r
+ <PostBuildEvent>\r
+ <Command>copy "$(TargetPath)" "$(ProjectDir)..\..\src\fastlz-windows-x86.dll"</Command>\r
+ </PostBuildEvent>\r
+ </ItemDefinitionGroup>\r
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
+ <Midl>\r
+ <TargetEnvironment>X64</TargetEnvironment>\r
+ </Midl>\r
+ <ClCompile>\r
+ <Optimization>MaxSpeed</Optimization>\r
+ <IntrinsicFunctions>true</IntrinsicFunctions>\r
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;FASTLZ_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r
+ <FunctionLevelLinking>true</FunctionLevelLinking>\r
+ <PrecompiledHeader>\r
+ </PrecompiledHeader>\r
+ <WarningLevel>Level3</WarningLevel>\r
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
+ </ClCompile>\r
+ <Link>\r
+ <GenerateDebugInformation>true</GenerateDebugInformation>\r
+ <SubSystem>Windows</SubSystem>\r
+ <OptimizeReferences>true</OptimizeReferences>\r
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
+ <TargetMachine>MachineX64</TargetMachine>\r
+ </Link>\r
+ <PostBuildEvent>\r
+ <Command>copy "$(TargetPath)" "$(ProjectDir)..\..\src\fastlz-windows-x86_64.dll"</Command>\r
+ </PostBuildEvent>\r
+ </ItemDefinitionGroup>\r
+ <ItemGroup>\r
+ <ClCompile Include="..\fastlz.c" />\r
+ <ClCompile Include="..\jniWrapper.c" />\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <ClInclude Include="..\fastlz.h" />\r
+ </ItemGroup>\r
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
+ <ImportGroup Label="ExtensionTargets">\r
+ </ImportGroup>\r
+</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+ <ItemGroup>\r
+ <Filter Include="Source Files">\r
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\r
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\r
+ </Filter>\r
+ <Filter Include="Header Files">\r
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\r
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\r
+ </Filter>\r
+ <Filter Include="Resource Files">\r
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\r
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>\r
+ </Filter>\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <ClCompile Include="..\fastlz.c">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="..\jniWrapper.c">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
+ </ItemGroup>\r
+ <ItemGroup>\r
+ <ClInclude Include="..\fastlz.h">\r
+ <Filter>Resource Files</Filter>\r
+ </ClInclude>\r
+ </ItemGroup>\r
+</Project>
\ No newline at end of file
super(stream, channel);\r
}\r
\r
+ @Override\r
+ protected ByteBuffer allocateBuffer(int capacity) {\r
+ return ByteBuffer.allocate(capacity);\r
+ }\r
+ \r
@Override\r
public void decompress(ByteBuffer compressed, int compressedOffset, int compressedSize, ByteBuffer uncompressed,\r
int uncompressedOffset, int uncompressedSize) throws IOException {\r
@Test\r
public void validateCompress() throws IOException {\r
validateCompress(testData1);\r
- validateCompress(new File("grades.snp"));\r
}\r
\r
private void validateCompress(File testData) throws IOException {\r