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
- #empty? ⇒ Boolean
- #include?(key) ⇒ Boolean
-
#initialize(value) ⇒ Node
constructor
A new instance of Node.
- #keys ⇒ Object
- #leaf? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(value) ⇒ Node
Returns a new instance of Node.
145 146 147 148 |
# File 'lib/chess_openings/search_tree.rb', line 145 def initialize(value) @value = value @nodes = {} end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
143 144 145 |
# File 'lib/chess_openings/search_tree.rb', line 143 def nodes @nodes end |
#value ⇒ Object
Returns the value of attribute value.
143 144 145 |
# File 'lib/chess_openings/search_tree.rb', line 143 def value @value end |
Instance Method Details
#==(other) ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/chess_openings/search_tree.rb', line 170 def ==(other) return false if size != other.size || @value != other.value @nodes.keys.each do |key| return false unless other.keys.include?(key) return false if @nodes[key] != other.nodes[key] end true end |
#empty? ⇒ Boolean
150 151 152 |
# File 'lib/chess_openings/search_tree.rb', line 150 def empty? @value.nil? end |
#include?(key) ⇒ Boolean
166 167 168 |
# File 'lib/chess_openings/search_tree.rb', line 166 def include?(key) @nodes.keys.include?(key) end |
#keys ⇒ Object
162 163 164 |
# File 'lib/chess_openings/search_tree.rb', line 162 def keys @nodes.keys end |
#leaf? ⇒ Boolean
154 155 156 |
# File 'lib/chess_openings/search_tree.rb', line 154 def leaf? @nodes.empty? end |
#size ⇒ Object
158 159 160 |
# File 'lib/chess_openings/search_tree.rb', line 158 def size @nodes.size end |