public class TwoThreeTree
extends java.lang.Object
Constructor and Description |
---|
TwoThreeTree(java.lang.String keyType)
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
protected TwoThreeNode |
CreateNode()
Creates new empty node.
|
protected TwoThreeNode |
CreateNode(java.lang.String ascii,
int dec,
java.lang.String hex,
int oct)
Creates a new node with data.
|
protected void |
ExpandTree(TwoThreeNode currentNode,
TwoThreeNode newSubTree)
Called if the insertion location is full.
|
protected TwoThreeNode |
FindInsertLocation(TwoThreeNode currentNode,
TwoThreeNode newNode)
Finds proper location for insertion of new node.
|
NodeData |
FindValue(TwoThreeNode node,
NodeData searchKey)
Traverses tree to find node with matching key.
|
int |
GetTreeHeight(TwoThreeNode node,
int level)
Gets height of tree.
|
void |
Insert(java.lang.String ascii,
int dec,
java.lang.String hex,
int oct)
Inserts new node at appropriate location.
|
protected void |
InsertNode(TwoThreeNode root,
TwoThreeNode newLeaf)
Handles more complicated cases of inserting into the tree.
|
protected void |
PrintKeys(TwoThreeNode node)
Prints all key values for node.
|
TwoThreeNode |
RootNode()
Getter for tree's root node.
|
void |
RootNode(TwoThreeNode rootNode)
Setter for tree's root node.
|
protected void |
SetChildKeys(TwoThreeNode currentNode)
Appropriately sets keys for node.
|
protected void |
SetOrdering(TwoThreeNode parentNode)
Ensures that child nodes are in proper ordering.
|
boolean |
SetOrderingOfParent(TwoThreeNode currentNode)
Compares parent's smallest value with the largest value of parent's previous sibling (if exists).
|
void |
TraverseAndPrintLeaves(TwoThreeNode root)
Traverses tree and prints all root nodes.
|
void |
TraverseAndPrintLevels(TwoThreeNode root)
Traverses tree and prints values for all nodes, in breadth-first fasion.
|
public TwoThreeTree(java.lang.String keyType)
keyType
- Defines key type for tree nodes.public TwoThreeNode RootNode()
public void RootNode(TwoThreeNode rootNode)
rootNode
- Root node of tree.protected TwoThreeNode CreateNode()
protected TwoThreeNode CreateNode(java.lang.String ascii, int dec, java.lang.String hex, int oct)
ascii
- dec
- hex
- oct
- public void Insert(java.lang.String ascii, int dec, java.lang.String hex, int oct)
ascii
- dec
- hex
- oct
- public NodeData FindValue(TwoThreeNode node, NodeData searchKey)
node
- Current node in tree to search.searchKey
- Keys to compare against.public int GetTreeHeight(TwoThreeNode node, int level)
node
- Root node.level
- Current level (should pass 0 to start).public void TraverseAndPrintLevels(TwoThreeNode root)
root
- Root node of tree.protected void PrintKeys(TwoThreeNode node)
node
- Node to print keys of.public void TraverseAndPrintLeaves(TwoThreeNode root)
root
- Root node.protected void InsertNode(TwoThreeNode root, TwoThreeNode newLeaf)
root
- "Ideal" location of tree to insert into. Note: If this location is full, obviously it cannot insert
and has to manipulate tree accordingly.newLeaf
- New leaf to insert into.protected TwoThreeNode FindInsertLocation(TwoThreeNode currentNode, TwoThreeNode newNode)
currentNode
- Current location to check.newNode
- Node to locate spot for.protected void ExpandTree(TwoThreeNode currentNode, TwoThreeNode newSubTree)
currentNode
- Current location within tree.newSubTree
- New section to add onto tree.protected void SetOrdering(TwoThreeNode parentNode)
parentNode
- Node to sort children of.public boolean SetOrderingOfParent(TwoThreeNode currentNode)
currentNode
- Node to compare.protected void SetChildKeys(TwoThreeNode currentNode)
currentNode
- Current node to set keys for.