code: function zip_gen_codes(tree,	// the tree to decorate
    max_code) {	// largest code with non zero frequency
    var next_code = new Array(zip_MAX_BITS + 1); // next code value for each bit length
    var code = 0;		// running code value
    var bits;			// bit index
    var n;			// code index
  
    /* The distribution counts are first used to generate the code values
     * without bit reversal.
     */
    for (bits = 1; bits <= zip_MAX_BITS; bits++) {
      code = ((code + zip_bl_count[bits - 1]) << 1);
      next_code[bits] = code;
    }
  
    /* Check that the bit counts in bl_count are consistent. The last code
     * must be all ones.
     */
    //    Assert (code + encoder->bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
    //	    "inconsistent bit counts");
    //    Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  
    for (n = 0; n <= max_code; n++) {
      var len = tree[n].dl;
      if (len == 0) { continue; }
      // Now reverse the bits
      tree[n].fc = zip_bi_reverse(next_code[len]++, len);
  
      //      Tracec(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
      //	  n, (isgraph(n) ? n : ' '), len, tree[n].fc, next_code[len]-1));
    }
  }
docs: /* ==========================================================================
  Generate the codes for a given tree and bit counts (which need not be
  optimal).
  IN assertion: the array bl_count contains the bit length statistics for
  the given tree and the field len is set for all tree elements.
  OUT assertion: the field code is set for all tree elements of non
  zero code length.