Class: RunDefiningVisitor

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

Overview

set the height of the complete binary tree node that each node maps to

Instance Method Summary collapse

Instance Method Details

#postVisit(node) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/visitor/numbering_visitor.rb', line 157

def postVisit(node)
  # the child with a greatest binaryTreeHeight larger than the current node's binaryTreeHeight
  # is the runTail, the current node is the runHead (which we need to set in runTail)
  if (node.children != nil) then
    maxBinaryTreeHeight = node.binaryTreeHeight
    maxBinaryTreeHeightNode = nil
    node.children.values.each do |child|
      if (child.runTail.binaryTreeHeight > maxBinaryTreeHeight) then
        maxBinaryTreeHeight = child.runTail.binaryTreeHeight
        maxBinaryTreeHeightNode = child
      end
    end
    if (maxBinaryTreeHeightNode != nil) then
      node.runTail = maxBinaryTreeHeightNode.runTail

      # runHead is ONLY valid in the runTail node,
      # the alternative is to traverse from runTail to node whenever runHead changes
      # (or to do this only on final change)
      node.runTail.runHead = node
    end
  end
end

#preVisit(node) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/visitor/numbering_visitor.rb', line 148

def preVisit(node)
  # every node gets the runTail set correctly
  # runHead is ONLY valid in the runTail node
  node.runHead = node.runTail = node
  parentDfsNumber = 0
  parentDfsNumber = node.parent.dfsNumber if (node.parent != nil)
  return true
end