46 #ifndef LZ4HC_HEAPMODE 47 # define LZ4HC_HEAPMODE 1 57 # pragma GCC diagnostic ignored "-Wunused-function" 59 #if defined (__clang__) 60 # pragma clang diagnostic ignored "-Wunused-function" 63 #define LZ4_COMMONDEFS_ONLY 68 #define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH) 72 #define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-LZ4HC_HASH_LOG)) 73 #define DELTANEXTMAXD(p) chainTable[(p) & LZ4HC_MAXD_MASK] 74 #define DELTANEXTU16(table, pos) table[(U16)(pos)] 105 while (idx < target) {
107 size_t delta = idx - hashTable[
h];
119 const BYTE*
const ip,
const BYTE*
const iLimit,
120 const BYTE** matchpos,
121 const int maxNbAttempts)
130 int nbAttempts = maxNbAttempts;
137 while ((matchIndex>=lowLimit) && (nbAttempts)) {
139 if (matchIndex >= dictLimit) {
140 const BYTE*
const match = base + matchIndex;
141 if ( (*(match+ml) == *(ip+ml))
145 if (mlt > ml) { ml = mlt; *matchpos = match; }
148 const BYTE*
const match = dictBase + matchIndex;
151 const BYTE* vLimit = ip + (dictLimit - matchIndex);
152 if (vLimit > iLimit) vLimit = iLimit;
154 if ((ip+mlt == vLimit) && (vLimit < iLimit))
155 mlt +=
LZ4_count(ip+mlt, base+dictLimit, iLimit);
156 if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; }
168 const BYTE*
const ip,
169 const BYTE*
const iLowLimit,
170 const BYTE*
const iHighLimit,
172 const BYTE** matchpos,
173 const BYTE** startpos,
174 const int maxNbAttempts)
180 const BYTE*
const lowPrefixPtr = base + dictLimit;
183 int const delta = (int)(ip-iLowLimit);
184 int nbAttempts = maxNbAttempts;
192 while ((matchIndex>=lowLimit) && (nbAttempts)) {
194 if (matchIndex >= dictLimit) {
195 const BYTE*
const matchPtr = base + matchIndex;
196 if (*(iLowLimit + longest) == *(matchPtr - delta + longest)) {
201 while ( (ip+back > iLowLimit)
202 && (matchPtr+back > lowPrefixPtr)
203 && (ip[back-1] == matchPtr[back-1])) {
211 *matchpos = matchPtr+back;
215 const BYTE*
const matchPtr = dictBase + matchIndex;
219 const BYTE* vLimit = ip + (dictLimit - matchIndex);
220 if (vLimit > iHighLimit) vLimit = iHighLimit;
222 if ((ip+mlt == vLimit) && (vLimit < iHighLimit))
223 mlt +=
LZ4_count(ip+mlt, base+dictLimit, iHighLimit);
224 while ((ip+back > iLowLimit) && (matchIndex+back > lowLimit) && (ip[back-1] == matchPtr[back-1])) back--;
226 if (mlt > longest) { longest = mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
243 # define LZ4HC_DEBUG 0 254 const BYTE*
const match,
259 BYTE*
const token = (*op)++;
262 printf(
"literal : %u -- match : %u -- offset : %u\n",
263 (
U32)(*ip - *anchor), (
U32)matchLength, (
U32)(*ip-match));
267 length = (
size_t)(*ip - *anchor);
268 if ((limit) && ((*op + (length >> 8) + length + (2 + 1 +
LASTLITERALS)) > oend))
return 1;
271 *token = (RUN_MASK <<
ML_BITS);
272 for(; len >= 255 ; len -= 255) *(*op)++ = 255;
273 *(*op)++ = (
BYTE)len;
287 if ((limit) && (*op + (length >> 8) + (1 +
LASTLITERALS) > oend))
return 1;
291 for(; length >= 510 ; length -= 510) { *(*op)++ = 255; *(*op)++ = 255; }
292 if (length >= 255) { length -= 255; *(*op)++ = 255; }
293 *(*op)++ = (
BYTE)length;
295 *token += (
BYTE)(length);
315 unsigned maxNbAttempts,
321 const BYTE* ip = (
const BYTE*) source;
322 const BYTE* anchor = ip;
331 int ml, ml2, ml3, ml0;
352 while (ip < mflimit) {
354 if (!ml) { ip++;
continue; }
374 if (start2 < ip + ml0) {
382 if ((start2 - ip) < 3) {
397 if (ip+new_ml > start2 + ml2 -
MINMATCH) new_ml = (int)(start2 - ip) + ml2 -
MINMATCH;
398 correction = new_ml - (int)(start2 - ip);
399 if (correction > 0) {
400 start2 += correction;
407 if (start2 + ml2 < mflimit)
414 if (start2 < ip+ml) ml = (int)(start2 - ip);
424 if (start3 < ip+ml+3) {
425 if (start3 >= (ip+ml)) {
426 if (start2 < ip+ml) {
427 int correction = (int)(ip+ml - start2);
428 start2 += correction;
460 if (start2 < ip+ml) {
461 if ((start2 - ip) < (int)
ML_MASK) {
464 if (ip + ml > start2 + ml2 -
MINMATCH) ml = (int)(start2 - ip) + ml2 -
MINMATCH;
465 correction = ml - (int)(start2 - ip);
466 if (correction > 0) {
467 start2 += correction;
472 ml = (int)(start2 - ip);
491 {
size_t lastRunSize = (
size_t)(iend - anchor);
492 size_t litLength = (lastRunSize + 255 -
RUN_MASK) / 255;
493 size_t const totalSize = 1 + litLength + lastRunSize;
495 if (limit && (op + totalSize > oend)) {
498 lastRunSize = (
size_t)(oend - op) - 1;
499 litLength = (lastRunSize + 255 -
RUN_MASK) / 255;
500 lastRunSize -= litLength;
502 ip = anchor + lastRunSize;
505 size_t accumulator = lastRunSize -
RUN_MASK;
507 for(; accumulator >= 255 ; accumulator -= 255) *op++ = 255;
508 *op++ = (
BYTE) accumulator;
512 memcpy(op, anchor, lastRunSize);
517 *srcSizePtr = (int) (((
const char*)ip) -
source);
518 return (
int) (((
char*)op)-
dest);
530 switch (compressionLevel) {
533 case 12:
return 1<<10;
539 const char*
const src,
541 int*
const srcSizePtr,
542 int const dstCapacity,
573 if (((
size_t)(
state)&(
sizeof(
void*)-1)) != 0)
return 0;
583 #if defined(LZ4HC_HEAPMODE) && LZ4HC_HEAPMODE==1 590 #if defined(LZ4HC_HEAPMODE) && LZ4HC_HEAPMODE==1 629 if (dictSize > 64
KB) {
630 dictionary += dictSize - 64
KB;
634 ctxPtr->
end = (
const BYTE*)dictionary + dictSize;
657 ctxPtr->
end = newBlock;
662 const char*
src,
char*
dst,
663 int* srcSizePtr,
int dstCapacity,
671 if ((
size_t)(ctxPtr->
end - ctxPtr->
base) > 2
GB) {
673 if (dictSize > 64
KB) dictSize = 64
KB;
674 LZ4_loadDictHC(LZ4_streamHCPtr, (
const char*)(ctxPtr->
end) - dictSize, (
int)dictSize);
681 {
const BYTE* sourceEnd = (
const BYTE*) src + *srcSizePtr;
684 if ((sourceEnd > dictBegin) && ((
const BYTE*)src < dictEnd)) {
685 if (sourceEnd > dictEnd) sourceEnd = dictEnd;
716 int const prefixSize = (int)(streamPtr->
end - (streamPtr->
base + streamPtr->
dictLimit));
717 if (dictSize > 64
KB) dictSize = 64
KB;
718 if (dictSize < 4) dictSize = 0;
719 if (dictSize > prefixSize) dictSize = prefixSize;
720 memmove(safeBuffer, streamPtr->
end - dictSize, dictSize);
721 {
U32 const endIndex = (
U32)(streamPtr->
end - streamPtr->
base);
722 streamPtr->
end = (
const BYTE*)safeBuffer + dictSize;
723 streamPtr->
base = streamPtr->
end - endIndex;
724 streamPtr->
dictLimit = endIndex - dictSize;
725 streamPtr->
lowLimit = endIndex - dictSize;
744 int LZ4_compressHC2_limitedOutput_withStateHC (
void*
state,
const char*
src,
char*
dst,
int srcSize,
int maxDstSize,
int cLevel) {
return LZ4_compress_HC_extStateHC(state, src, dst, srcSize, maxDstSize, cLevel); }
755 if ((((
size_t)state) & (
sizeof(
void*)-1)) != 0)
return 1;
unsigned char * inputBuffer
int LZ4_freeHC(void *LZ4HC_Data)
static int LZ4HC_compress_optimal(LZ4HC_CCtx_internal *ctx, const char *const source, char *dest, int inputSize, int maxOutputSize, limitedOutput_directive limit, size_t sufficient_len, const int fullUpdate)
FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch(LZ4HC_CCtx_internal *hc4, const BYTE *const ip, const BYTE *const iLowLimit, const BYTE *const iHighLimit, int longest, const BYTE **matchpos, const BYTE **startpos, const int maxNbAttempts)
#define LZ4HC_CLEVEL_DEFAULT
int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, const char *dictionary, int dictSize)
int LZ4_compressHC2_withStateHC(void *state, const char *src, char *dst, int srcSize, int cLevel)
int LZ4_compressHC(const char *src, char *dst, int srcSize)
static U32 LZ4HC_hashPtr(const void *ptr)
int LZ4_compressHC_withStateHC(void *state, const char *src, char *dst, int srcSize)
#define LZ4HC_CLEVEL_OPT_MIN
LZ4LIB_API char * inputBuffer
static int LZ4HC_getSearchNum(int compressionLevel)
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
int LZ4_freeStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr)
void LZ4_resetStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
LZ4HC_CCtx_internal internal_donotuse
union LZ4_streamHC_u LZ4_streamHC_t
FORCE_INLINE int LZ4HC_encodeSequence(const BYTE **ip, BYTE **op, const BYTE **anchor, int matchLength, const BYTE *const match, limitedOutput_directive limit, BYTE *oend)
LZ4LIB_API char int int compressionLevel
GLfloat GLfloat GLfloat GLfloat h
static void LZ4HC_setExternalDict(LZ4HC_CCtx_internal *ctxPtr, const BYTE *newBlock)
LZ4_streamHC_t * LZ4_createStreamHC(void)
const unsigned char * dictBase
int LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize, int maxDstSize)
int LZ4_compressHC2_continue(void *LZ4HC_Data, const char *src, char *dst, int srcSize, int cLevel)
FORCE_INLINE int LZ4HC_InsertAndFindBestMatch(LZ4HC_CCtx_internal *const hc4, const BYTE *const ip, const BYTE *const iLimit, const BYTE **matchpos, const int maxNbAttempts)
unsigned int hashTable[LZ4HC_HASHTABLESIZE]
int LZ4_compressHC_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize)
int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int *srcSizePtr, int targetDestSize)
int LZ4_compressHC2_limitedOutput_continue(void *LZ4HC_Data, const char *src, char *dst, int srcSize, int dstCapacity, int cLevel)
static int LZ4_compressHC_continue_generic(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int *srcSizePtr, int dstCapacity, limitedOutput_directive limit)
int LZ4_compress_HC_destSize(void *LZ4HC_Data, const char *source, char *dest, int *sourceSizePtr, int targetDestSize, int cLevel)
int LZ4_compressHC2_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
FORCE_INLINE void LZ4HC_updateBinTree(LZ4HC_CCtx_internal *ctx, const BYTE *const ip, const BYTE *const iHighLimit)
FORCE_INLINE void LZ4HC_Insert(LZ4HC_CCtx_internal *hc4, const BYTE *ip)
int LZ4_resetStreamStateHC(void *state, char *inputBuffer)
unsigned int nextToUpdate
static void LZ4HC_init(LZ4HC_CCtx_internal *hc4, const BYTE *start)
#define DELTANEXTU16(table, pos)
static const int LZ4_minLength
int LZ4_sizeofStateHC(void)
void * LZ4_createHC(char *inputBuffer)
static void LZ4_writeLE16(void *memPtr, U16 value)
int LZ4_compressHC_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize)
static void LZ4_wildCopy(void *dstPtr, const void *srcPtr, void *dstEnd)
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int srcSize, int dstCapacity)
static U32 LZ4_read32(const void *memPtr)
#define LZ4_STATIC_ASSERT(c)
#define LZ4_MAX_INPUT_SIZE
LZ4LIB_API const char char int inputSize
const unsigned char * base
static int LZ4HC_compress_generic(LZ4HC_CCtx_internal *const ctx, const char *const src, char *const dst, int *const srcSizePtr, int const dstCapacity, int cLevel, limitedOutput_directive limit)
int LZ4_compressHC2_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
LZ4LIB_API char int int maxDstSize
LZ4LIB_API char int int maxOutputSize
int LZ4_compressHC2(const char *src, char *dst, int srcSize, int cLevel)
GLsizei GLsizei GLchar * source
#define LZ4_STREAMHCSIZE_SIZET
int LZ4_sizeofStreamStateHC(void)
int LZ4_compressBound(int isize)
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
GLenum GLuint GLenum GLsizei length
char * LZ4_slideInputBufferHC(void *LZ4HC_Data)
unsigned short chainTable[LZ4HC_MAXD]
static int LZ4HC_compress_hashChain(LZ4HC_CCtx_internal *const ctx, const char *const source, char *const dest, int *srcSizePtr, int const maxOutputSize, unsigned maxNbAttempts, limitedOutput_directive limit)
int LZ4_compressHC_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize)
const unsigned char * end
static unsigned LZ4_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *pInLimit)
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)