|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet
common.IndexedTreeSet
public class IndexedTreeSet
An implementation of the IndexedSet interface that keeps elements in sorted order. The order can be the natural ordering of the elements (if they implement the Comparable interface), or it can be specified by passing a Comparator object to the constructor.
This implementation uses a red-black tree, as described in Chapter 13 of Cormen, Leiserson, Rivest and Stein, "Introduction to Algorithms", 2nd ed. Each node in the tree also stores the size of the subtree rooted at it; this allows us to find the element at any given index in the ordering in O(lg n) time.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface common.IndexedSet |
|---|
IndexedSet.EmptyIndexedSet |
| Field Summary |
|---|
| Fields inherited from interface common.IndexedSet |
|---|
EMPTY_INDEXED_SET |
| Constructor Summary | |
|---|---|
IndexedTreeSet()
Creates an empty IndexedTreeSet that uses the natural ordering on its elements. |
|
IndexedTreeSet(java.util.Collection c)
Creates an IndexedTreeSet that contains the same elements as the given collection and uses the natural ordering on the elements. |
|
IndexedTreeSet(java.util.Comparator comparator)
Creates an empty IndexedTreeSet that uses the given comparator. |
|
IndexedTreeSet(java.util.SortedSet s)
Creates an IndexedTreeSet that contains the same elements as the given SortedSet and uses the same comparator. |
|
| Method Summary | |
|---|---|
boolean |
add(java.lang.Object o)
|
void |
clear()
|
java.lang.Object |
clone()
|
java.util.Comparator |
comparator()
|
boolean |
contains(java.lang.Object o)
|
java.lang.Object |
first()
|
java.lang.Object |
get(int index)
Returns the object with the specified index in this IndexedSet. |
java.util.SortedSet |
headSet(java.lang.Object toElement)
|
int |
indexOf(java.lang.Object o)
Returns the index of the given object in this IndexedSet, or -1 if this IndexedSet does not contain the given object. |
java.util.Iterator |
iterator()
|
java.lang.Object |
last()
|
static void |
main(java.lang.String[] args)
Test program. |
void |
print()
|
boolean |
remove(java.lang.Object o)
|
int |
size()
|
java.util.SortedSet |
subSet(java.lang.Object fromElement,
java.lang.Object toElement)
|
java.util.SortedSet |
tailSet(java.lang.Object fromElement)
|
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public IndexedTreeSet()
public IndexedTreeSet(java.util.Comparator comparator)
public IndexedTreeSet(java.util.Collection c)
public IndexedTreeSet(java.util.SortedSet s)
| Method Detail |
|---|
public boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in interface java.util.Setcontains in class java.util.AbstractCollectionpublic int size()
size in interface java.util.Collectionsize in interface java.util.Setsize in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Setiterator in class java.util.AbstractCollectionpublic boolean add(java.lang.Object o)
add in interface java.util.Collectionadd in interface java.util.Setadd in class java.util.AbstractCollectionpublic boolean remove(java.lang.Object o)
remove in interface java.util.Collectionremove in interface java.util.Setremove in class java.util.AbstractCollectionpublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Setclear in class java.util.AbstractCollectionpublic java.util.Comparator comparator()
comparator in interface java.util.SortedSetpublic java.lang.Object first()
first in interface java.util.SortedSetpublic java.lang.Object last()
last in interface java.util.SortedSetpublic java.util.SortedSet headSet(java.lang.Object toElement)
headSet in interface java.util.SortedSetpublic java.util.SortedSet tailSet(java.lang.Object fromElement)
tailSet in interface java.util.SortedSet
public java.util.SortedSet subSet(java.lang.Object fromElement,
java.lang.Object toElement)
subSet in interface java.util.SortedSetpublic java.lang.Object get(int index)
IndexedSet
get in interface IndexedSetpublic int indexOf(java.lang.Object o)
IndexedSet
indexOf in interface IndexedSetpublic java.lang.Object clone()
clone in class java.lang.Objectpublic void print()
public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||