ObjectSET<Key>
public class SET<Key extends Comparable<Key>>
The SET class represents an ordered set. It assumes that the elements are Comparable. It supports the usual add, contains, and delete methods. It also provides ordered methods for finding the minimum, maximum, floor, and ceiling.
This implementation uses a balanced binary search tree. The add, contains, delete, minimum, maximum, ceiling, and floor methods take logarithmic time.
For additional documentation, see Section 4.4 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
| Constructor Summary | |
|---|---|
SET()
Create an empty set. |
|
| Method Summary | |
|---|---|
void |
add(Key key)
Add the key to this set. |
Key |
ceil(Key k)
Return the smallest key in this set >= k. |
boolean |
contains(Key key)
Does this set contain the given key? |
void |
delete(Key key)
Delete the given key from this set. |
Key |
floor(Key k)
Return the largest key in this set <= k. |
SET<Key> |
intersects(SET<Key> that)
Return the intersection of this set with that set. |
boolean |
isEmpty()
Is this set empty? |
java.util.Iterator<Key> |
iterator()
Return an Iterator for this set. |
static void |
main(String[] args)
Test routine. |
Key |
max()
Return the key in this set with the maximum value. |
Key |
min()
Return the key in this set with the minimum value. |
int |
size()
Return the number of keys in this set. |
SET<Key> |
union(SET<Key> that)
Return the union of this set with that set. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SET()
| Method Detail |
|---|
public boolean isEmpty()
public void add(Key key)
public boolean contains(Key key)
public void delete(Key key)
public int size()
public java.util.Iterator<Key> iterator()
iterator in interface Iterable<Key extends Comparable<Key>>public Key max()
public Key min()
public Key ceil(Key k)
public Key floor(Key k)
public SET<Key> union(SET<Key> that)
public SET<Key> intersects(SET<Key> that)
public static void main(String[] args)