byucc.jhdl.base.list
Class TreeList

java.lang.Object
  extended bybyucc.jhdl.base.list.TreeList
All Implemented Interfaces:
List
Direct Known Subclasses:
NodeList

public class TreeList
extends java.lang.Object
implements List

This list structure is based on a modified binary tree design. Each object keeps track of its next sibling and its first child. This is useful for objects that are guaranteed to appear only once, on a single list. Insert, init, atEnd, next are all O(1), append and prev are not presently supported, and elementCount is O(n). To make a treelist of objects, the target class must implement TreeListable.

Author:
Eric Blake

Constructor Summary
TreeList()
           
 
Method Summary
protected  void append(TreeListable obj)
          Append not supported at present.
 boolean atEnd()
          Returns true when the current pointer is at the end of the list.
 boolean delete(TreeListable obj)
          If found, deletes the child from the list of children, then reinitializes list
 int elementCount()
          Returns the size of the list; i.e.
 java.util.Enumeration elements()
          Returns an enumeration for safe simultaneous traversal of this list
 boolean empty()
          Returns true if the list has no elements
protected  TreeListable getElt()
          Returns the object pointed to by the current pointer.
 void init()
          Initializes the list to start at the first child, for traversal.
 boolean inList(java.lang.Object obj)
          Returns true if the object is found in the list
 boolean inList(TreeListable obj)
          Returns true if the object is found in the list
protected  void insert(TreeListable obj)
          Inserts a child to the list
 void next()
          Advances the current pointer, for iterating through the list.
 void prev()
          Prev not supported at present.
 java.lang.String toString()
          For nice output; useful in debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeList

public TreeList()
Method Detail

insert

protected void insert(TreeListable obj)
Inserts a child to the list

Parameters:
obj - the child to insert

delete

public boolean delete(TreeListable obj)
If found, deletes the child from the list of children, then reinitializes list

Parameters:
obj - the child to delete
Returns:
true if the element was found and deleted

empty

public final boolean empty()
Returns true if the list has no elements

Returns:
true if empty

init

public final void init()
Initializes the list to start at the first child, for traversal.

Specified by:
init in interface List
Returns:
an Iterator for simultaneous traversal

atEnd

public final boolean atEnd()
Returns true when the current pointer is at the end of the list.

Specified by:
atEnd in interface List
Returns:
true if at the end of the list

next

public final void next()
Advances the current pointer, for iterating through the list.

Specified by:
next in interface List

prev

public final void prev()
Prev not supported at present.

Specified by:
prev in interface List

getElt

protected TreeListable getElt()
Returns the object pointed to by the current pointer.

Returns:
the current node.

elementCount

public final int elementCount()
Returns the size of the list; i.e. the number of children belonging to a node

Specified by:
elementCount in interface List
Returns:
number of elements in list

append

protected void append(TreeListable obj)
Append not supported at present.


inList

public final boolean inList(java.lang.Object obj)
Returns true if the object is found in the list

Specified by:
inList in interface List
Returns:
true if the object is in the list

inList

public final boolean inList(TreeListable obj)
Returns true if the object is found in the list

Returns:
true if the object is in the list

toString

public java.lang.String toString()
For nice output; useful in debugging.

Returns:
a String representing this list

elements

public java.util.Enumeration elements()
Returns an enumeration for safe simultaneous traversal of this list

Returns:
an enumerator for this list


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.