Class: Node

Inherits:
Object
  • Object
show all
Includes:
NodeExtensions
Defined in:
lib/support/node.rb,
lib/visitor/numbering_visitor.rb

Constant Summary collapse

CURRENT_ENDING_OFFSET =

Leaf nodes use this due to Rule 1: once a leaf, always a leaf

-1
UNSPECIFIED_OFFSET =

Root uses this, it has no incoming edge, yet as a Node has incoming edge offset properties

-2
LEAF_DEPTH =

Leaf nodes get special depth, since they vary as characters get added

-3

Instance Attribute Summary collapse

Attributes included from NodeExtensions

#binaryTreeHeight, #dfsNumber, #numberNodesInSubtree, #runBits, #runHead, #runTail

Instance Method Summary collapse

Constructor Details

#initialize(nodeId, suffixOffset = UNSPECIFIED_OFFSET) ⇒ Node

Returns a new instance of Node.



15
16
17
18
19
20
21
22
23
24
# File 'lib/support/node.rb', line 15

def initialize(nodeId, suffixOffset = UNSPECIFIED_OFFSET)
  @nodeId = nodeId
  @incomingEdgeStartOffset = UNSPECIFIED_OFFSET
  @incomingEdgeEndOffset = UNSPECIFIED_OFFSET
  @suffixOffset = suffixOffset

  @parent = nil
  @suffixLink = nil
  @children = nil
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



12
13
14
# File 'lib/support/node.rb', line 12

def children
  @children
end

#incomingEdgeEndOffsetObject

Returns the value of attribute incomingEdgeEndOffset.



11
12
13
# File 'lib/support/node.rb', line 11

def incomingEdgeEndOffset
  @incomingEdgeEndOffset
end

#incomingEdgeStartOffsetObject

Returns the value of attribute incomingEdgeStartOffset.



11
12
13
# File 'lib/support/node.rb', line 11

def incomingEdgeStartOffset
  @incomingEdgeStartOffset
end

#nodeIdObject (readonly)

Returns the value of attribute nodeId.



13
14
15
# File 'lib/support/node.rb', line 13

def nodeId
  @nodeId
end

#parentObject

Returns the value of attribute parent.



12
13
14
# File 'lib/support/node.rb', line 12

def parent
  @parent
end

Returns the value of attribute suffixLink.



12
13
14
# File 'lib/support/node.rb', line 12

def suffixLink
  @suffixLink
end

#suffixOffsetObject

Returns the value of attribute suffixOffset.



11
12
13
# File 'lib/support/node.rb', line 11

def suffixOffset
  @suffixOffset
end

Instance Method Details

#createAccessor(name) ⇒ Object

some algorithms require additional accessors, allow these to be created dynamically



45
46
47
# File 'lib/support/node.rb', line 45

def createAccessor(name)
  self.class.send(:attr_accessor, name)
end

#each_suffixObject

suffix offset enumerator (not sure this belongs here)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/support/node.rb', line 52

def each_suffix
  if (self.isLeaf) then
    yield suffixOffset
  else
    children.keys.sort.each do |key|
      children[key].each_suffix do |suffixOffset|
        yield suffixOffset
      end
    end
  end
end

#incomingEdgeLengthObject



38
39
40
# File 'lib/support/node.rb', line 38

def incomingEdgeLength
  return @incomingEdgeEndOffset - @incomingEdgeStartOffset + 1
end

#isInternalObject



34
35
36
# File 'lib/support/node.rb', line 34

def isInternal
  return !isLeaf && !isRoot
end

#isLeafObject



30
31
32
# File 'lib/support/node.rb', line 30

def isLeaf
  return @incomingEdgeEndOffset == CURRENT_ENDING_OFFSET
end

#isRootObject



26
27
28
# File 'lib/support/node.rb', line 26

def isRoot
  return @parent == nil
end