org.jikesrvm.compilers.opt.util
Class TreeTopDownEnumerator

java.lang.Object
  extended by org.jikesrvm.compilers.opt.util.TreeTopDownEnumerator
All Implemented Interfaces:
Enumeration<TreeNode>

final class TreeTopDownEnumerator
extends Object
implements Enumeration<TreeNode>

This class provides enumeration of elements of a tree in a town-down manner It guarantees that all children of a node will only be visited after the parent. This is not necessarily the same as a top-down level walk.


Field Summary
private  ListIterator<TreeNode> iterator
          an iterator of the above list
private  ArrayList<TreeNode> list
          List of nodes in preorder
 
Constructor Summary
TreeTopDownEnumerator(TreeNode root)
          constructor: it creates the list of nodes
 
Method Summary
private  void DFS(TreeNode node)
          A preorder depth first traversal, adding nodes to the list
 boolean hasMoreElements()
          any elements left?
 TreeNode nextElement()
          returns the next element in the list iterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

private final ArrayList<TreeNode> list
List of nodes in preorder


iterator

private final ListIterator<TreeNode> iterator
an iterator of the above list

Constructor Detail

TreeTopDownEnumerator

TreeTopDownEnumerator(TreeNode root)
constructor: it creates the list of nodes

Parameters:
root - Root of the tree to traverse
Method Detail

hasMoreElements

public boolean hasMoreElements()
any elements left?

Specified by:
hasMoreElements in interface Enumeration<TreeNode>
Returns:
whether there are any elements left

nextElement

public TreeNode nextElement()
returns the next element in the list iterator

Specified by:
nextElement in interface Enumeration<TreeNode>
Returns:
the next element in the list iterator or null

DFS

private void DFS(TreeNode node)
A preorder depth first traversal, adding nodes to the list

Parameters:
node -