Class: Collatz::TreeGraph
- Inherits:
-
Object
- Object
- Collatz::TreeGraph
- Defined in:
- lib/collatz/tree_graph.rb
Overview
Contains the results of computing the Tree Graph via tree_graph(~). Contains the root node of a tree of TreeGraphNode’s.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
The root node of the tree of TreeGraphNode’s.
Instance Method Summary collapse
-
#==(other) ⇒ Object
The equality between TreeGraph’s is determined by the equality check on subtrees.
-
#initialize(node_value, max_orbit_distance, p, a, b, create_raw: false, root: nil) ⇒ TreeGraph
constructor
Create a new TreeGraph with the root node defined by the inputs.
Constructor Details
#initialize(node_value, max_orbit_distance, p, a, b, create_raw: false, root: nil) ⇒ TreeGraph
Create a new TreeGraph with the root node defined by the inputs.
134 135 136 137 138 139 140 |
# File 'lib/collatz/tree_graph.rb', line 134 def initialize(node_value, max_orbit_distance, p, a, b, create_raw: false, root: nil) if create_raw && !root.nil? @root = root else @root = TreeGraphNode.new(node_value, max_orbit_distance, p, a, b) end end |
Instance Attribute Details
#root ⇒ Object (readonly)
The root node of the tree of TreeGraphNode’s.
113 114 115 |
# File 'lib/collatz/tree_graph.rb', line 113 def root @root end |
Instance Method Details
#==(other) ⇒ Object
The equality between TreeGraph’s is determined by the equality check on subtrees. A subtree check will be done on both TreeGraph’s root nodes.
148 149 150 151 152 153 154 |
# File 'lib/collatz/tree_graph.rb', line 148 def ==(other) # Generic checks return false if other.nil? return false unless other.is_a?(self.class) # Actual check self.root.sub_tree_equals(other.root) end |