Class: Matchers::ACAutomaton::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: 0, goto: {}, failure: 0, out: []) ⇒ Node

Returns a new instance of Node.



112
113
114
115
116
117
# File 'lib/matcher.rb', line 112

def initialize(id: 0, goto: {}, failure: 0, out: [])
  @id = id
  @goto = goto
  @failure = failure
  @out = out
end

Instance Attribute Details

#failureObject

Returns the value of attribute failure.



108
109
110
# File 'lib/matcher.rb', line 108

def failure
  @failure
end

#gotoObject (readonly)

Manages the goto as a character -> node ID mapping.



105
106
107
# File 'lib/matcher.rb', line 105

def goto
  @goto
end

#idObject (readonly)

Uniquely (in an automaton) assigned ID of the Node.



107
108
109
# File 'lib/matcher.rb', line 107

def id
  @id
end

#outObject

Stores out of AC, that is the index of the patterns.



110
111
112
# File 'lib/matcher.rb', line 110

def out
  @out
end

Instance Method Details

#==(other) ⇒ Object



136
137
138
# File 'lib/matcher.rb', line 136

def ==(other)
  @id == other.id && @goto == other.goto && @failure == other.failure && @out == other.out
end

#g(char) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/matcher.rb', line 123

def g(char)
  if (next_node = @goto[char])
    return next_node
  end
  return 0 if root?

  nil
end

#root?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/matcher.rb', line 119

def root?
  @id.zero?
end

#to_sObject



132
133
134
# File 'lib/matcher.rb', line 132

def to_s
  "id: #{@id}, goto: #{@goto}, failure: #{@failure}, out: #{@out}"
end