lib/HuffmanAllocator.js
function(array, maximumLength) {
    switch (array.length) {
    case 2:
      array[1] = 1;
    case 1:
      array[0] = 1;
      return;
    }

    /* Pass 1 : Set extended parent pointers */
    setExtendedParentPointers (array);

    /* Pass 2 : Find number of nodes to relocate in order to achieve
     *          maximum code length */
    var nodesToRelocate = findNodesToRelocate (array, maximumLength);

    /* Pass 3 : Generate code lengths */
    if ((array[0] % array.length) >= nodesToRelocate) {
      allocateNodeLengths (array);
    } else {
      var insertDepth = maximumLength - (Util.fls(nodesToRelocate - 1));
      allocateNodeLengthsWithRelocation (array, nodesToRelocate, insertDepth);
    }
  }
function(array, maximumLength) {
    switch (array.length) {
    case 2:
      array[1] = 1;
    case 1:
      array[0] = 1;
      return;
    }

    /* Pass 1 : Set extended parent pointers */
    setExtendedParentPointers (array);

    /* Pass 2 : Find number of nodes to relocate in order to achieve
     *          maximum code length */
    var nodesToRelocate = findNodesToRelocate (array, maximumLength);

    /* Pass 3 : Generate code lengths */
    if ((array[0] % array.length) >= nodesToRelocate) {
      allocateNodeLengths (array);
    } else {
      var insertDepth = maximumLength - (Util.fls(nodesToRelocate - 1));
      allocateNodeLengthsWithRelocation (array, nodesToRelocate, insertDepth);
    }
  }
function ( array , maximumLength ) { switch ( array . length ) { case 2 : array [ 1 ] = 1 ; case 1 : array [ 0 ] = 1 ; return ; } /* Pass 1 : Set extended parent pointers */ setExtendedParentPointers ( array ) ; /* Pass 2 : Find number of nodes to relocate in order to achieve
     *          maximum code length */ var nodesToRelocate = findNodesToRelocate ( array , maximumLength ) ; /* Pass 3 : Generate code lengths */ if ( ( array [ 0 ] % array . length ) >= nodesToRelocate ) { allocateNodeLengths ( array ) ; } else { var insertDepth = maximumLength - ( Util . fls ( nodesToRelocate - 1 ) ) ; allocateNodeLengthsWithRelocation ( array , nodesToRelocate , insertDepth ) ; } }
Allocates Canonical Huffman code lengths in place based on a sorted
frequency array
@param array On input, a sorted array of symbol frequencies; On output,
an array of Canonical Huffman code lengths
@param maximumLength The maximum code length. Must be at least
{@code ceil(log2(array.length))}
 public
Allocates Canonical Huffman code lengths in place based on a sorted frequency array