comparison contrib/python-zstandard/zstd/common/entropy_common.c @ 30822:b54a2984cdd4

zstd: vendor python-zstandard 0.6.0 Commit 63c68d6f5fc8de4afd9bde81b13b537beb4e47e8 from https://github.com/indygreg/python-zstandard is imported without modifications (other than removing unwanted files). This includes minor performance and feature improvements. It also changes the vendored zstd library from 1.1.1 to 1.1.2. # no-check-commit
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 14 Jan 2017 19:41:43 -0800
parents 2e484bdea8c4
children b1fb341d8a61
comparison
equal deleted inserted replaced
30821:7005c03f7387 30822:b54a2984cdd4
157 157
158 158
159 /*! HUF_readStats() : 159 /*! HUF_readStats() :
160 Read compact Huffman tree, saved by HUF_writeCTable(). 160 Read compact Huffman tree, saved by HUF_writeCTable().
161 `huffWeight` is destination buffer. 161 `huffWeight` is destination buffer.
162 `rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
162 @return : size read from `src` , or an error Code . 163 @return : size read from `src` , or an error Code .
163 Note : Needed by HUF_readCTable() and HUF_readDTableX?() . 164 Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
164 */ 165 */
165 size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats, 166 size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
166 U32* nbSymbolsPtr, U32* tableLogPtr, 167 U32* nbSymbolsPtr, U32* tableLogPtr,
185 for (n=0; n<oSize; n+=2) { 186 for (n=0; n<oSize; n+=2) {
186 huffWeight[n] = ip[n/2] >> 4; 187 huffWeight[n] = ip[n/2] >> 4;
187 huffWeight[n+1] = ip[n/2] & 15; 188 huffWeight[n+1] = ip[n/2] & 15;
188 } } } 189 } } }
189 else { /* header compressed with FSE (normal case) */ 190 else { /* header compressed with FSE (normal case) */
191 FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
190 if (iSize+1 > srcSize) return ERROR(srcSize_wrong); 192 if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
191 oSize = FSE_decompress(huffWeight, hwSize-1, ip+1, iSize); /* max (hwSize-1) values decoded, as last one is implied */ 193 oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
192 if (FSE_isError(oSize)) return oSize; 194 if (FSE_isError(oSize)) return oSize;
193 } 195 }
194 196
195 /* collect weight stats */ 197 /* collect weight stats */
196 memset(rankStats, 0, (HUF_TABLELOG_ABSOLUTEMAX + 1) * sizeof(U32)); 198 memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
197 weightTotal = 0; 199 weightTotal = 0;
198 { U32 n; for (n=0; n<oSize; n++) { 200 { U32 n; for (n=0; n<oSize; n++) {
199 if (huffWeight[n] >= HUF_TABLELOG_ABSOLUTEMAX) return ERROR(corruption_detected); 201 if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
200 rankStats[huffWeight[n]]++; 202 rankStats[huffWeight[n]]++;
201 weightTotal += (1 << huffWeight[n]) >> 1; 203 weightTotal += (1 << huffWeight[n]) >> 1;
202 } } 204 } }
203 if (weightTotal == 0) return ERROR(corruption_detected); 205 if (weightTotal == 0) return ERROR(corruption_detected);
204 206
205 /* get last non-null symbol weight (implied, total must be 2^n) */ 207 /* get last non-null symbol weight (implied, total must be 2^n) */
206 { U32 const tableLog = BIT_highbit32(weightTotal) + 1; 208 { U32 const tableLog = BIT_highbit32(weightTotal) + 1;
207 if (tableLog > HUF_TABLELOG_ABSOLUTEMAX) return ERROR(corruption_detected); 209 if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
208 *tableLogPtr = tableLog; 210 *tableLogPtr = tableLog;
209 /* determine last weight */ 211 /* determine last weight */
210 { U32 const total = 1 << tableLog; 212 { U32 const total = 1 << tableLog;
211 U32 const rest = total - weightTotal; 213 U32 const rest = total - weightTotal;
212 U32 const verif = 1 << BIT_highbit32(rest); 214 U32 const verif = 1 << BIT_highbit32(rest);