class Collatz::TreeGraph

Contains the results of computing the Tree Graph via tree_graph(~). Contains the root node of a tree of TreeGraphNode’s.

Attributes

root[R]

The root node of the tree of TreeGraphNode’s.

Public Class Methods

new(node_value, max_orbit_distance, p, a, b, create_raw: false, root: nil) click to toggle source

Create a new TreeGraph with the root node defined by the inputs.

@raise FailedSaneParameterCheck If p or a are 0.

@param Integer node_value: The value for which to find the tree graph node reversal.

@param Integer max_orbit_distance: The maximum distance/orbit/branch length to travel.

@param Integer p: Modulus used to devide n, iff n is equivalent to (0 mod p).

@param Integer a: Factor by which to multiply n.

@param Integer b: Value to add to the scaled value of n.

@param Boolean create_raw: Used to instruct the initialiser method to take 1:1 inputs, used in testing.

@param TreeGraphNode root: A node that will be set to the root of this tree

@return [TreeGraph] A tree graph, with a computed root node.

# 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

Public Instance Methods

==(other) click to toggle source

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.

@param TreeGraph

@return Boolean true, if both are TreeGraph, with the entire root’s sub-trees being equal.

# 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