All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.tools.v2-0.BTree

java.lang.Object
   |
   +----com.roguewave.tools.v2-0.CollectionBase
           |
           +----com.roguewave.tools.v2-0.BTree

public class BTree
extends CollectionBase
implements Cloneable, Serializable
Class BTree (for Balanced Tree) represents a group of ordered elements; duplicates are not allowed. The elements are ordered according to a Comparator, which is supplied when constructing the tree.

This class has certain advantages over class BinaryTree. First, the tree is automatically balanced. (With BinaryTree, you must call the method balance() to balance the tree.) Nodes are never allowed to have less than a certain number of items (called the order). The default order is 50. Because many keys are held in a single node, class BTree tends to fragment memeory less and is well suited for collecting a large number of elements.

See Also:
BinaryTree, Comparator, NumericCompare, StringCompare

Variable Index

 o comp_
The Comparator object used to order elements of this BTree.
 o root_
The root node of this BTree

Constructor Index

 o BTree()
Creates an empty BTree with a null comparator.
 o BTree(Comparator)
Creates an empty tree.

Method Index

 o clear()
Removes all items from the collection.
 o clone()
Returns a clone of this BTree.
 o contains(Object)
Checks the tree for an element that compares equal to the given item.
 o elements()
Returns an Enumeration object, which can be used to visit each element of the collection in turn.
 o find(Object)
 o height()
Calculates the height of this tree by finding the length of the longest path from the root node to a leaf.
 o insert(Object)
Inserts an item into the tree.
 o occurrencesOf(Object)
Returns the number of elements in the tree that compare equal to the given item.
 o remove(Object)
Removes from the tree that element that compares equal to the given item.
 o removeAll(Object)
Removes from the tree all elements that compare equal to the given item.
 o setComparator(Comparator)
Set the Comparator.
 o subsetOf(BTree)
Returns true if self is a subset of the given BTree.
 o toString()
Coverts this tree to a string.

Variables

 o root_
 protected BTreeNode root_
The root node of this BTree

 o comp_
 protected Comparator comp_
The Comparator object used to order elements of this BTree.

Constructors

 o BTree
 public BTree()
Creates an empty BTree with a null comparator. The comparator must be set before adding any elements.

See Also:
setComparator
 o BTree
 public BTree(Comparator comp)
Creates an empty tree.

Parameters:
comp - The object used to order the elements

Methods

 o height
 public synchronized int height()
Calculates the height of this tree by finding the length of the longest path from the root node to a leaf. Note that an empty tree has height 0, while a tree with only a root with no children has height 1.

Returns:
The height of this tree
 o clear
 public synchronized void clear()
Removes all items from the collection.

Overrides:
clear in class CollectionBase
 o clone
 public synchronized Object clone()
Returns a clone of this BTree. Note that neither the Comparator object nor the elements of the tree themselves are cloned. The cloned tree will have the same node structure as the original tree.

Overrides:
clone in class Object
 o contains
 public boolean contains(Object item)
Checks the tree for an element that compares equal to the given item.

Returns:
true if such an element is found, false otherwise
Overrides:
contains in class CollectionBase
 o elements
 public synchronized Enumeration elements()
Returns an Enumeration object, which can be used to visit each element of the collection in turn.

Overrides:
elements in class CollectionBase
 o find
 public synchronized Object find(Object item)
Overrides:
find in class CollectionBase
 o insert
 public synchronized Object insert(Object item)
Inserts an item into the tree. The item will only be inserted if the tree does not already contain an element that compares equal to item.

Returns:
The new item if successful, otherwise return the existing element that compares equal to item
Overrides:
insert in class CollectionBase
 o occurrencesOf
 public int occurrencesOf(Object item)
Returns the number of elements in the tree that compare equal to the given item. Note that, because this collection does not admit duplicate entries, the only possible return values are 0 and 1.

Overrides:
occurrencesOf in class CollectionBase
 o remove
 public synchronized Object remove(Object item)
Removes from the tree that element that compares equal to the given item. If there is no such element the method does nothing.

Returns:
The element removed, or null if no such element
Overrides:
remove in class CollectionBase
 o removeAll
 public int removeAll(Object item)
Removes from the tree all elements that compare equal to the given item. Note that, since the collection does not admit duplicate entries, the maximum number of elements removed will be 1.

Returns:
The number of elements removed
Overrides:
removeAll in class CollectionBase
 o subsetOf
 public synchronized boolean subsetOf(BTree bt)
Returns true if self is a subset of the given BTree. Note that an empty tree is a subset of any other tree.

 o toString
 public synchronized String toString()
Coverts this tree to a string. The string will have the form
   CompClass:[e1, e2, e3, ..., eN]
 
where CompClass is the string value of the comparator and the elements of the collection are listed in sorted order.

Overrides:
toString in class Object
 o setComparator
 public boolean setComparator(Comparator comp)
Set the Comparator. The collection must be empty or this method will fail.

Returns:
true if the method is successfull, false otherwise.

All Packages  Class Hierarchy  This Package  Previous  Next  Index