class RhEntitlement::HuffmanNode

Attributes

left[RW]
parent[RW]
right[RW]
symbol[RW]
weight[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 60
def initialize(params = {})
  @weight = params[:weight] || 0
  @symbol = params[:symbol] || ''
  @left   = params[:left]   || nil
  @right  = params[:right]  || nil
  @parent = params[:parent] || nil
end

Public Instance Methods

internal?() click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 82
def internal?
  @symbol == ''
end
leaf?() click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 78
def leaf?
  @symbol != ''
end
root?() click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 86
def root?
  internal? and @parent.nil?
end
walk(&block) click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 68
def walk(&block)
  walk_node('', &block)
end
walk_node(code) { |self, code| ... } click to toggle source
# File lib/rh_entitlement/huffman_encoding.rb, line 72
def walk_node(code, &block)
  yield(self, code)
  @left.walk_node(code + '0', &block) unless @left.nil?
  @right.walk_node(code + '1', &block) unless @right.nil?
end