docs: function build_tree(clens, cmap, MAX) {
  	var maxlen = 1, w = 0, i = 0, j = 0, ccode = 0, L = clens.length;
  
  	var bl_count  = use_typed_arrays ? new Uint16Array(32) : zero_fill_array(32);
  	for(i = 0; i < 32; ++i) bl_count[i] = 0;
  
  	for(i = L; i < MAX; ++i) clens[i] = 0;
  	L = clens.length;
  
  	var ctree = use_typed_arrays ? new Uint16Array(L) : zero_fill_array(L); // []
  
  	/* build code tree */
  	for(i = 0; i < L; ++i) {
  		bl_count[(w = clens[i])]++;
  		if(maxlen < w) maxlen = w;
  		ctree[i] = 0;
  	}
  	bl_count[0] = 0;
  	for(i = 1; i <= maxlen; ++i) bl_count[i+16] = (ccode = (ccode + bl_count[i-1])<<1);
  	for(i = 0; i < L; ++i) {
  		ccode = clens[i];
  		if(ccode != 0) ctree[i] = bl_count[ccode+16]++;
  	}
  
  	/* cmap[maxlen + 4 bits] = (off&15) + (lit<<4) reverse mapping */
  	var cleni = 0;
  	for(i = 0; i < L; ++i) {
  		cleni = clens[i];
  		if(cleni != 0) {
  			ccode = bit_swap_n(ctree[i], maxlen)>>(maxlen-cleni);
  			for(j = (1<<(maxlen + 4 - cleni)) - 1; j>=0; --j)
  				cmap[ccode|(j<<cleni)] = (cleni&15) | (i<<4);
  		}
  	}
  	return maxlen;
  }