| 2366 | }; |
| 2367 | |
| 2368 | static bool hufBuildEncTable( |
| 2369 | long long *frq, // io: input frequencies [HUF_ENCSIZE], output table |
| 2370 | int *im, // o: min frq index |
| 2371 | int *iM) // o: max frq index |
| 2372 | { |
| 2373 | // |
| 2374 | // This function assumes that when it is called, array frq |
| 2375 | // indicates the frequency of all possible symbols in the data |
| 2376 | // that are to be Huffman-encoded. (frq[i] contains the number |
| 2377 | // of occurrences of symbol i in the data.) |
| 2378 | // |
| 2379 | // The loop below does three things: |
| 2380 | // |
| 2381 | // 1) Finds the minimum and maximum indices that point |
| 2382 | // to non-zero entries in frq: |
| 2383 | // |
| 2384 | // frq[im] != 0, and frq[i] == 0 for all i < im |
| 2385 | // frq[iM] != 0, and frq[i] == 0 for all i > iM |
| 2386 | // |
| 2387 | // 2) Fills array fHeap with pointers to all non-zero |
| 2388 | // entries in frq. |
| 2389 | // |
| 2390 | // 3) Initializes array hlink such that hlink[i] == i |
| 2391 | // for all array entries. |
| 2392 | // |
| 2393 | |
| 2394 | std::vector<int> hlink(HUF_ENCSIZE); |
| 2395 | std::vector<long long *> fHeap(HUF_ENCSIZE); |
| 2396 | |
| 2397 | *im = 0; |
| 2398 | |
| 2399 | while (!frq[*im]) (*im)++; |
| 2400 | |
| 2401 | int nf = 0; |
| 2402 | |
| 2403 | for (int i = *im; i < HUF_ENCSIZE; i++) { |
| 2404 | hlink[i] = i; |
| 2405 | |
| 2406 | if (frq[i]) { |
| 2407 | fHeap[nf] = &frq[i]; |
| 2408 | nf++; |
| 2409 | *iM = i; |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | // |
| 2414 | // Add a pseudo-symbol, with a frequency count of 1, to frq; |
| 2415 | // adjust the fHeap and hlink array accordingly. Function |
| 2416 | // hufEncode() uses the pseudo-symbol for run-length encoding. |
| 2417 | // |
| 2418 | |
| 2419 | (*iM)++; |
| 2420 | frq[*iM] = 1; |
| 2421 | fHeap[nf] = &frq[*iM]; |
| 2422 | nf++; |
| 2423 | |
| 2424 | // |
| 2425 | // Build an array, scode, such that scode[i] contains the number |
no test coverage detected