Sha256: b5b71f66a61d27c9a6056a941cc5a0b7ad6ca793d7b82823031bc890ba096526
Contents?: true
Size: 467 Bytes
Versions: 1
Compression:
Stored size: 467 Bytes
Contents
class Node attr_reader :weight def initialize(value, weight, left = nil, right = nil) @value = value @weight = weight @left = left @right = right @leaf = (@left == nil && @right == nil) end def traverse(code, hash) if @leaf hash[@value] = code else @left.traverse("#{code}1", hash) @right.traverse("#{code}0", hash) end end def <=>(other) @weight <=> other.weight end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
huffman_coding-0.0.1 | lib/huffman_coding/node.rb |