priceFunc
diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c
index 6312ea3..8a5f6f6 100644
--- a/lib/zstd_compress.c
+++ b/lib/zstd_compress.c
@@ -1919,8 +1919,10 @@
BYTE* op = ostart;
const U32 maxDist = 1 << zc->params.windowLog;
seqStore_t* ssPtr = &zc->seqStore;
+ static U32 priceFunc = 0;
- ssPtr->realMatchSum = ssPtr->realLitSum = ssPtr->realSeqSum = ssPtr->realRepSum = 0;
+ ssPtr->realMatchSum = ssPtr->realLitSum = ssPtr->realSeqSum = ssPtr->realRepSum = 1;
+ ssPtr->priceFunc = priceFunc;
while (remaining) {
size_t cSize;
@@ -1954,9 +1956,11 @@
op += cSize;
}
+
#if ZSTD_OPT_DEBUG >= 3
ssPtr->realMatchSum += ssPtr->realSeqSum * ((zc->params.searchLength == 3) ? 3 : 4);
- printf("avgMatchL=%.2f avgLitL=%.2f match=%.1f%% lit=%.1f%% reps=%d seq=%d\n", (float)ssPtr->realMatchSum/ssPtr->realSeqSum, (float)ssPtr->realLitSum/ssPtr->realSeqSum, 100.0*ssPtr->realMatchSum/(ssPtr->realMatchSum+ssPtr->realLitSum), 100.0*ssPtr->realLitSum/(ssPtr->realMatchSum+ssPtr->realLitSum), ssPtr->realRepSum, ssPtr->realSeqSum);
+ printf("avgMatchL=%.2f avgLitL=%.2f match=%.1f%% lit=%.1f%% reps=%d seq=%d priceFunc=%d\n", (float)ssPtr->realMatchSum/ssPtr->realSeqSum, (float)ssPtr->realLitSum/ssPtr->realSeqSum, 100.0*ssPtr->realMatchSum/(ssPtr->realMatchSum+ssPtr->realLitSum), 100.0*ssPtr->realLitSum/(ssPtr->realMatchSum+ssPtr->realLitSum), ssPtr->realRepSum, ssPtr->realSeqSum, ssPtr->priceFunc);
+ priceFunc++;
#endif
return op-ostart;
diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h
index 39b76d8..c575f46 100644
--- a/lib/zstd_internal.h
+++ b/lib/zstd_internal.h
@@ -176,6 +176,7 @@
U32* litFreq;
U32* offCodeFreq;
U32 matchLengthSum;
+ U32 matchSum;
U32 litLengthSum;
U32 litSum;
U32 offCodeSum;
@@ -183,6 +184,7 @@
U32 realLitSum;
U32 realSeqSum;
U32 realRepSum;
+ U32 priceFunc;
} seqStore_t;
seqStore_t ZSTD_copySeqStore(const ZSTD_CCtx* ctx);
diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h
index b5b10ef..4169f87 100644
--- a/lib/zstd_opt.h
+++ b/lib/zstd_opt.h
@@ -46,18 +46,20 @@
if (matchLength >= MaxML) matchLength = MaxML;
price += ZSTD_highbit(seqStorePtr->matchLengthSum) - ZSTD_highbit(seqStorePtr->matchLengthFreq[matchLength]);
-#if 0
- if (!litLength)
- return price + 1 + ((seqStorePtr->litSum>>4) / seqStorePtr->litLengthSum) + (matchLength==0);
-
- return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum>>4) / seqStorePtr->litLengthSum) + (matchLength==0);
-#else
- if (!litLength)
- return price + 1;
-
- return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals);
-// return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals);
-#endif
+#define ZSTD_PRICE_MULT 2
+ switch (seqStorePtr->priceFunc)
+ {
+ default:
+ case 0:
+ if (!litLength) return price + 1 + ((seqStorePtr->litSum<<ZSTD_PRICE_MULT) / (seqStorePtr->litSum + seqStorePtr->matchSum)) + (matchLength==0);
+ return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum<<ZSTD_PRICE_MULT) / (seqStorePtr->litSum + seqStorePtr->matchSum)) + (matchLength==0);
+ case 1:
+ if (!litLength) return price + 1 + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + (matchLength==0);
+ return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ((seqStorePtr->litSum>>5) / seqStorePtr->litLengthSum) + (matchLength==0);
+ case 2:
+ if (!litLength) return price + 1;
+ return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals);
+ }
}
diff --git a/lib/zstd_opt_internal.h b/lib/zstd_opt_internal.h
index 47d5a49..e9ca5f2 100644
--- a/lib/zstd_opt_internal.h
+++ b/lib/zstd_opt_internal.h
@@ -43,7 +43,7 @@
#define ZSTD_OPT_NUM (1<<12)
#define ZSTD_FREQ_START 1
#define ZSTD_FREQ_STEP 1
-#define ZSTD_FREQ_DIV 6
+#define ZSTD_FREQ_DIV 5
/*- Debug -*/
#if defined(ZSTD_OPT_DEBUG) && ZSTD_OPT_DEBUG>=9
@@ -94,6 +94,7 @@
ssPtr->matchLengthSum = 0;
ssPtr->litLengthSum = 0;
ssPtr->litSum = 0;
+ ssPtr->matchSum = 0;
ssPtr->offCodeSum = 0;
for (u=0; u<=MaxLit; u++) {
@@ -107,6 +108,7 @@
for (u=0; u<=MaxML; u++) {
ssPtr->matchLengthFreq[u] = ZSTD_FREQ_START + (ssPtr->matchLengthFreq[u]>>ZSTD_FREQ_DIV);
ssPtr->matchLengthSum += ssPtr->matchLengthFreq[u];
+ ssPtr->matchSum += ssPtr->matchLengthFreq[u] * (u + 3);
}
for (u=0; u<=MaxOff; u++) {
ssPtr->offCodeFreq[u] = ZSTD_FREQ_START + (ssPtr->offCodeFreq[u]>>ZSTD_FREQ_DIV);