Class: Omnizip::Algorithms::BZip2::Huffman::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/bzip2/huffman.rb

Overview

Huffman tree node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, frequency) ⇒ Node

Initialize node

Parameters:

  • symbol (Integer, nil)

    Symbol (nil for internal nodes)

  • frequency (Integer)

    Frequency/weight



47
48
49
50
51
52
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 47

def initialize(symbol, frequency)
  @symbol = symbol
  @frequency = frequency
  @left = nil
  @right = nil
end

Instance Attribute Details

#frequencyObject

Returns the value of attribute frequency.



41
42
43
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 41

def frequency
  @frequency
end

#leftObject

Returns the value of attribute left.



41
42
43
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 41

def left
  @left
end

#rightObject

Returns the value of attribute right.



41
42
43
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 41

def right
  @right
end

#symbolObject

Returns the value of attribute symbol.



41
42
43
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 41

def symbol
  @symbol
end

Instance Method Details

#leaf?Boolean

Check if node is a leaf

Returns:

  • (Boolean)

    True if leaf node



57
58
59
# File 'lib/omnizip/algorithms/bzip2/huffman.rb', line 57

def leaf?
  @left.nil? && @right.nil?
end