Fixed minor gcc5+ warning
This commit is contained in:
parent
7010c27a13
commit
8eb50b8acf
43
lib/huff0.c
43
lib/huff0.c
@ -183,7 +183,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
||||
/* early exit : all is fine */
|
||||
if (largestBits <= maxNbBits) return largestBits;
|
||||
|
||||
// now we have a few too large elements (at least >= 2)
|
||||
/* there are several too large elements (at least >= 2) */
|
||||
{
|
||||
const U32 baseCost = 1 << (largestBits - maxNbBits);
|
||||
U32 n = lastNonNull;
|
||||
@ -193,25 +193,25 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
||||
totalCost += baseCost - (1 << (largestBits - huffNode[n].nbBits));
|
||||
huffNode[n].nbBits = (BYTE)maxNbBits;
|
||||
n --;
|
||||
}
|
||||
} /* n stops at huffNode[n].nbBits <= maxNbBits */
|
||||
while (huffNode[n].nbBits == maxNbBits) n--; /* n end at index of smallest symbol using (maxNbBits-1) */
|
||||
|
||||
/* renorm totalCost */
|
||||
totalCost >>= (largestBits - maxNbBits); /* note : totalCost necessarily multiple of baseCost */
|
||||
|
||||
// repay cost
|
||||
while (huffNode[n].nbBits == maxNbBits) n--; // n at last of rank (maxNbBits-1)
|
||||
totalCost >>= (largestBits - maxNbBits); /* note : totalCost is necessarily a multiple of baseCost */
|
||||
|
||||
/* repay normalized cost */
|
||||
{
|
||||
const U32 noOne = 0xF0F0F0F0;
|
||||
// Get pos of last (smallest) symbol per rank
|
||||
U32 rankLast[HUF_MAX_TABLELOG];
|
||||
const U32 noSymbol = 0xF0F0F0F0;
|
||||
U32 rankLast[HUF_MAX_TABLELOG+1];
|
||||
U32 currentNbBits = maxNbBits;
|
||||
int pos;
|
||||
|
||||
/* Get pos of last (smallest) symbol per rank */
|
||||
memset(rankLast, 0xF0, sizeof(rankLast));
|
||||
for (pos=n ; pos >= 0; pos--)
|
||||
{
|
||||
if (huffNode[pos].nbBits >= currentNbBits) continue;
|
||||
currentNbBits = huffNode[pos].nbBits;
|
||||
currentNbBits = huffNode[pos].nbBits; /* < maxNbBits */
|
||||
rankLast[maxNbBits-currentNbBits] = pos;
|
||||
}
|
||||
|
||||
@ -222,33 +222,34 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
||||
{
|
||||
U32 highPos = rankLast[nBitsToDecrease];
|
||||
U32 lowPos = rankLast[nBitsToDecrease-1];
|
||||
if (highPos == noOne) continue;
|
||||
if (lowPos == noOne) break;
|
||||
if (highPos == noSymbol) continue;
|
||||
if (lowPos == noSymbol) break;
|
||||
{
|
||||
U32 highTotal = huffNode[highPos].count;
|
||||
U32 lowTotal = 2 * huffNode[lowPos].count;
|
||||
if (highTotal <= lowTotal) break;
|
||||
}
|
||||
}
|
||||
while (rankLast[nBitsToDecrease] == noOne)
|
||||
nBitsToDecrease ++; // In some rare cases, no more rank 1 left => overshoot to closest
|
||||
/* only triggered when no more rank 1 symbol left => find closest one (note : there is necessarily at least one !) */
|
||||
while ((nBitsToDecrease<=HUF_MAX_TABLELOG) && (rankLast[nBitsToDecrease] == noSymbol)) /* HUF_MAX_TABLELOG test just to please gcc 5+; but it should not be necessary */
|
||||
nBitsToDecrease ++;
|
||||
totalCost -= 1 << (nBitsToDecrease-1);
|
||||
if (rankLast[nBitsToDecrease-1] == noOne)
|
||||
rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt
|
||||
if (rankLast[nBitsToDecrease-1] == noSymbol)
|
||||
rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; /* this rank is no longer empty */
|
||||
huffNode[rankLast[nBitsToDecrease]].nbBits ++;
|
||||
if (rankLast[nBitsToDecrease] == 0)
|
||||
rankLast[nBitsToDecrease] = noOne;
|
||||
if (rankLast[nBitsToDecrease] == 0) /* special case, reached largest symbol */
|
||||
rankLast[nBitsToDecrease] = noSymbol;
|
||||
else
|
||||
{
|
||||
rankLast[nBitsToDecrease]--;
|
||||
if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease)
|
||||
rankLast[nBitsToDecrease] = noOne; // rank list emptied
|
||||
rankLast[nBitsToDecrease] = noSymbol; /* this rank is now empty */
|
||||
}
|
||||
}
|
||||
|
||||
while (totalCost < 0) /* Sometimes, cost correction overshoot */
|
||||
{
|
||||
if (rankLast[1] == noOne) /* special case, no weight 1, let's find it back at n */
|
||||
if (rankLast[1] == noSymbol) /* special case : no rank 1 symbol (using maxNbBits-1); let's create one from largest rank 0 (using maxNbBits) */
|
||||
{
|
||||
while (huffNode[n].nbBits == maxNbBits) n--;
|
||||
huffNode[n+1].nbBits--;
|
||||
@ -312,7 +313,7 @@ size_t HUF_buildCTable (HUF_CElt* tree, const U32* count, U32 maxSymbolValue, U3
|
||||
if (maxSymbolValue > HUF_MAX_SYMBOL_VALUE) return ERROR(GENERIC);
|
||||
memset(huffNode0, 0, sizeof(huffNode0));
|
||||
|
||||
// sort, decreasing order
|
||||
/* sort, decreasing order */
|
||||
HUF_sort(huffNode, count, maxSymbolValue);
|
||||
|
||||
// init for parents
|
||||
|
Loading…
Reference in New Issue
Block a user