A Leaf has, in addition to the attributes of a Node, a symbol. The width and height are 1, and the offset is 0.5.
The String associated with a weight in a leaf node.
Assign a Numeric weight and a symbol (String) to a leaf.
The width and height are 1, and the offset is 0.5.
# File huffman_tree.rb, line 107 def initialize(weight, symbol) super(weight, 1, 1, 0.5) @symbol = symbol end
Generate JavaScript to draw leaf.
Draw a labeled link to the node. Write the symbol at the end of the link.
# File huffman_tree.rb, line 125 def draw(bits='') "#{draw_link(bits)} draw_leaf(#{@offset}, #{symbol.dump.dump});" end
Number of characters in 'dump' representation of :symbol.
# File huffman_tree.rb, line 115 def margin(deepest, depth=0) depth == deepest ? @symbol.dump.length : 0 end