Class: AhoC::Node
- Inherits:
-
Object
- Object
- AhoC::Node
- Defined in:
- lib/ahocorasick.rb
Overview
Aho-Corasick Node Class
Description
Class for creating and accessing nodes that are added to an Aho-Corasick Trie.
Instance Attribute Summary collapse
-
#failure ⇒ Object
failure: gets and sets the node to go to when no goto transition exists for an item.
-
#output ⇒ Object
output: gets and sets the output at the node.
Instance Method Summary collapse
-
#add(item) ⇒ Object
Creates a node in the hash table for “item”.
-
#get ⇒ Object
Return the hash that contains all nodes pointed to by this node.
-
#goto(item) ⇒ Object
Returns the node pointed to by item.
-
#initialize ⇒ Node
constructor
Creates an empty hash table to store goto transitions for this node.
-
#set(item, node) ⇒ Object
Assigns a node to the key “item” in the hash table.
Constructor Details
#initialize ⇒ Node
Creates an empty hash table to store goto transitions for this node.
264 265 266 |
# File 'lib/ahocorasick.rb', line 264 def initialize @hash = {} end |
Instance Attribute Details
#failure ⇒ Object
failure: gets and sets the node to go to when no goto transition exists for an item.
259 260 261 |
# File 'lib/ahocorasick.rb', line 259 def failure @failure end |
#output ⇒ Object
output: gets and sets the output at the node.
261 262 263 |
# File 'lib/ahocorasick.rb', line 261 def output @output end |
Instance Method Details
#add(item) ⇒ Object
Creates a node in the hash table for “item”. This represents a goto transition in the Aho-Corasick automaton for the item.
270 271 272 |
# File 'lib/ahocorasick.rb', line 270 def add(item) @hash[item] = Node.new end |
#get ⇒ Object
Return the hash that contains all nodes pointed to by this node.
275 276 277 |
# File 'lib/ahocorasick.rb', line 275 def get @hash end |
#goto(item) ⇒ Object
Returns the node pointed to by item. If no node exists the default value is returned.
281 282 283 |
# File 'lib/ahocorasick.rb', line 281 def goto(item) @hash[item] ? @hash[item] : @hash.default end |
#set(item, node) ⇒ Object
Assigns a node to the key “item” in the hash table.
286 287 288 |
# File 'lib/ahocorasick.rb', line 286 def set(item, node) @hash[item] = node end |