lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
# Construct one Huffman tree and assigns the code bit strings and lengths.
# Update the total bit length for the current block.
# IN assertion: the field freq is set for all tree elements.
# OUT assertions: the fields len and code are set to the optimal bit length
#     and corresponding code. The length opt_len is updated; static_len is
#     also updated if stree is not null. The field max_code is set.
Construct one Huffman tree and assigns the code bit strings and lengths.
Update the total bit length for the current block.
IN assertion: the field freq is set for all tree elements.
OUT assertions: the fields len and code are set to the optimal bit length
and corresponding code. The length opt_len is updated; static_len is
also updated if stree is not null. The field max_code is set.
Construct one Huffman tree and assigns the code bit strings and lengths . Update the total bit length for the current block . IN assertion : the field freq is set for all tree elements . OUT assertions : the fields len and code are set to the optimal bit length and corresponding code . The length opt_len is updated ; static_len is also updated if stree is not null . The field max_code is set .
def build_tree(s,desc)
    tree = desc.dyn_tree
    stree = desc.stat_desc.static_tree
    elems = desc.stat_desc.elems
    max_code = -1
    s.heap_len = 0
    s.heap_max = HEAP_SIZE
    for n in 0 ... elems
      if tree[n].fc != 0
        max_code = n
        s.heap_len+=1
        s.heap[s.heap_len] = n
        s.depth[n] = 0
      else
        tree[n].dl = 0
      end
    end
    while (s.heap_len < 2)
      s.heap_len+=1
      if (max_code < 2)
        max_code+=1
        s.heap[s.heap_len] = max_code
        node = max_code
      else
        s.heap[s.heap_len] = 0
        node = 0
      end
      tree[node].fc = 1
      s.depth[node] = 0
      s.opt_len-=1
      if stree
        s.static_len -= stree[node].dl
      end
    end
    desc.max_code = max_code
    (s.heap_len / 2).downto(1) do |nheap|
      pqdownheap(s, tree, nheap)
    end
    node = elems
    loop do
      n = s.heap[SMALLEST]
      s.heap[SMALLEST] = s.heap[s.heap_len]
      s.heap_len-=1
      pqdownheap(s, tree, SMALLEST)
      m = s.heap[SMALLEST]
      s.heap_max-=1
      s.heap[s.heap_max] = n
      s.heap_max-=1
      s.heap[s.heap_max] = m
      tree[node].fc = tree[n].fc + tree[m].fc
      if (s.depth[n] >= s.depth[m])
        s.depth[node] = s.depth[n] + 1
      else
        s.depth[node] = s.depth[m] + 1
      end
      tree[m].dl = node
      tree[n].dl = node
      s.heap[SMALLEST] = node
      node+=1
      pqdownheap(s, tree, SMALLEST)
      break if (s.heap_len < 2)
    end
    s.heap_max-=1
    s.heap[s.heap_max] = s.heap[SMALLEST]
    gen_bitlen(s, desc)
    gen_codes(tree, max_code, s.bl_count)
  end
def build_tree ( s , desc ) tree = desc . dyn_tree stree = desc . stat_desc . static_tree elems = desc . stat_desc . elems max_code = - 1 s . heap_len = 0 s . heap_max = HEAP_SIZE for n in 0 ... elems if tree [ n ] . fc != 0 max_code = n s . heap_len += 1 s . heap [ s . heap_len ] = n s . depth [ n ] = 0 else tree [ n ] . dl = 0 end end while ( s . heap_len < 2 ) s . heap_len += 1 if ( max_code < 2 ) max_code += 1 s . heap [ s . heap_len ] = max_code node = max_code else s . heap [ s . heap_len ] = 0 node = 0 end tree [ node ] . fc = 1 s . depth [ node ] = 0 s . opt_len -= 1 if stree s . static_len -= stree [ node ] . dl end end desc . max_code = max_code ( s . heap_len / 2 ) . downto ( 1 ) do | nheap | pqdownheap ( s , tree , nheap ) end node = elems loop do n = s . heap [ SMALLEST ] s . heap [ SMALLEST ] = s . heap [ s . heap_len ] s . heap_len -= 1 pqdownheap ( s , tree , SMALLEST ) m = s . heap [ SMALLEST ] s . heap_max -= 1 s . heap [ s . heap_max ] = n s . heap_max -= 1 s . heap [ s . heap_max ] = m tree [ node ] . fc = tree [ n ] . fc + tree [ m ] . fc if ( s . depth [ n ] >= s . depth [ m ] ) s . depth [ node ] = s . depth [ n ] + 1 else s . depth [ node ] = s . depth [ m ] + 1 end tree [ m ] . dl = node tree [ n ] . dl = node s . heap [ SMALLEST ] = node node += 1 pqdownheap ( s , tree , SMALLEST ) break if ( s . heap_len < 2 ) end s . heap_max -= 1 s . heap [ s . heap_max ] = s . heap [ SMALLEST ] gen_bitlen ( s , desc ) gen_codes ( tree , max_code , s . bl_count ) end
Construct one Huffman tree and assigns the code bit strings and lengths.
Construct one Huffman tree and assigns the code bit strings and lengths .
s
<not_specific>
desc
<not_specific>