class Node
Attributes
weight[R]
Public Class Methods
new(value, weight, left = nil, right = nil)
click to toggle source
# File lib/huffman_coding/node.rb, line 6 def initialize(value, weight, left = nil, right = nil) @value = value @weight = weight @left = left @right = right @leaf = (@left == nil && @right == nil) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/huffman_coding/node.rb, line 23 def <=>(other) @weight <=> other.weight end
traverse(code, hash)
click to toggle source
# File lib/huffman_coding/node.rb, line 14 def traverse(code, hash) if @leaf hash[@value] = code else @left.traverse("#{code}1", hash) @right.traverse("#{code}0", hash) end end