Function exr::compression::piz::huffman::build_encoding_table

source ·
fn build_encoding_table(frequencies: &mut [u64]) -> (usize, usize)
Expand description

Compute Huffman codes (based on frq input) and store them in frq:

  • code structure is : [63:lsb - 6:msb] | [5-0: bit length];
  • max code length is 58 bits;
  • codes outside the range [im-iM] have a null length (unused values);
  • original frequencies are destroyed;
  • encoding tables are used by hufEncode() and hufBuildDecTable();

NB: The following code “(*a == *b) && (a > b))” was added to ensure elements in the heap with the same value are sorted by index. This is to ensure, the STL make_heap()/pop_heap()/push_heap() methods produced a resultant sorted heap that is identical across OSes.