| 2168 | // |
| 2169 | |
| 2170 | static void hufCanonicalCodeTable(long long hcode[HUF_ENCSIZE]) { |
| 2171 | long long n[59]; |
| 2172 | |
| 2173 | // |
| 2174 | // For each i from 0 through 58, count the |
| 2175 | // number of different codes of length i, and |
| 2176 | // store the count in n[i]. |
| 2177 | // |
| 2178 | |
| 2179 | for (int i = 0; i <= 58; ++i) n[i] = 0; |
| 2180 | |
| 2181 | for (int i = 0; i < HUF_ENCSIZE; ++i) n[hcode[i]] += 1; |
| 2182 | |
| 2183 | // |
| 2184 | // For each i from 58 through 1, compute the |
| 2185 | // numerically lowest code with length i, and |
| 2186 | // store that code in n[i]. |
| 2187 | // |
| 2188 | |
| 2189 | long long c = 0; |
| 2190 | |
| 2191 | for (int i = 58; i > 0; --i) { |
| 2192 | long long nc = ((c + n[i]) >> 1); |
| 2193 | n[i] = c; |
| 2194 | c = nc; |
| 2195 | } |
| 2196 | |
| 2197 | // |
| 2198 | // hcode[i] contains the length, l, of the |
| 2199 | // code for symbol i. Assign the next available |
| 2200 | // code of length l to the symbol and store both |
| 2201 | // l and the code in hcode[i]. |
| 2202 | // |
| 2203 | |
| 2204 | for (int i = 0; i < HUF_ENCSIZE; ++i) { |
| 2205 | int l = static_cast<int>(hcode[i]); |
| 2206 | |
| 2207 | if (l > 0) hcode[i] = l | (n[l]++ << 6); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | // |
| 2212 | // Compute Huffman codes (based on frq input) and store them in frq: |
no outgoing calls
no test coverage detected