Class: SearchTree::Node
- Inherits:
-
Object
- Object
- SearchTree::Node
- Defined in:
- lib/chess_openings/search_tree.rb
Overview
Class that represents a node of a tree data structure
Instance Attribute Summary collapse
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(value) ⇒ Node
constructor
A new instance of Node.
- #is_empty? ⇒ Boolean
- #is_leaf? ⇒ Boolean
- #keys ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(value) ⇒ Node
Returns a new instance of Node
153 154 155 156 |
# File 'lib/chess_openings/search_tree.rb', line 153 def initialize(value) @value = value @nodes = {} end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes
151 152 153 |
# File 'lib/chess_openings/search_tree.rb', line 151 def nodes @nodes end |
#value ⇒ Object
Returns the value of attribute value
151 152 153 |
# File 'lib/chess_openings/search_tree.rb', line 151 def value @value end |
Instance Method Details
#==(other) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/chess_openings/search_tree.rb', line 178 def ==(other) return false if self.size != other.size || @value != other.value @nodes.keys.each do |key| return false unless other.keys.include?(key) end @nodes.keys.each do |key| return false if @nodes[key] != other.nodes[key] end true end |
#include?(key) ⇒ Boolean
174 175 176 |
# File 'lib/chess_openings/search_tree.rb', line 174 def include?(key) @nodes.keys.include?(key) end |
#is_empty? ⇒ Boolean
158 159 160 |
# File 'lib/chess_openings/search_tree.rb', line 158 def is_empty? @value.nil? end |
#is_leaf? ⇒ Boolean
162 163 164 |
# File 'lib/chess_openings/search_tree.rb', line 162 def is_leaf? @nodes.empty? end |
#keys ⇒ Object
170 171 172 |
# File 'lib/chess_openings/search_tree.rb', line 170 def keys @nodes.keys end |
#size ⇒ Object
166 167 168 |
# File 'lib/chess_openings/search_tree.rb', line 166 def size @nodes.size end |