org.jikesrvm.compilers.opt.util
Class Tree

java.lang.Object
  extended by org.jikesrvm.compilers.opt.util.Tree
Direct Known Subclasses:
CallSiteTree, DominatorTree

public class Tree
extends Object

This class is a generic tree. It uses TreeNode and some enumeration classes.


Field Summary
private  TreeNode root
          A tree is simply a pointer to the root
 
Constructor Summary
Tree()
          constructor where the root is not initially known
Tree(TreeNode node)
          constructor where the root is initially known
 
Method Summary
private  StringBuffer DFS(StringBuffer sb, TreeNode node, int depth)
          A preorder depth first traversal, printing node as visited
 Enumeration<TreeNode> elements()
          Provides an undefined enumeration over all elements in the tree
 Enumeration<TreeNode> getBottomUpEnumerator()
          Provides a bottom-up enumeration over all elements in the tree
 TreeNode getRoot()
          Gets the root of the tree
 Enumeration<TreeNode> getTopDownEnumerator()
          Provides a top-down enumeration over all elements in the tree
 boolean isEmpty()
          Is the tree empty?
 int numberOfNodes()
          Counts and returns the number of nodes
 void setRoot(TreeNode node)
          Sets the root of the tree to be the passed node.
 String toString()
          Prints the tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

root

private TreeNode root
A tree is simply a pointer to the root

Constructor Detail

Tree

public Tree()
constructor where the root is not initially known


Tree

public Tree(TreeNode node)
constructor where the root is initially known

Parameters:
node - Root of the tree.
Method Detail

isEmpty

public final boolean isEmpty()
Is the tree empty?

Returns:
whether the tree is empty

getRoot

public final TreeNode getRoot()
Gets the root of the tree

Returns:
the root of the tree

setRoot

public final void setRoot(TreeNode node)
Sets the root of the tree to be the passed node. WARNING: the tree should be empty when this occurs


elements

public final Enumeration<TreeNode> elements()
Provides an undefined enumeration over all elements in the tree

Returns:
enumeration

numberOfNodes

public final int numberOfNodes()
Counts and returns the number of nodes

Returns:
the number of nodes.

getBottomUpEnumerator

public final Enumeration<TreeNode> getBottomUpEnumerator()
Provides a bottom-up enumeration over all elements in the tree

Returns:
enumeration

getTopDownEnumerator

public final Enumeration<TreeNode> getTopDownEnumerator()
Provides a top-down enumeration over all elements in the tree

Returns:
enumeration

toString

public final String toString()
Prints the tree

Overrides:
toString in class Object
Returns:
the tree as a string

DFS

private StringBuffer DFS(StringBuffer sb,
                         TreeNode node,
                         int depth)
A preorder depth first traversal, printing node as visited

Parameters:
sb - the string buffer to insert the results
node - the node to process
depth - the current depth (root = 0) in the tree