Class: ACT::Vertex
- Inherits:
-
Object
- Object
- ACT::Vertex
- Defined in:
- lib/act/vertex.rb
Overview
Trie vertex class
Instance Attribute Summary collapse
-
#char ⇒ Object
Letter representing this vertex.
-
#children ⇒ Object
readonly
Array of children ACT::Vertex references, ACT::Vertex.
-
#end_indexes ⇒ Object
Array of indexes of word in dictionary Empty if it is intermediate ACT::Vertex in chain.
-
#parent ⇒ Object
readonly
Reference to the parent ACT::Vertex.
Instance Method Summary collapse
-
#add_child(char, end_index) ⇒ Object
Initializes new ACT::Vertex and adds it to the parent attribute.
-
#children_chars ⇒ Object
Returns array of characters from array of children ACT::Vertex.
-
#get_child(char) ⇒ Object
Returns child ACT::Vertex by letter, from children attribute.
-
#initialize(parent = nil) ⇒ Vertex
constructor
Initializes new vertex *
parentis parent ACT::Vertex Example: >> ACT::Vertex.new(@root_vertex) >> ACT::Vertex.new(@root_vertex) Optional arguments: parent: (ACT::Vertex).
Constructor Details
#initialize(parent = nil) ⇒ Vertex
Initializes new vertex
-
parentis parent ACT::Vertex
Example:
>> ACT::Vertex.new(@root_vertex)
>> ACT::Vertex.new(@root_vertex)
Optional arguments:
parent: (ACT::Vertex)
28 29 30 31 32 33 |
# File 'lib/act/vertex.rb', line 28 def initialize(parent = nil) @char = nil @parent = parent @children = [] @end_indexes = [] end |
Instance Attribute Details
#char ⇒ Object
Letter representing this vertex
18 19 20 |
# File 'lib/act/vertex.rb', line 18 def char @char end |
#children ⇒ Object (readonly)
Array of children ACT::Vertex references, ACT::Vertex
11 12 13 |
# File 'lib/act/vertex.rb', line 11 def children @children end |
#end_indexes ⇒ Object
Array of indexes of word in dictionary Empty if it is intermediate ACT::Vertex in chain
15 16 17 |
# File 'lib/act/vertex.rb', line 15 def end_indexes @end_indexes end |
#parent ⇒ Object (readonly)
Reference to the parent ACT::Vertex
8 9 10 |
# File 'lib/act/vertex.rb', line 8 def parent @parent end |
Instance Method Details
#add_child(char, end_index) ⇒ Object
Initializes new ACT::Vertex and adds it to the parent attribute
37 38 39 40 41 42 43 44 45 |
# File 'lib/act/vertex.rb', line 37 def add_child(char, end_index) child = get_child(char) if child child.end_indexes << end_index unless end_index.nil? child else init_subchild(char, end_index) end end |
#children_chars ⇒ Object
Returns array of characters from array of children ACT::Vertex
55 56 57 |
# File 'lib/act/vertex.rb', line 55 def children_chars @children.map(&:char) end |
#get_child(char) ⇒ Object
Returns child ACT::Vertex by letter, from children attribute
49 50 51 |
# File 'lib/act/vertex.rb', line 49 def get_child(char) @children.find { |c| c.char == char } end |