Class: Resedit::Huffman::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/resedit/text/huffman.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject

Returns the value of attribute left.



7
8
9
# File 'lib/resedit/text/huffman.rb', line 7

def left
  @left
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/resedit/text/huffman.rb', line 7

def parent
  @parent
end

#rightObject

Returns the value of attribute right.



7
8
9
# File 'lib/resedit/text/huffman.rb', line 7

def right
  @right
end

#valueObject

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