lib/gziprb/huffman.rb
# Creates a Tree from a mapping of literal to codes. Does not check for uniqueness of either
# codes or literals.
Creates a Tree from a mapping of literal to codes. Does not check for uniqueness of either
codes or literals.
Creates a Tree from a mapping of literal to codes . Does not check for uniqueness of either codes or literals .
def insert_code(tree, code, lit)
        return lit if code.empty?
        bit = code.slice!(0).to_i
        if bit.zero?
          tree.l = insert_code(tree.l || Tree.empty, code, lit)
        else
          tree.r = insert_code(tree.r || Tree.empty, code, lit)
        end
        tree
      end
def insert_code ( tree , code , lit ) return lit if code . empty? bit = code . slice! ( 0 ) . to_i if bit . zero? tree . l = insert_code ( tree . l || Tree . empty , code , lit ) else tree . r = insert_code ( tree . r || Tree . empty , code , lit ) end tree end
Creates a Tree from a mapping of literal to codes.
Creates a Tree from a mapping of literal to codes .
tree
code
lit