762 /* note : the result of this phase should be used to better appreciate the impact on statistics */ |
762 /* note : the result of this phase should be used to better appreciate the impact on statistics */ |
763 |
763 |
764 total=0; for (u=0; u<=offcodeMax; u++) total+=offcodeCount[u]; |
764 total=0; for (u=0; u<=offcodeMax; u++) total+=offcodeCount[u]; |
765 errorCode = FSE_normalizeCount(offcodeNCount, Offlog, offcodeCount, total, offcodeMax); |
765 errorCode = FSE_normalizeCount(offcodeNCount, Offlog, offcodeCount, total, offcodeMax); |
766 if (FSE_isError(errorCode)) { |
766 if (FSE_isError(errorCode)) { |
767 eSize = ERROR(GENERIC); |
767 eSize = errorCode; |
768 DISPLAYLEVEL(1, "FSE_normalizeCount error with offcodeCount \n"); |
768 DISPLAYLEVEL(1, "FSE_normalizeCount error with offcodeCount \n"); |
769 goto _cleanup; |
769 goto _cleanup; |
770 } |
770 } |
771 Offlog = (U32)errorCode; |
771 Offlog = (U32)errorCode; |
772 |
772 |
773 total=0; for (u=0; u<=MaxML; u++) total+=matchLengthCount[u]; |
773 total=0; for (u=0; u<=MaxML; u++) total+=matchLengthCount[u]; |
774 errorCode = FSE_normalizeCount(matchLengthNCount, mlLog, matchLengthCount, total, MaxML); |
774 errorCode = FSE_normalizeCount(matchLengthNCount, mlLog, matchLengthCount, total, MaxML); |
775 if (FSE_isError(errorCode)) { |
775 if (FSE_isError(errorCode)) { |
776 eSize = ERROR(GENERIC); |
776 eSize = errorCode; |
777 DISPLAYLEVEL(1, "FSE_normalizeCount error with matchLengthCount \n"); |
777 DISPLAYLEVEL(1, "FSE_normalizeCount error with matchLengthCount \n"); |
778 goto _cleanup; |
778 goto _cleanup; |
779 } |
779 } |
780 mlLog = (U32)errorCode; |
780 mlLog = (U32)errorCode; |
781 |
781 |
782 total=0; for (u=0; u<=MaxLL; u++) total+=litLengthCount[u]; |
782 total=0; for (u=0; u<=MaxLL; u++) total+=litLengthCount[u]; |
783 errorCode = FSE_normalizeCount(litLengthNCount, llLog, litLengthCount, total, MaxLL); |
783 errorCode = FSE_normalizeCount(litLengthNCount, llLog, litLengthCount, total, MaxLL); |
784 if (FSE_isError(errorCode)) { |
784 if (FSE_isError(errorCode)) { |
785 eSize = ERROR(GENERIC); |
785 eSize = errorCode; |
786 DISPLAYLEVEL(1, "FSE_normalizeCount error with litLengthCount \n"); |
786 DISPLAYLEVEL(1, "FSE_normalizeCount error with litLengthCount \n"); |
787 goto _cleanup; |
787 goto _cleanup; |
788 } |
788 } |
789 llLog = (U32)errorCode; |
789 llLog = (U32)errorCode; |
790 |
790 |
791 /* write result to buffer */ |
791 /* write result to buffer */ |
792 { size_t const hhSize = HUF_writeCTable(dstPtr, maxDstSize, hufTable, 255, huffLog); |
792 { size_t const hhSize = HUF_writeCTable(dstPtr, maxDstSize, hufTable, 255, huffLog); |
793 if (HUF_isError(hhSize)) { |
793 if (HUF_isError(hhSize)) { |
794 eSize = ERROR(GENERIC); |
794 eSize = hhSize; |
795 DISPLAYLEVEL(1, "HUF_writeCTable error \n"); |
795 DISPLAYLEVEL(1, "HUF_writeCTable error \n"); |
796 goto _cleanup; |
796 goto _cleanup; |
797 } |
797 } |
798 dstPtr += hhSize; |
798 dstPtr += hhSize; |
799 maxDstSize -= hhSize; |
799 maxDstSize -= hhSize; |
800 eSize += hhSize; |
800 eSize += hhSize; |
801 } |
801 } |
802 |
802 |
803 { size_t const ohSize = FSE_writeNCount(dstPtr, maxDstSize, offcodeNCount, OFFCODE_MAX, Offlog); |
803 { size_t const ohSize = FSE_writeNCount(dstPtr, maxDstSize, offcodeNCount, OFFCODE_MAX, Offlog); |
804 if (FSE_isError(ohSize)) { |
804 if (FSE_isError(ohSize)) { |
805 eSize = ERROR(GENERIC); |
805 eSize = ohSize; |
806 DISPLAYLEVEL(1, "FSE_writeNCount error with offcodeNCount \n"); |
806 DISPLAYLEVEL(1, "FSE_writeNCount error with offcodeNCount \n"); |
807 goto _cleanup; |
807 goto _cleanup; |
808 } |
808 } |
809 dstPtr += ohSize; |
809 dstPtr += ohSize; |
810 maxDstSize -= ohSize; |
810 maxDstSize -= ohSize; |
811 eSize += ohSize; |
811 eSize += ohSize; |
812 } |
812 } |
813 |
813 |
814 { size_t const mhSize = FSE_writeNCount(dstPtr, maxDstSize, matchLengthNCount, MaxML, mlLog); |
814 { size_t const mhSize = FSE_writeNCount(dstPtr, maxDstSize, matchLengthNCount, MaxML, mlLog); |
815 if (FSE_isError(mhSize)) { |
815 if (FSE_isError(mhSize)) { |
816 eSize = ERROR(GENERIC); |
816 eSize = mhSize; |
817 DISPLAYLEVEL(1, "FSE_writeNCount error with matchLengthNCount \n"); |
817 DISPLAYLEVEL(1, "FSE_writeNCount error with matchLengthNCount \n"); |
818 goto _cleanup; |
818 goto _cleanup; |
819 } |
819 } |
820 dstPtr += mhSize; |
820 dstPtr += mhSize; |
821 maxDstSize -= mhSize; |
821 maxDstSize -= mhSize; |
822 eSize += mhSize; |
822 eSize += mhSize; |
823 } |
823 } |
824 |
824 |
825 { size_t const lhSize = FSE_writeNCount(dstPtr, maxDstSize, litLengthNCount, MaxLL, llLog); |
825 { size_t const lhSize = FSE_writeNCount(dstPtr, maxDstSize, litLengthNCount, MaxLL, llLog); |
826 if (FSE_isError(lhSize)) { |
826 if (FSE_isError(lhSize)) { |
827 eSize = ERROR(GENERIC); |
827 eSize = lhSize; |
828 DISPLAYLEVEL(1, "FSE_writeNCount error with litlengthNCount \n"); |
828 DISPLAYLEVEL(1, "FSE_writeNCount error with litlengthNCount \n"); |
829 goto _cleanup; |
829 goto _cleanup; |
830 } |
830 } |
831 dstPtr += lhSize; |
831 dstPtr += lhSize; |
832 maxDstSize -= lhSize; |
832 maxDstSize -= lhSize; |
833 eSize += lhSize; |
833 eSize += lhSize; |
834 } |
834 } |
835 |
835 |
836 if (maxDstSize<12) { |
836 if (maxDstSize<12) { |
837 eSize = ERROR(GENERIC); |
837 eSize = ERROR(dstSize_tooSmall); |
838 DISPLAYLEVEL(1, "not enough space to write RepOffsets \n"); |
838 DISPLAYLEVEL(1, "not enough space to write RepOffsets \n"); |
839 goto _cleanup; |
839 goto _cleanup; |
840 } |
840 } |
841 # if 0 |
841 # if 0 |
842 MEM_writeLE32(dstPtr+0, bestRepOffset[0].offset); |
842 MEM_writeLE32(dstPtr+0, bestRepOffset[0].offset); |