Package io.github.skenvy
Class Collatz.TreeGraphNode
- java.lang.Object
-
- io.github.skenvy.Collatz.TreeGraphNode
-
- Enclosing class:
- Collatz
public static final class Collatz.TreeGraphNode extends Object
Nodes that form a "tree graph", structured as a tree, with their own node's value, as well as references to either possible child node, where a node can only ever have two children, as there are only ever two reverse values. Also records any possible "terminal sequence state", whether that be that the "orbit distance" has been reached, as an "out of bounds" stop, which is the regularly expected terminal state. Other terminal states possible however include the cycle state and cycle length (end) states.
-
-
Constructor Summary
Constructors Constructor Description TreeGraphNode(BigInteger nodeValue, int maxOrbitDistance, BigInteger p, BigInteger a, BigInteger b)
Create an instance of TreeGraphNode which will yield its entire sub-tree of all child nodes.TreeGraphNode(BigInteger nodeValue, Collatz.SequenceState terminalSequenceState, Collatz.TreeGraphNode preNDivPNode, Collatz.TreeGraphNode preANplusBNode)
Create an instance of TreeGraphNode by directly passing it the values required to instantiate, intended to be used in testing by manually creating trees in reverse, by passing expected child nodes to their parents until the entire expected tree is created.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
The equality between TreeGraphNodes is determined exclusively by the node's value, independent of the child nodes or sequence states that would be relevant to the node's status relative to the tree.int
hashCode()
The hashCode of a TreeGraphNode is determined by the node's value, the child nodes and sequence state.boolean
subTreeEquals(Collatz.TreeGraphNode tgn)
A much stricter equality check than theequals(Object obj)
override.
-
-
-
Constructor Detail
-
TreeGraphNode
public TreeGraphNode(BigInteger nodeValue, int maxOrbitDistance, BigInteger p, BigInteger a, BigInteger b) throws Collatz.FailedSaneParameterCheck
Create an instance of TreeGraphNode which will yield its entire sub-tree of all child nodes.- Parameters:
nodeValue
- The value for which to find the tree graph node reversal.maxOrbitDistance
- The maximum distance/orbit/branch length to travel.p
- Modulus used to devide n, iff n is equivalent to (0 mod P).a
- Factor by which to multiply n.b
- Value to add to the scaled value of n.- Throws:
Collatz.FailedSaneParameterCheck
- if P or a are 0.
-
TreeGraphNode
public TreeGraphNode(BigInteger nodeValue, Collatz.SequenceState terminalSequenceState, Collatz.TreeGraphNode preNDivPNode, Collatz.TreeGraphNode preANplusBNode)
Create an instance of TreeGraphNode by directly passing it the values required to instantiate, intended to be used in testing by manually creating trees in reverse, by passing expected child nodes to their parents until the entire expected tree is created.- Parameters:
nodeValue
- The value expected of this node.terminalSequenceState
- The expected sequence state; null, MAX_STOP_OUT_OF_BOUNDS, CYCLE_INIT or CYCLE_LENGTH.preNDivPNode
- The expected "Pre N/P" child node.preANplusBNode
- The expected "Pre aN+b" child node.
-
-
Method Detail
-
equals
public boolean equals(Object obj)
The equality between TreeGraphNodes is determined exclusively by the node's value, independent of the child nodes or sequence states that would be relevant to the node's status relative to the tree.
-
hashCode
public int hashCode()
The hashCode of a TreeGraphNode is determined by the node's value, the child nodes and sequence state.
-
subTreeEquals
public boolean subTreeEquals(Collatz.TreeGraphNode tgn)
A much stricter equality check than theequals(Object obj)
override. This will only confirm an equality if the whole subtree of both nodes, including node values, sequence states, and child nodes, checked recursively, are equal.- Parameters:
tgn
- The TreeGraphNode with which to compare equality.- Returns:
true
, if the entire sub-trees are equal.
-
-