Class: Matchers::ACAutomaton::Node
- Inherits:
-
Object
- Object
- Matchers::ACAutomaton::Node
- Defined in:
- lib/matcher.rb
Instance Attribute Summary collapse
-
#failure ⇒ Object
Returns the value of attribute failure.
-
#goto ⇒ Object
readonly
Manages the goto as a character -> node ID mapping.
-
#id ⇒ Object
readonly
Uniquely (in an automaton) assigned ID of the Node.
-
#out ⇒ Object
Stores out of AC, that is the index of the patterns.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #g(char) ⇒ Object
-
#initialize(id: 0, goto: {}, failure: 0, out: []) ⇒ Node
constructor
A new instance of Node.
- #root? ⇒ Boolean
- #to_s ⇒ Object
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
#failure ⇒ Object
Returns the value of attribute failure.
108 109 110 |
# File 'lib/matcher.rb', line 108 def failure @failure end |
#goto ⇒ Object (readonly)
Manages the goto as a character -> node ID mapping.
105 106 107 |
# File 'lib/matcher.rb', line 105 def goto @goto end |
#id ⇒ Object (readonly)
Uniquely (in an automaton) assigned ID of the Node.
107 108 109 |
# File 'lib/matcher.rb', line 107 def id @id end |
#out ⇒ Object
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
119 120 121 |
# File 'lib/matcher.rb', line 119 def root? @id.zero? end |
#to_s ⇒ Object
132 133 134 |
# File 'lib/matcher.rb', line 132 def to_s "id: #{@id}, goto: #{@goto}, failure: #{@failure}, out: #{@out}" end |