mirror of
https://github.com/lz4/lz4.git
synced 2024-12-03 06:43:43 +08:00
17-bit LZ4HC_MAXD
This commit is contained in:
parent
c1ef7a177f
commit
2113ead176
16
lib/lz4hc.c
16
lib/lz4hc.c
@ -84,7 +84,7 @@
|
||||
* Local Macros
|
||||
**************************************/
|
||||
#define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-LZ4HC_HASH_LOG))
|
||||
/* #define DELTANEXTU16(p) chainTable[(p) & LZ4HC_MAXD_MASK] */ /* flexible, LZ4HC_MAXD dependent */
|
||||
#define DELTANEXTMAXD(p) chainTable[(p) & LZ4HC_MAXD_MASK] /* flexible, LZ4HC_MAXD dependent */
|
||||
#define DELTANEXTU16(p) chainTable[(U16)(p)] /* faster */
|
||||
|
||||
static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); }
|
||||
@ -499,14 +499,18 @@ static int LZ4HC_compress_generic (
|
||||
limitedOutput_directive limit
|
||||
)
|
||||
{
|
||||
/*
|
||||
16#silesia_tar : 211947520 -> 77841782 (2.723), 9.8 MB/s ,1874.4 MB/s
|
||||
|
||||
*/
|
||||
if (compressionLevel < 1) compressionLevel = LZ4HC_DEFAULT_CLEVEL;
|
||||
if (compressionLevel > 16) {
|
||||
switch (compressionLevel) {
|
||||
case 17: ctx->searchNum = 64; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 0, 64, 0);
|
||||
case 18: ctx->searchNum = 256; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 0, 256, 0);
|
||||
case 19: ctx->searchNum = 64; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 1, 64, 0);
|
||||
case 20:
|
||||
default: ctx->searchNum = 256; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 1, 256, 0);
|
||||
case 17: ctx->searchNum = 64; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 0, 64);
|
||||
case 18: ctx->searchNum = 256; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 0, 256);
|
||||
case 19: ctx->searchNum = 64; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 1, 64);
|
||||
default:
|
||||
case 20: ctx->searchNum = 1<<14; return LZ4HC_compress_optimal(ctx, source, dest, inputSize, maxOutputSize, limit, 1, LZ4_OPT_NUM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, in
|
||||
* Using these definitions makes the code vulnerable to potential API break when upgrading LZ4
|
||||
**************************************/
|
||||
#define LZ4HC_DICTIONARY_LOGSIZE 16
|
||||
#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
|
||||
#define LZ4HC_MAXD (1<<(LZ4HC_DICTIONARY_LOGSIZE+1))
|
||||
#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
|
||||
|
||||
#define LZ4HC_HASH_LOG (LZ4HC_DICTIONARY_LOGSIZE-1)
|
||||
@ -176,7 +176,7 @@ typedef struct
|
||||
|
||||
#endif
|
||||
|
||||
#define LZ4_STREAMHCSIZE 262200
|
||||
#define LZ4_STREAMHCSIZE 4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 52 /* 393268 */
|
||||
#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
|
||||
union LZ4_streamHC_u {
|
||||
size_t table[LZ4_STREAMHCSIZE_SIZET];
|
||||
|
51
lib/lz4opt.h
51
lib/lz4opt.h
@ -210,8 +210,8 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
||||
ctx->nextToUpdate++;
|
||||
|
||||
// check rest of matches
|
||||
ptr0 = &DELTANEXTU16(current*2+1);
|
||||
ptr1 = &DELTANEXTU16(current*2);
|
||||
ptr0 = &DELTANEXTMAXD(current*2+1);
|
||||
ptr1 = &DELTANEXTMAXD(current*2);
|
||||
delta0 = delta1 = current - matchIndex;
|
||||
|
||||
while ((matchIndex < current) && (matchIndex>=lowLimit) && (nbAttempts))
|
||||
@ -265,7 +265,7 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
||||
if (*(ip+mlt) < *(match+mlt))
|
||||
{
|
||||
*ptr0 = delta0;
|
||||
ptr0 = &DELTANEXTU16(matchIndex*2);
|
||||
ptr0 = &DELTANEXTMAXD(matchIndex*2);
|
||||
// printf("delta0=%d\n", delta0);
|
||||
if (*ptr0 == (U16)-1) break;
|
||||
delta0 = *ptr0;
|
||||
@ -275,7 +275,7 @@ FORCE_INLINE int LZ4HC_BinTree_GetAllMatches (
|
||||
else
|
||||
{
|
||||
*ptr1 = delta1;
|
||||
ptr1 = &DELTANEXTU16(matchIndex*2+1);
|
||||
ptr1 = &DELTANEXTMAXD(matchIndex*2+1);
|
||||
// printf("delta1=%d\n", delta1);
|
||||
if (*ptr1 == (U16)-1) break;
|
||||
delta1 = *ptr1;
|
||||
@ -313,14 +313,13 @@ static int LZ4HC_compress_optimal (
|
||||
int maxOutputSize,
|
||||
limitedOutput_directive limit,
|
||||
const int binaryTreeFinder,
|
||||
const size_t sufficient_len,
|
||||
const int faster_get_matches
|
||||
const size_t sufficient_len
|
||||
)
|
||||
{
|
||||
LZ4HC_optimal_t opt[LZ4_OPT_NUM + 4];
|
||||
LZ4HC_match_t matches[LZ4_OPT_NUM + 1];
|
||||
const BYTE *inr;
|
||||
size_t res, cur, cur2, skip_num = 0;
|
||||
size_t res, cur, cur2;
|
||||
size_t i, llen, litlen, mlen, best_mlen, price, offset, best_off, match_num, last_pos;
|
||||
|
||||
const BYTE* ip = (const BYTE*) source;
|
||||
@ -330,7 +329,6 @@ static int LZ4HC_compress_optimal (
|
||||
const BYTE* const matchlimit = (iend - LASTLITERALS);
|
||||
BYTE* op = (BYTE*) dest;
|
||||
BYTE* const oend = op + maxOutputSize;
|
||||
|
||||
|
||||
/* init */
|
||||
ctx->end += inputSize;
|
||||
@ -343,22 +341,17 @@ static int LZ4HC_compress_optimal (
|
||||
last_pos = 0;
|
||||
llen = ip - anchor;
|
||||
|
||||
best_mlen = (last_pos) ? last_pos : (MINMATCH-1);
|
||||
best_mlen = MINMATCH-1;
|
||||
|
||||
if (faster_get_matches && last_pos)
|
||||
match_num = 0;
|
||||
else
|
||||
{
|
||||
if (!binaryTreeFinder)
|
||||
{
|
||||
LZ4HC_Insert(ctx, ip);
|
||||
match_num = LZ4HC_GetAllMatches(ctx, ip, ip, matchlimit, best_mlen, matches);
|
||||
}
|
||||
else
|
||||
{
|
||||
match_num = LZ4HC_BinTree_GetAllMatches(ctx, ip, matchlimit, best_mlen, matches);
|
||||
}
|
||||
}
|
||||
if (!binaryTreeFinder)
|
||||
{
|
||||
LZ4HC_Insert(ctx, ip);
|
||||
match_num = LZ4HC_GetAllMatches(ctx, ip, ip, matchlimit, best_mlen, matches);
|
||||
}
|
||||
else
|
||||
{
|
||||
match_num = LZ4HC_BinTree_GetAllMatches(ctx, ip, matchlimit, best_mlen, matches);
|
||||
}
|
||||
|
||||
LZ4_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-source), match_num, last_pos);
|
||||
if (!last_pos && !match_num) { ip++; continue; }
|
||||
@ -393,7 +386,7 @@ static int LZ4HC_compress_optimal (
|
||||
opt[0].mlen = opt[1].mlen = 1;
|
||||
|
||||
// check further positions
|
||||
for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
|
||||
for (cur = 1; cur <= last_pos; cur++)
|
||||
{
|
||||
inr = ip + cur;
|
||||
|
||||
@ -430,14 +423,6 @@ static int LZ4HC_compress_optimal (
|
||||
|
||||
LZ4_LOG_PARSER("%d: CURRENT price[%d/%d]=%d off=%d mlen=%d litlen=%d\n", (int)(inr-source), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen);
|
||||
|
||||
|
||||
if (faster_get_matches && skip_num > 0)
|
||||
{
|
||||
skip_num--;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
best_mlen = (best_mlen > MINMATCH) ? best_mlen : (MINMATCH-1);
|
||||
|
||||
if (!binaryTreeFinder)
|
||||
@ -500,7 +485,7 @@ static int LZ4HC_compress_optimal (
|
||||
mlen++;
|
||||
}
|
||||
}
|
||||
} // for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
|
||||
} // for (cur = 1; cur <= last_pos; cur++)
|
||||
|
||||
|
||||
best_mlen = opt[last_pos].mlen;
|
||||
|
Loading…
Reference in New Issue
Block a user