| 2242 | // |
| 2243 | |
| 2244 | static void hufCanonicalCodeTable(long long hcode[HUF_ENCSIZE]) { |
| 2245 | long long n[59]; |
| 2246 | |
| 2247 | // |
| 2248 | // For each i from 0 through 58, count the |
| 2249 | // number of different codes of length i, and |
| 2250 | // store the count in n[i]. |
| 2251 | // |
| 2252 | |
| 2253 | for (int i = 0; i <= 58; ++i) n[i] = 0; |
| 2254 | |
| 2255 | for (int i = 0; i < HUF_ENCSIZE; ++i) n[hcode[i]] += 1; |
| 2256 | |
| 2257 | // |
| 2258 | // For each i from 58 through 1, compute the |
| 2259 | // numerically lowest code with length i, and |
| 2260 | // store that code in n[i]. |
| 2261 | // |
| 2262 | |
| 2263 | long long c = 0; |
| 2264 | |
| 2265 | for (int i = 58; i > 0; --i) { |
| 2266 | long long nc = ((c + n[i]) >> 1); |
| 2267 | n[i] = c; |
| 2268 | c = nc; |
| 2269 | } |
| 2270 | |
| 2271 | // |
| 2272 | // hcode[i] contains the length, l, of the |
| 2273 | // code for symbol i. Assign the next available |
| 2274 | // code of length l to the symbol and store both |
| 2275 | // l and the code in hcode[i]. |
| 2276 | // |
| 2277 | |
| 2278 | for (int i = 0; i < HUF_ENCSIZE; ++i) { |
| 2279 | int l = static_cast<int>(hcode[i]); |
| 2280 | |
| 2281 | if (l > 0) hcode[i] = l | (n[l]++ << 6); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | // |
| 2286 | // Compute Huffman codes (based on frq input) and store them in frq: |
no outgoing calls
no test coverage detected