| 7825 | To be used when primary method fails. */ |
| 7826 | |
| 7827 | static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue) |
| 7828 | { |
| 7829 | short const NOT_YET_ASSIGNED = -2; |
| 7830 | U32 s; |
| 7831 | U32 distributed = 0; |
| 7832 | U32 ToDistribute; |
| 7833 | |
| 7834 | /* Init */ |
| 7835 | U32 const lowThreshold = (U32)(total >> tableLog); |
| 7836 | U32 lowOne = (U32)((total * 3) >> (tableLog + 1)); |
| 7837 | |
| 7838 | for (s=0; s<=maxSymbolValue; s++) { |
| 7839 | if (count[s] == 0) { |
| 7840 | norm[s]=0; |
| 7841 | continue; |
| 7842 | } |
| 7843 | if (count[s] <= lowThreshold) { |
| 7844 | norm[s] = -1; |
| 7845 | distributed++; |
| 7846 | total -= count[s]; |
| 7847 | continue; |
| 7848 | } |
| 7849 | if (count[s] <= lowOne) { |
| 7850 | norm[s] = 1; |
| 7851 | distributed++; |
| 7852 | total -= count[s]; |
| 7853 | continue; |
| 7854 | } |
| 7855 | |
| 7856 | norm[s]=NOT_YET_ASSIGNED; |
| 7857 | } |
| 7858 | ToDistribute = (1 << tableLog) - distributed; |
| 7859 | |
| 7860 | if (ToDistribute == 0) |
| 7861 | return 0; |
| 7862 | |
| 7863 | if ((total / ToDistribute) > lowOne) { |
| 7864 | /* risk of rounding to zero */ |
| 7865 | lowOne = (U32)((total * 3) / (ToDistribute * 2)); |
| 7866 | for (s=0; s<=maxSymbolValue; s++) { |
| 7867 | if ((norm[s] == NOT_YET_ASSIGNED) && (count[s] <= lowOne)) { |
| 7868 | norm[s] = 1; |
| 7869 | distributed++; |
| 7870 | total -= count[s]; |
| 7871 | continue; |
| 7872 | } } |
| 7873 | ToDistribute = (1 << tableLog) - distributed; |
| 7874 | } |
| 7875 | |
| 7876 | if (distributed == maxSymbolValue+1) { |
| 7877 | /* all values are pretty poor; |
| 7878 | probably incompressible data (should have already been detected); |
| 7879 | find max, then give all remaining points to max */ |
| 7880 | U32 maxV = 0, maxC = 0; |
| 7881 | for (s=0; s<=maxSymbolValue; s++) |
| 7882 | if (count[s] > maxC) { maxV=s; maxC=count[s]; } |
| 7883 | norm[maxV] += (short)ToDistribute; |
| 7884 | return 0; |
no outgoing calls
no test coverage detected