53# pragma GCC diagnostic ignored "-Wunused-function"
56#if defined (__clang__)
57# pragma clang diagnostic ignored "-Wunused-function"
64#define MLZ4_COMMONDEFS_ONLY
71#define DICTIONARY_LOGSIZE 16
72#define MAXD (1<<DICTIONARY_LOGSIZE)
73#define MAXD_MASK (MAXD - 1)
75#define HASH_LOG (DICTIONARY_LOGSIZE-1)
76#define HASHTABLESIZE (1 << HASH_LOG)
77#define HASH_MASK (HASHTABLESIZE - 1)
79#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)
105#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))
107#define DELTANEXTU16(p) chainTable[(U16)(p)]
121 hc4->
base = start - 64
KB;
135 const U32 target = (
U32)(ip - base);
141 size_t delta = idx - HashTable[h];
153 const BYTE* ip,
const BYTE*
const iLimit,
154 const BYTE** matchpos,
155 const int maxNbAttempts)
165 int nbAttempts=maxNbAttempts;
172 while ((matchIndex>=lowLimit) && (nbAttempts))
175 if (matchIndex >= dictLimit)
177 match = base + matchIndex;
178 if (*(match+ml) == *(ip+ml)
182 if (mlt > ml) { ml = mlt; *matchpos = match; }
187 match = dictBase + matchIndex;
191 const BYTE* vLimit = ip + (dictLimit - matchIndex);
192 if (vLimit > iLimit) vLimit = iLimit;
194 if ((ip+mlt == vLimit) && (vLimit < iLimit))
195 mlt +=
MLZ4_count(ip+mlt, base+dictLimit, iLimit);
196 if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; }
208 const BYTE*
const ip,
209 const BYTE*
const iLowLimit,
210 const BYTE*
const iHighLimit,
212 const BYTE** matchpos,
213 const BYTE** startpos,
214 const int maxNbAttempts)
220 const BYTE*
const lowPrefixPtr = base + dictLimit;
224 int nbAttempts = maxNbAttempts;
225 int delta = (int)(ip-iLowLimit);
232 while ((matchIndex>=lowLimit) && (nbAttempts))
235 if (matchIndex >= dictLimit)
237 const BYTE* matchPtr = base + matchIndex;
238 if (*(iLowLimit + longest) == *(matchPtr - delta + longest))
244 while ((ip+back>iLowLimit)
245 && (matchPtr+back > lowPrefixPtr)
246 && (ip[back-1] == matchPtr[back-1]))
254 *matchpos = matchPtr+back;
261 const BYTE* matchPtr = dictBase + matchIndex;
266 const BYTE* vLimit = ip + (dictLimit - matchIndex);
267 if (vLimit > iHighLimit) vLimit = iHighLimit;
269 if ((ip+mlt == vLimit) && (vLimit < iHighLimit))
270 mlt +=
MLZ4_count(ip+mlt, base+dictLimit, iHighLimit);
271 while ((ip+back > iLowLimit) && (matchIndex+back > lowLimit) && (ip[back-1] == matchPtr[back-1])) back--;
273 if ((
int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
287static unsigned debug = 0;
295 const BYTE*
const match,
303 if (debug) printf(
"literal : %u -- match : %u -- offset : %u\n", (
U32)(*ip - *anchor), (
U32)matchLength, (
U32)(*ip-match));
307 length = (int)(*ip - *anchor);
309 if ((limitedOutputBuffer) && ((*op + (length>>8) + length + (2 + 1 +
LASTLITERALS)) > oend))
return 1;
321 length = (int)(matchLength-
MINMATCH);
322 if ((limitedOutputBuffer) && (*op + (length>>8) + (1 +
LASTLITERALS) > oend))
return 1;
323 if (length>=(
int)
ML_MASK) { *token+=
ML_MASK; length-=
ML_MASK;
for(; length > 509 ; length-=510) { *(*op)++ = 255; *(*op)++ = 255; }
if (length > 254) { length-=255; *(*op)++ = 255; } *(*op)++ = (
BYTE)length; }
324 else *token += (
BYTE)(length);
346 const BYTE* anchor = ip;
354 unsigned maxNbAttempts;
355 int ml, ml2, ml3, ml0;
356 const BYTE* ref=NULL;
357 const BYTE* start2=NULL;
358 const BYTE* ref2=NULL;
359 const BYTE* start3=NULL;
360 const BYTE* ref3=NULL;
377 if (!ml) { ip++;
continue; }
397 if (start2 < ip + ml0)
406 if ((start2 - ip) < 3)
425 if (ip+new_ml > start2 + ml2 -
MINMATCH) new_ml = (int)(start2 - ip) + ml2 -
MINMATCH;
426 correction = new_ml - (int)(start2 - ip);
429 start2 += correction;
436 if (start2 + ml2 < mflimit)
443 if (start2 < ip+ml) ml = (int)(start2 - ip);
451 if (start3 < ip+ml+3)
453 if (start3 >= (ip+ml))
457 int correction = (int)(ip+ml - start2);
458 start2 += correction;
492 if ((start2 - ip) < (int)
ML_MASK)
496 if (ip + ml > start2 + ml2 -
MINMATCH) ml = (int)(start2 - ip) + ml2 -
MINMATCH;
497 correction = ml - (int)(start2 - ip);
500 start2 += correction;
507 ml = (int)(start2 - ip);
525 int lastRun = (int)(iend - anchor);
529 memcpy(op, anchor, iend - anchor);
534 return (
int) (((
char*)op)-
dest);
542 if (((
size_t)(state)&(
sizeof(
void*)-1)) != 0)
return 0;
577 if (dictSize > 64
KB)
579 dictionary += dictSize - 64
KB;
583 if (dictSize >= 4)
LZ4HC_Insert (ctxPtr, (
const BYTE*)dictionary +(dictSize-3));
584 ctxPtr->
end = (
const BYTE*)dictionary + dictSize;
593 if (ctxPtr->
end >= ctxPtr->
base + 4)
600 ctxPtr->
end = newBlock;
609 if (ctxPtr->
base == NULL)
613 if ((
size_t)(ctxPtr->
end - ctxPtr->
base) > 2
GB)
616 if (dictSize > 64
KB) dictSize = 64
KB;
630 if ((sourceEnd > dictBegin) && ((
const BYTE*)
source < dictEnd))
632 if (sourceEnd > dictEnd) sourceEnd = dictEnd;
655 int prefixSize = (int)(streamPtr->
end - (streamPtr->
base + streamPtr->
dictLimit));
656 if (dictSize > 64
KB) dictSize = 64
KB;
657 if (dictSize < 4) dictSize = 0;
658 if (dictSize > prefixSize) dictSize = prefixSize;
659 memmove(safeBuffer, streamPtr->
end - dictSize, dictSize);
662 streamPtr->
end = (
const BYTE*)safeBuffer + dictSize;
663 streamPtr->
base = streamPtr->
end - endIndex;
664 streamPtr->
dictLimit = endIndex - dictSize;
665 streamPtr->
lowLimit = endIndex - dictSize;
684int MLZ4_compressHC2_limitedOutput_withStateHC (
void* state,
const char* src,
char*
dst,
int srcSize,
int maxDstSize,
int cLevel) {
return MLZ4_compress_HC_extStateHC(state, src,
dst, srcSize,
maxDstSize, cLevel); }
695 if ((((
size_t)state) & (
sizeof(
void*)-1)) != 0)
return 1;
704 if (hc4 == NULL)
return NULL;
int MLZ4_compressBound(int inputSize)
#define MLZ4_STREAMHCSIZE
const char char int int maxOutputSize
const char char int inputSize
const char char int int compressionLevel
#define MLZ4_STATIC_ASSERT(c)
static unsigned MLZ4_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *pInLimit)
static void MLZ4_writeLE16(void *memPtr, U16 value)
static U32 MLZ4_read32(const void *memPtr)
static void MLZ4_wildCopy(void *dstPtr, const void *srcPtr, void *dstEnd)
void MLZ4_resetStreamHC(MLZ4_streamHC_t *MLZ4_streamHCPtr, int compressionLevel)
int MLZ4_compress_HC_continue(MLZ4_streamHC_t *MLZ4_streamHCPtr, const char *source, char *dest, int inputSize, int maxOutputSize)
int MLZ4_compressHC_withStateHC(void *state, const char *src, char *dst, int srcSize)
int MLZ4_compressHC2_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int compressionLevel)
MLZ4_streamHC_t * MLZ4_createStreamHC(void)
char * MLZ4_slideInputBufferHC(void *LZ4HC_Data)
FORCE_INLINE int LZ4HC_InsertAndFindBestMatch(LZ4HC_Data_Structure *hc4, const BYTE *ip, const BYTE *const iLimit, const BYTE **matchpos, const int maxNbAttempts)
int MLZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
static const int LZ4HC_compressionLevel_default
int MLZ4_resetStreamStateHC(void *state, char *inputBuffer)
FORCE_INLINE int LZ4HC_encodeSequence(const BYTE **ip, BYTE **op, const BYTE **anchor, int matchLength, const BYTE *const match, limitedOutput_directive limitedOutputBuffer, BYTE *oend)
int MLZ4_compressHC2(const char *src, char *dst, int srcSize, int cLevel)
static const int g_maxCompressionLevel
int MLZ4_compressHC_continue(MLZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize)
int MLZ4_compressHC(const char *src, char *dst, int srcSize)
static U32 LZ4HC_hashPtr(const void *ptr)
int MLZ4_loadDictHC(MLZ4_streamHC_t *MLZ4_streamHCPtr, const char *dictionary, int dictSize)
int MLZ4_saveDictHC(MLZ4_streamHC_t *MLZ4_streamHCPtr, char *safeBuffer, int dictSize)
int MLZ4_compressHC2_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
int MLZ4_compressHC_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize)
int MLZ4_compressHC2_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
int MLZ4_freeHC(void *LZ4HC_Data)
FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch(LZ4HC_Data_Structure *hc4, const BYTE *const ip, const BYTE *const iLowLimit, const BYTE *const iHighLimit, int longest, const BYTE **matchpos, const BYTE **startpos, const int maxNbAttempts)
int MLZ4_sizeofStateHC(void)
FORCE_INLINE void LZ4HC_Insert(LZ4HC_Data_Structure *hc4, const BYTE *ip)
int MLZ4_compress_HC(const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
int MLZ4_sizeofStreamStateHC(void)
static void LZ4HC_init(LZ4HC_Data_Structure *hc4, const BYTE *start)
int MLZ4_freeStreamHC(MLZ4_streamHC_t *MLZ4_streamHCPtr)
void * MLZ4_createHC(char *inputBuffer)
static void LZ4HC_setExternalDict(LZ4HC_Data_Structure *ctxPtr, const BYTE *newBlock)
int MLZ4_compressHC2_withStateHC(void *state, const char *src, char *dst, int srcSize, int cLevel)
int MLZ4_compressHC_limitedOutput_continue(MLZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize, int maxDstSize)
static int LZ4HC_compress_generic(void *ctxvoid, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel, limitedOutput_directive limit)
static int MLZ4_compressHC_continue_generic(LZ4HC_Data_Structure *ctxPtr, const char *source, char *dest, int inputSize, int maxOutputSize, limitedOutput_directive limit)
int MLZ4_compressHC_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize)
int MLZ4_compressHC2_limitedOutput_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel)
U32 hashTable[HASHTABLESIZE]