Class: Resedit::Huffman::Node
- Inherits:
-
Object
- Object
- Resedit::Huffman::Node
- Defined in:
- lib/resedit/text/huffman.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#right ⇒ Object
Returns the value of attribute right.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #addLeft(value = nil) ⇒ Object
- #addNode(isLeft, value = nil) ⇒ Object
- #addRight(value = nil) ⇒ Object
- #getLeafs(leftS, rightS, path = '') ⇒ Object
-
#initialize(value = nil, parent = nil) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(value = nil, parent = nil) ⇒ Node
Returns a new instance of Node.
9 10 11 |
# File 'lib/resedit/text/huffman.rb', line 9 def initialize(value=nil, parent=nil) @value=value end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
7 8 9 |
# File 'lib/resedit/text/huffman.rb', line 7 def left @left end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/resedit/text/huffman.rb', line 7 def parent @parent end |
#right ⇒ Object
Returns the value of attribute right.
7 8 9 |
# File 'lib/resedit/text/huffman.rb', line 7 def right @right end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/resedit/text/huffman.rb', line 7 def value @value end |
Instance Method Details
#addLeft(value = nil) ⇒ Object
23 24 25 |
# File 'lib/resedit/text/huffman.rb', line 23 def addLeft(value=nil) addNode(true, value) end |
#addNode(isLeft, value = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/resedit/text/huffman.rb', line 13 def addNode(isLeft,value=nil) n=Node.new(value) if isLeft @left=n else @right=n end return n end |
#addRight(value = nil) ⇒ Object
27 28 29 |
# File 'lib/resedit/text/huffman.rb', line 27 def addRight(value=nil) addNode(false, value) end |
#getLeafs(leftS, rightS, path = '') ⇒ Object
31 32 33 34 35 36 |
# File 'lib/resedit/text/huffman.rb', line 31 def getLeafs(leftS,rightS,path='') return {path=>@value} if @value l=@left.getLeafs(leftS, rightS, path+leftS) r=@right.getLeafs(leftS, rightS, path+rightS) return l.merge(r) end |