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
-
comp_
- The Comparator object used to order elements of this BTree.
-
root_
- The root node of this BTree
-
BTree()
- Creates an empty BTree with a null comparator.
-
BTree(Comparator)
- Creates an empty tree.
-
clear()
- Removes all items from the collection.
-
clone()
- Returns a clone of this BTree.
-
contains(Object)
- Checks the tree for an element that compares equal to
the given item.
-
elements()
- Returns an Enumeration object, which can be used to visit
each element of the collection in turn.
-
find(Object)
-
-
height()
- Calculates the height of this tree by finding
the length of the longest path from the root node to a leaf.
-
insert(Object)
- Inserts an item into the tree.
-
occurrencesOf(Object)
- Returns the number of elements in the tree that compare
equal to the given item.
-
remove(Object)
- Removes from the tree that element that compares
equal to the given item.
-
removeAll(Object)
- Removes from the tree all elements that compare equal
to the given item.
-
setComparator(Comparator)
- Set the Comparator.
-
subsetOf(BTree)
- Returns true if self is a subset of the given BTree.
-
toString()
- Coverts this tree to a string.
root_
protected BTreeNode root_
- The root node of this BTree
comp_
protected Comparator comp_
- The Comparator object used to order elements of this BTree.
BTree
public BTree()
- Creates an empty BTree with a null comparator.
The comparator must be set before adding any elements.
- See Also:
- setComparator
BTree
public BTree(Comparator comp)
- Creates an empty tree.
- Parameters:
- comp - The object used to order the elements
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
clear
public synchronized void clear()
- Removes all items from the collection.
- Overrides:
- clear in class CollectionBase
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
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
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
find
public synchronized Object find(Object item)
- Overrides:
- find in class CollectionBase
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
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
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
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
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.
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
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