Fixed minor gcc5+ warning
This commit is contained in:
+22
-21
@@ -183,7 +183,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|||||||
/* early exit : all is fine */
|
/* early exit : all is fine */
|
||||||
if (largestBits <= maxNbBits) return largestBits;
|
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);
|
const U32 baseCost = 1 << (largestBits - maxNbBits);
|
||||||
U32 n = lastNonNull;
|
U32 n = lastNonNull;
|
||||||
@@ -193,25 +193,25 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|||||||
totalCost += baseCost - (1 << (largestBits - huffNode[n].nbBits));
|
totalCost += baseCost - (1 << (largestBits - huffNode[n].nbBits));
|
||||||
huffNode[n].nbBits = (BYTE)maxNbBits;
|
huffNode[n].nbBits = (BYTE)maxNbBits;
|
||||||
n --;
|
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 */
|
/* renorm totalCost */
|
||||||
totalCost >>= (largestBits - maxNbBits); /* note : totalCost necessarily multiple of baseCost */
|
totalCost >>= (largestBits - maxNbBits); /* note : totalCost is necessarily a multiple of baseCost */
|
||||||
|
|
||||||
// repay cost
|
|
||||||
while (huffNode[n].nbBits == maxNbBits) n--; // n at last of rank (maxNbBits-1)
|
|
||||||
|
|
||||||
|
/* repay normalized cost */
|
||||||
{
|
{
|
||||||
const U32 noOne = 0xF0F0F0F0;
|
const U32 noSymbol = 0xF0F0F0F0;
|
||||||
// Get pos of last (smallest) symbol per rank
|
U32 rankLast[HUF_MAX_TABLELOG+1];
|
||||||
U32 rankLast[HUF_MAX_TABLELOG];
|
|
||||||
U32 currentNbBits = maxNbBits;
|
U32 currentNbBits = maxNbBits;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
|
/* Get pos of last (smallest) symbol per rank */
|
||||||
memset(rankLast, 0xF0, sizeof(rankLast));
|
memset(rankLast, 0xF0, sizeof(rankLast));
|
||||||
for (pos=n ; pos >= 0; pos--)
|
for (pos=n ; pos >= 0; pos--)
|
||||||
{
|
{
|
||||||
if (huffNode[pos].nbBits >= currentNbBits) continue;
|
if (huffNode[pos].nbBits >= currentNbBits) continue;
|
||||||
currentNbBits = huffNode[pos].nbBits;
|
currentNbBits = huffNode[pos].nbBits; /* < maxNbBits */
|
||||||
rankLast[maxNbBits-currentNbBits] = pos;
|
rankLast[maxNbBits-currentNbBits] = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,33 +222,34 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|||||||
{
|
{
|
||||||
U32 highPos = rankLast[nBitsToDecrease];
|
U32 highPos = rankLast[nBitsToDecrease];
|
||||||
U32 lowPos = rankLast[nBitsToDecrease-1];
|
U32 lowPos = rankLast[nBitsToDecrease-1];
|
||||||
if (highPos == noOne) continue;
|
if (highPos == noSymbol) continue;
|
||||||
if (lowPos == noOne) break;
|
if (lowPos == noSymbol) break;
|
||||||
{
|
{
|
||||||
U32 highTotal = huffNode[highPos].count;
|
U32 highTotal = huffNode[highPos].count;
|
||||||
U32 lowTotal = 2 * huffNode[lowPos].count;
|
U32 lowTotal = 2 * huffNode[lowPos].count;
|
||||||
if (highTotal <= lowTotal) break;
|
if (highTotal <= lowTotal) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (rankLast[nBitsToDecrease] == noOne)
|
/* only triggered when no more rank 1 symbol left => find closest one (note : there is necessarily at least one !) */
|
||||||
nBitsToDecrease ++; // In some rare cases, no more rank 1 left => overshoot to closest
|
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);
|
totalCost -= 1 << (nBitsToDecrease-1);
|
||||||
if (rankLast[nBitsToDecrease-1] == noOne)
|
if (rankLast[nBitsToDecrease-1] == noSymbol)
|
||||||
rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt
|
rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; /* this rank is no longer empty */
|
||||||
huffNode[rankLast[nBitsToDecrease]].nbBits ++;
|
huffNode[rankLast[nBitsToDecrease]].nbBits ++;
|
||||||
if (rankLast[nBitsToDecrease] == 0)
|
if (rankLast[nBitsToDecrease] == 0) /* special case, reached largest symbol */
|
||||||
rankLast[nBitsToDecrease] = noOne;
|
rankLast[nBitsToDecrease] = noSymbol;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rankLast[nBitsToDecrease]--;
|
rankLast[nBitsToDecrease]--;
|
||||||
if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-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 */
|
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--;
|
while (huffNode[n].nbBits == maxNbBits) n--;
|
||||||
huffNode[n+1].nbBits--;
|
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);
|
if (maxSymbolValue > HUF_MAX_SYMBOL_VALUE) return ERROR(GENERIC);
|
||||||
memset(huffNode0, 0, sizeof(huffNode0));
|
memset(huffNode0, 0, sizeof(huffNode0));
|
||||||
|
|
||||||
// sort, decreasing order
|
/* sort, decreasing order */
|
||||||
HUF_sort(huffNode, count, maxSymbolValue);
|
HUF_sort(huffNode, count, maxSymbolValue);
|
||||||
|
|
||||||
// init for parents
|
// init for parents
|
||||||
|
|||||||
Reference in New Issue
Block a user