|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tangosol.util.Base
com.tangosol.util.Tree
public class Tree
A red/black tree is a combination of a 2-3-4 B-tree and binary search tree. The tree's balance is maintained on insertions and deletions only. On the average, less than one rotation occurs per insertion/deletion. Searching the tree uses the simple binary search algorithm, which is very efficient since the tree is kept in a balanced state. The manner in which a red- black tree is balanced ensures that the longest branch of the tree is no longer than twice the length of the shortest branch of the tree. In tests with a Java implementation of a red/black tree, a hash table out-performed the tree on insertions and deletions by a factor of 2:1. The benefit of a binary tree, however, is that the values are maintained in order and therefor are enumerated in order.
Nested Class Summary | |
---|---|
protected static class |
Tree.Crawler
A red/black tree node iterator. |
protected static class |
Tree.Node
A red/black tree node. |
Field Summary | |
---|---|
protected Tree.Node |
head
The first node of the tree (or NIL if the tree is empty). |
protected static Tree.Node |
NIL
NIL is the sentinal Node that is used instead of null, simplifying the implementation of the red/black tree. |
protected int |
size
The number of nodes in the tree. |
Constructor Summary | |
---|---|
Tree()
Default constructor. |
Method Summary | |
---|---|
void |
add(Comparable key)
Add the passed key to the tree. |
boolean |
addAll(Tree that)
Adds all of the nodes in the specified Tree to this Tree if they are not already present. |
void |
clear()
Remove all nodes from the tree. |
Object |
clone()
Make a shallow copy of the tree and its nodes. |
boolean |
contains(Comparable key)
Determine if the passed key is in the tree. |
Enumeration |
elements()
Create an enumerator for the tree's values. |
boolean |
equals(Object obj)
Test for tree equality. |
protected Tree.Node |
find(Comparable key)
Find the specified key and return its node. |
Object |
get(Comparable key)
Find the specified key and return its value. |
int |
getSize()
Determine the size of the tree. |
protected Tree.Crawler |
getUnsynchronizedNodeEnumerator()
Get an enumerator of the nodes in the tree. |
protected Tree.Crawler |
getUnsynchronizedNodeEnumerator(Comparable key)
Get an enumerator of the nodes in the tree. |
boolean |
isEmpty()
Test for empty tree. |
Enumeration |
keys()
Create an in-order enumerator for the tree's keys. |
void |
print()
In-order printing of the contents of the tree. |
void |
put(Comparable key,
Object value)
Add the passed key to the tree and associate the passed value with the key. |
void |
putAll(Tree that)
Puts all of the nodes in the specified Tree to this Tree (including the ones that are already present). |
Object |
remove(Comparable key)
Remove the specified key from the tree, returning its associated value. |
boolean |
removeAll(Tree that)
Removes from this Tree all of its nodes that are contained in the specified Tree. |
boolean |
retainAll(Tree that)
Retains only the nodes in this Tree that are contained in the specified Tree. |
String |
toString()
Provide a string representation of the tree. |
Field Detail |
---|
protected static final Tree.Node NIL
protected Tree.Node head
protected int size
Constructor Detail |
---|
public Tree()
Method Detail |
---|
public void add(Comparable key)
key
- the key to add to the treepublic void put(Comparable key, Object value)
key
- the key to add to the treevalue
- the object to associate with the keypublic Object get(Comparable key)
key
- the key to look for in the tree
public boolean contains(Comparable key)
key
- the key to look for in the tree
public Object remove(Comparable key)
key
- the key to look for in the tree
public void clear()
public int getSize()
public boolean isEmpty()
public Enumeration keys()
public Enumeration elements()
public boolean addAll(Tree that)
Collection.addAll(Collection)
public void putAll(Tree that)
public boolean retainAll(Tree that)
Collection.retainAll(Collection)
public boolean removeAll(Tree that)
Collection.removeAll(Collection)
public String toString()
public boolean equals(Object obj)
public Object clone()
public void print()
protected Tree.Crawler getUnsynchronizedNodeEnumerator()
protected Tree.Crawler getUnsynchronizedNodeEnumerator(Comparable key)
protected Tree.Node find(Comparable key)
key
- the key to look for in the tree
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |