lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
# Compute the optimal bit lengths for a tree and update the total bit length
# for the current block.
# IN assertion: the fields freq and dad are set, heap[heap_max] and
#    above are the tree nodes sorted by increasing frequency.
# OUT assertions: the field len is set to the optimal bit length, the
#     array bl_count contains the frequencies for each bit length.
#     The length opt_len is updated; static_len is also updated if stree is
#     not null.
Compute the optimal bit lengths for a tree and update the total bit length
for the current block.
IN assertion: the fields freq and dad are set, heap[heap_max] and
above are the tree nodes sorted by increasing frequency.
OUT assertions: the field len is set to the optimal bit length, the
array bl_count contains the frequencies for each bit length.
The length opt_len is updated; static_len is also updated if stree is
not null.
Compute the optimal bit lengths for a tree and update the total bit length for the current block . IN assertion : the fields freq and dad are set heap [ heap_max ] and above are the tree nodes sorted by increasing frequency . OUT assertions : the field len is set to the optimal bit length the array bl_count contains the frequencies for each bit length . The length opt_len is updated ; static_len is also updated if stree is not null .
def gen_bitlen(s,desc)
    tree = desc.dyn_tree
    max_code = desc.max_code
    stree = desc.stat_desc.static_tree
    extra = desc.stat_desc.extra_bits
    base = desc.stat_desc.extra_base
    max_length = desc.stat_desc.max_length
    overflow = 0
    for bits in 0 .. MAX_BITS
      s.bl_count[bits] = 0
    end
    tree[s.heap[s.heap_max]].dl = 0
    for h in s.heap_max+1 ... HEAP_SIZE
      n = s.heap[h]
      bits = tree[tree[n].dl].dl + 1
      if (bits > max_length)
        bits = max_length
        overflow+=1
      end
      tree[n].dl = bits
      next if (n > max_code)
      s.bl_count[bits]+=1
      xbits = 0
      xbits = extra[n-base] if (n >= base)
      f = tree[n].fc
      s.opt_len += (f) * (bits + xbits)
      if stree
        s.static_len += (f) * (stree[n].dl + xbits)
      end
    end
    return if overflow == 0
    loop do
      bits = max_length-1
      bits -= 1 while s.bl_count[bits] == 0
      s.bl_count[bits] -= 1
      s.bl_count[bits+1] += 2
      s.bl_count[max_length] -= 1
      overflow -= 2
      break if (overflow <= 0)
    end
    h = HEAP_SIZE
    max_length.downto(1) do |nbits|
      n = s.bl_count[nbits]
      while n != 0
        h -= 1
        m = s.heap[h]
        next if (m > max_code)
        if (tree[m].dl != nbits)
          s.opt_len += (nbits - tree[m].dl) * tree[m].fc
          tree[m].dl = nbits
        end
        n-=1
      end
    end
  end
def gen_bitlen ( s , desc ) tree = desc . dyn_tree max_code = desc . max_code stree = desc . stat_desc . static_tree extra = desc . stat_desc . extra_bits base = desc . stat_desc . extra_base max_length = desc . stat_desc . max_length overflow = 0 for bits in 0 .. MAX_BITS s . bl_count [ bits ] = 0 end tree [ s . heap [ s . heap_max ] ] . dl = 0 for h in s . heap_max + 1 ... HEAP_SIZE n = s . heap [ h ] bits = tree [ tree [ n ] . dl ] . dl + 1 if ( bits > max_length ) bits = max_length overflow += 1 end tree [ n ] . dl = bits next if ( n > max_code ) s . bl_count [ bits ] += 1 xbits = 0 xbits = extra [ n - base ] if ( n >= base ) f = tree [ n ] . fc s . opt_len += ( f ) * ( bits + xbits ) if stree s . static_len += ( f ) * ( stree [ n ] . dl + xbits ) end end return if overflow == 0 loop do bits = max_length - 1 bits -= 1 while s . bl_count [ bits ] == 0 s . bl_count [ bits ] -= 1 s . bl_count [ bits + 1 ] += 2 s . bl_count [ max_length ] -= 1 overflow -= 2 break if ( overflow <= 0 ) end h = HEAP_SIZE max_length . downto ( 1 ) do | nbits | n = s . bl_count [ nbits ] while n != 0 h -= 1 m = s . heap [ h ] next if ( m > max_code ) if ( tree [ m ] . dl != nbits ) s . opt_len += ( nbits - tree [ m ] . dl ) * tree [ m ] . fc tree [ m ] . dl = nbits end n -= 1 end end end
Compute the optimal bit lengths for a tree and update the total bit length
for the current block.
Compute the optimal bit lengths for a tree and update the total bit length for the current block .
s
<not_specific>
desc
<not_specific>