Lines Matching +full:count +full:- +full:threshold
6 * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
7 * - Public forum : https://groups.google.com/forum/#!forum/lz4c
9 * This source code is licensed under both the BSD-style license (found in the
12 * You may select, at your option, one of the above-listed licenses.
42 for type-specific functions (template emulation in C)
72 U32 const tableMask = tableSize - 1; in FSE_buildCTable_wksp()
83 U32 highThreshold = tableSize-1; in FSE_buildCTable_wksp()
85 assert(((size_t)workSpace & 1) == 0); /* Must be 2 bytes-aligned */ in FSE_buildCTable_wksp()
88 tableU16[-2] = (U16) tableLog; in FSE_buildCTable_wksp()
89 tableU16[-1] = (U16) maxSymbolValue; in FSE_buildCTable_wksp()
90 assert(tableLog < 16); /* required for threshold strategy to work */ in FSE_buildCTable_wksp()
93 * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */ in FSE_buildCTable_wksp()
96 …0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */ in FSE_buildCTable_wksp()
103 if (normalizedCounter[u-1]==-1) { /* Low proba symbol */ in FSE_buildCTable_wksp()
104 cumul[u] = cumul[u-1] + 1; in FSE_buildCTable_wksp()
105 tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1); in FSE_buildCTable_wksp()
107 assert(normalizedCounter[u-1] >= 0); in FSE_buildCTable_wksp()
108 cumul[u] = cumul[u-1] + (U16)normalizedCounter[u-1]; in FSE_buildCTable_wksp()
109 assert(cumul[u] >= cumul[u-1]); /* no overflow */ in FSE_buildCTable_wksp()
115 if (highThreshold == tableSize - 1) { in FSE_buildCTable_wksp()
116 /* Case for no low prob count symbols. Lay down 8 bytes at a time in FSE_buildCTable_wksp()
182 symbolTT[s].deltaNbBits = ((tableLog+1) << 16) - (1<<tableLog); in FSE_buildCTable_wksp()
185 case -1: in FSE_buildCTable_wksp()
187 symbolTT[s].deltaNbBits = (tableLog << 16) - (1<<tableLog); in FSE_buildCTable_wksp()
189 symbolTT[s].deltaFindState = (int)(total - 1); in FSE_buildCTable_wksp()
194 { U32 const maxBitsOut = tableLog - BIT_highbit32 ((U32)normalizedCounter[s]-1); in FSE_buildCTable_wksp()
196 symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus; in FSE_buildCTable_wksp()
197 symbolTT[s].deltaFindState = (int)(total - (unsigned)normalizedCounter[s]); in FSE_buildCTable_wksp()
202 DEBUGLOG(5, "\n --- table statistics : "); in FSE_buildCTable_wksp()
219 /*-**************************************************************
243 int threshold; in FSE_writeNCount_generic() local
251 bitStream += (tableLog-FSE_MIN_TABLELOG) << bitCount; in FSE_writeNCount_generic()
256 threshold = tableSize; in FSE_writeNCount_generic()
267 if ((!writeIsSafe) && (out > oend-2)) in FSE_writeNCount_generic()
279 bitStream += (symbol-start) << bitCount; in FSE_writeNCount_generic()
282 if ((!writeIsSafe) && (out > oend - 2)) in FSE_writeNCount_generic()
288 bitCount -= 16; in FSE_writeNCount_generic()
290 { int count = normalizedCounter[symbol++]; in FSE_writeNCount_generic() local
291 int const max = (2*threshold-1) - remaining; in FSE_writeNCount_generic()
292 remaining -= count < 0 ? -count : count; in FSE_writeNCount_generic()
293 count++; /* +1 for extra accuracy */ in FSE_writeNCount_generic()
294 if (count>=threshold) in FSE_writeNCount_generic()
295 count += max; /* [0..max[ [max..threshold[ (...) [threshold+max 2*threshold[ */ in FSE_writeNCount_generic()
296 bitStream += count << bitCount; in FSE_writeNCount_generic()
298 bitCount -= (count<max); in FSE_writeNCount_generic()
299 previousIs0 = (count==1); in FSE_writeNCount_generic()
301 while (remaining<threshold) { nbBits--; threshold>>=1; } in FSE_writeNCount_generic()
304 if ((!writeIsSafe) && (out > oend - 2)) in FSE_writeNCount_generic()
310 bitCount -= 16; in FSE_writeNCount_generic()
318 if ((!writeIsSafe) && (out > oend - 2)) in FSE_writeNCount_generic()
324 return (out-ostart); in FSE_writeNCount_generic()
341 /*-**************************************************************
367 U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus; in FSE_optimalTableLog_internal()
387 static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 m… in FSE_normalizeM2() argument
389 short const NOT_YET_ASSIGNED = -2; in FSE_normalizeM2()
399 if (count[s] == 0) { in FSE_normalizeM2()
403 if (count[s] <= lowThreshold) { in FSE_normalizeM2()
406 total -= count[s]; in FSE_normalizeM2()
409 if (count[s] <= lowOne) { in FSE_normalizeM2()
412 total -= count[s]; in FSE_normalizeM2()
418 ToDistribute = (1 << tableLog) - distributed; in FSE_normalizeM2()
427 if ((norm[s] == NOT_YET_ASSIGNED) && (count[s] <= lowOne)) { in FSE_normalizeM2()
430 total -= count[s]; in FSE_normalizeM2()
433 ToDistribute = (1 << tableLog) - distributed; in FSE_normalizeM2()
442 if (count[s] > maxC) { maxV=s; maxC=count[s]; } in FSE_normalizeM2()
450 if (norm[s] > 0) { ToDistribute--; norm[s]++; } in FSE_normalizeM2()
454 { U64 const vStepLog = 62 - tableLog; in FSE_normalizeM2()
455 U64 const mid = (1ULL << (vStepLog-1)) - 1; in FSE_normalizeM2()
460 U64 const end = tmpTotal + (count[s] * rStep); in FSE_normalizeM2()
463 U32 const weight = sEnd - sStart; in FSE_normalizeM2()
474 const unsigned* count, size_t total, in FSE_normalizeCount() argument
484 short const lowProbCount = useLowProbCount ? -1 : 1; in FSE_normalizeCount()
485 U64 const scale = 62 - tableLog; in FSE_normalizeCount()
487 U64 const vStep = 1ULL<<(scale-20); in FSE_normalizeCount()
495 if (count[s] == total) return 0; /* rle special case */ in FSE_normalizeCount()
496 if (count[s] == 0) { normalizedCounter[s]=0; continue; } in FSE_normalizeCount()
497 if (count[s] <= lowThreshold) { in FSE_normalizeCount()
499 stillToDistribute--; in FSE_normalizeCount()
501 short proba = (short)((count[s]*step) >> scale); in FSE_normalizeCount()
504 proba += (count[s]*step) - ((U64)proba<<scale) > restToBeat; in FSE_normalizeCount()
508 stillToDistribute -= proba; in FSE_normalizeCount()
510 if (-stillToDistribute >= (normalizedCounter[largest] >> 1)) { in FSE_normalizeCount()
512 …size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue… in FSE_normalizeCount()
540 const unsigned tableMask = tableSize - 1; in FSE_buildCTable_raw()
552 tableU16[-2] = (U16) nbBits; in FSE_buildCTable_raw()
553 tableU16[-1] = (U16) maxSymbolValue; in FSE_buildCTable_raw()
560 { const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits); in FSE_buildCTable_raw()
563 symbolTT[s].deltaFindState = s-1; in FSE_buildCTable_raw()
578 tableU16[-2] = (U16) 0; in FSE_buildCTable_rle()
579 tableU16[-1] = (U16) symbolValue; in FSE_buildCTable_rle()
612 FSE_initCState2(&CState1, ct, *--ip); in FSE_compress_usingCTable_generic()
613 FSE_initCState2(&CState2, ct, *--ip); in FSE_compress_usingCTable_generic()
614 FSE_encodeSymbol(&bitC, &CState1, *--ip); in FSE_compress_usingCTable_generic()
617 FSE_initCState2(&CState2, ct, *--ip); in FSE_compress_usingCTable_generic()
618 FSE_initCState2(&CState1, ct, *--ip); in FSE_compress_usingCTable_generic()
622 srcSize -= 2; in FSE_compress_usingCTable_generic()
624 FSE_encodeSymbol(&bitC, &CState2, *--ip); in FSE_compress_usingCTable_generic()
625 FSE_encodeSymbol(&bitC, &CState1, *--ip); in FSE_compress_usingCTable_generic()
632 FSE_encodeSymbol(&bitC, &CState2, *--ip); in FSE_compress_usingCTable_generic()
637 FSE_encodeSymbol(&bitC, &CState1, *--ip); in FSE_compress_usingCTable_generic()
640 FSE_encodeSymbol(&bitC, &CState2, *--ip); in FSE_compress_usingCTable_generic()
641 FSE_encodeSymbol(&bitC, &CState1, *--ip); in FSE_compress_usingCTable_generic()
678 unsigned count[FSE_MAX_SYMBOL_VALUE+1]; in FSE_compress_wksp() local
683 size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable)); in FSE_compress_wksp()
692 …{ CHECK_V_F(maxCount, HIST_count_wksp(count, &maxSymbolValue, src, srcSize, scratchBuffer, scrat… in FSE_compress_wksp()
699 …CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue, /* useLowProbCount */ … in FSE_compress_wksp()
702 { CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) ); in FSE_compress_wksp()
708 { CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) ); in FSE_compress_wksp()
714 if ( (size_t)(op-ostart) >= srcSize-1 ) return 0; in FSE_compress_wksp()
716 return op-ostart; in FSE_compress_wksp()