code: static void allocateHuffmanCodeLengths(final int[] array, final int maximumLength) {
          switch (array.length) {
              case 2:
                  array[1] = 1;
                  // fall through
              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 */
          int nodesToRelocate = findNodesToRelocate(array, maximumLength);
  
          /* Pass 3 : Generate code lengths */
          if (array[0] % array.length >= nodesToRelocate) {
              allocateNodeLengths(array);
          } else {
              int insertDepth = maximumLength - (32 - Integer.numberOfLeadingZeros(nodesToRelocate - 1));
              allocateNodeLengthsWithRelocation(array, nodesToRelocate, insertDepth);
          }
      }
docs: 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))}