Class: MerkleTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/merkletree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, left, right) ⇒ Node

Returns a new instance of Node.



24
25
26
27
28
# File 'lib/merkletree.rb', line 24

def initialize( value, left, right )
   @value = value
   @left  = left
   @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



21
22
23
# File 'lib/merkletree.rb', line 21

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



22
23
24
# File 'lib/merkletree.rb', line 22

def right
  @right
end

#valueObject (readonly)

Returns the value of attribute value.



20
21
22
# File 'lib/merkletree.rb', line 20

def value
  @value
end

Instance Method Details

#do_dump(depth) ⇒ Object

dump (recursive_worker)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/merkletree.rb', line 35

def do_dump( depth )    ## dump (recursive_worker)
  depth.times { print ' ' }
  print "#{depth}:[#{value}] "
  if @left
    print '{'
    puts
    @left.do_dump( depth+1 )
    @right.do_dump( depth+1)  if @right    # note: make right node optional (might be nil/empty)
    depth.times { print ' ' }
    print '}'
  end
  puts
end

#dumpObject

for debugging / testing add pretty printing (dump tree)



33
# File 'lib/merkletree.rb', line 33

def dump() do_dump( 0 ); end