|
|||||||||
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.Collection
contains
in interface java.util.Set
contains
in class java.util.AbstractCollection
public int size()
size
in interface java.util.Collection
size
in interface java.util.Set
size
in class java.util.AbstractCollection
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.Set
iterator
in class java.util.AbstractCollection
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
add
in interface java.util.Set
add
in class java.util.AbstractCollection
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
remove
in interface java.util.Set
remove
in class java.util.AbstractCollection
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.Set
clear
in class java.util.AbstractCollection
public java.util.Comparator comparator()
comparator
in interface java.util.SortedSet
public java.lang.Object first()
first
in interface java.util.SortedSet
public java.lang.Object last()
last
in interface java.util.SortedSet
public java.util.SortedSet headSet(java.lang.Object toElement)
headSet
in interface java.util.SortedSet
public 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.SortedSet
public java.lang.Object get(int index)
IndexedSet
get
in interface IndexedSet
public int indexOf(java.lang.Object o)
IndexedSet
indexOf
in interface IndexedSet
public java.lang.Object clone()
clone
in class java.lang.Object
public 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 |