| 2296 | }; |
| 2297 | |
| 2298 | static bool hufBuildEncTable( |
| 2299 | long long *frq, // io: input frequencies [HUF_ENCSIZE], output table |
| 2300 | int *im, // o: min frq index |
| 2301 | int *iM) // o: max frq index |
| 2302 | { |
| 2303 | // |
| 2304 | // This function assumes that when it is called, array frq |
| 2305 | // indicates the frequency of all possible symbols in the data |
| 2306 | // that are to be Huffman-encoded. (frq[i] contains the number |
| 2307 | // of occurrences of symbol i in the data.) |
| 2308 | // |
| 2309 | // The loop below does three things: |
| 2310 | // |
| 2311 | // 1) Finds the minimum and maximum indices that point |
| 2312 | // to non-zero entries in frq: |
| 2313 | // |
| 2314 | // frq[im] != 0, and frq[i] == 0 for all i < im |
| 2315 | // frq[iM] != 0, and frq[i] == 0 for all i > iM |
| 2316 | // |
| 2317 | // 2) Fills array fHeap with pointers to all non-zero |
| 2318 | // entries in frq. |
| 2319 | // |
| 2320 | // 3) Initializes array hlink such that hlink[i] == i |
| 2321 | // for all array entries. |
| 2322 | // |
| 2323 | |
| 2324 | std::vector<int> hlink(HUF_ENCSIZE); |
| 2325 | std::vector<long long *> fHeap(HUF_ENCSIZE); |
| 2326 | |
| 2327 | *im = 0; |
| 2328 | |
| 2329 | while (!frq[*im]) (*im)++; |
| 2330 | |
| 2331 | int nf = 0; |
| 2332 | |
| 2333 | for (int i = *im; i < HUF_ENCSIZE; i++) { |
| 2334 | hlink[i] = i; |
| 2335 | |
| 2336 | if (frq[i]) { |
| 2337 | fHeap[nf] = &frq[i]; |
| 2338 | nf++; |
| 2339 | *iM = i; |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | // |
| 2344 | // Add a pseudo-symbol, with a frequency count of 1, to frq; |
| 2345 | // adjust the fHeap and hlink array accordingly. Function |
| 2346 | // hufEncode() uses the pseudo-symbol for run-length encoding. |
| 2347 | // |
| 2348 | |
| 2349 | (*iM)++; |
| 2350 | frq[*iM] = 1; |
| 2351 | fHeap[nf] = &frq[*iM]; |
| 2352 | nf++; |
| 2353 | |
| 2354 | // |
| 2355 | // Build an array, scode, such that scode[i] contains the number |
no test coverage detected