Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/prefix_tree/node.rb
Constant Summary collapse
- @@nodes =
[]
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#is_end_point ⇒ Object
readonly
Returns the value of attribute is_end_point.
-
#number_size ⇒ Object
readonly
Returns the value of attribute number_size.
-
#strings_indexs ⇒ Object
readonly
Returns the value of attribute strings_indexs.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #add_strings_indexs(index) ⇒ Object
- #become_end_point ⇒ Object
- #create_child(char) ⇒ Object
- #decrement_size ⇒ Object
- #delete_element(value) ⇒ Object
- #delete_node ⇒ Object
- #delete_strings_indexs ⇒ Object
- #find(char) ⇒ Object
- #include?(char) ⇒ Boolean
- #increment_size ⇒ Object
-
#initialize(value = 'root') ⇒ Node
constructor
A new instance of Node.
- #not_end_point ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value = 'root') ⇒ Node
Returns a new instance of Node.
14 15 16 17 18 19 20 21 |
# File 'lib/prefix_tree/node.rb', line 14 def initialize(value = 'root') @value = value @children ||= [] @strings_indexs = [] @number_size = 0 @@nodes << self @is_end_point = false end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/prefix_tree/node.rb', line 6 def children @children end |
#is_end_point ⇒ Object (readonly)
Returns the value of attribute is_end_point.
6 7 8 |
# File 'lib/prefix_tree/node.rb', line 6 def is_end_point @is_end_point end |
#number_size ⇒ Object (readonly)
Returns the value of attribute number_size.
6 7 8 |
# File 'lib/prefix_tree/node.rb', line 6 def number_size @number_size end |
#strings_indexs ⇒ Object (readonly)
Returns the value of attribute strings_indexs.
6 7 8 |
# File 'lib/prefix_tree/node.rb', line 6 def strings_indexs @strings_indexs end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/prefix_tree/node.rb', line 6 def value @value end |
Class Method Details
.nodes ⇒ Object
10 11 12 |
# File 'lib/prefix_tree/node.rb', line 10 def self.nodes @@nodes end |
Instance Method Details
#add_strings_indexs(index) ⇒ Object
61 62 63 |
# File 'lib/prefix_tree/node.rb', line 61 def add_strings_indexs(index) @strings_indexs << index end |
#become_end_point ⇒ Object
45 46 47 |
# File 'lib/prefix_tree/node.rb', line 45 def become_end_point @is_end_point = true end |
#create_child(char) ⇒ Object
23 24 25 26 |
# File 'lib/prefix_tree/node.rb', line 23 def create_child(char) @children << child = Node.new(char) child end |
#decrement_size ⇒ Object
57 58 59 |
# File 'lib/prefix_tree/node.rb', line 57 def decrement_size @number_size -= 1 end |
#delete_element(value) ⇒ Object
71 72 73 |
# File 'lib/prefix_tree/node.rb', line 71 def delete_element(value) @strings_indexs.delete_if { |element| element.eql? value } end |
#delete_node ⇒ Object
28 29 30 |
# File 'lib/prefix_tree/node.rb', line 28 def delete_node @children.delete_if { |node| node.number_size.zero? } end |
#delete_strings_indexs ⇒ Object
65 66 67 68 69 |
# File 'lib/prefix_tree/node.rb', line 65 def delete_strings_indexs @children.each do |node| erase_indexs(node) end end |
#find(char) ⇒ Object
40 41 42 43 |
# File 'lib/prefix_tree/node.rb', line 40 def find(char) @children.each { |node| return node if node.value == char } false end |
#include?(char) ⇒ Boolean
36 37 38 |
# File 'lib/prefix_tree/node.rb', line 36 def include?(char) @children.any? { |node| node.value == char } end |
#increment_size ⇒ Object
53 54 55 |
# File 'lib/prefix_tree/node.rb', line 53 def increment_size @number_size += 1 end |
#not_end_point ⇒ Object
49 50 51 |
# File 'lib/prefix_tree/node.rb', line 49 def not_end_point @is_end_point = false end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/prefix_tree/node.rb', line 32 def to_s @value end |