Class SET<Key extends Comparable<Key>>

Object
  extended by SET<Key>
All Implemented Interfaces:
Iterable<Key>

public class SET<Key extends Comparable<Key>>
extends Object
implements Iterable<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

SET

public SET()
Create an empty set.

Method Detail

isEmpty

public boolean isEmpty()
Is this set empty?


add

public void add(Key key)
Add the key to this set.


contains

public boolean contains(Key key)
Does this set contain the given key?


delete

public void delete(Key key)
Delete the given key from this set.


size

public int size()
Return the number of keys in this set.


iterator

public java.util.Iterator<Key> iterator()
Return an Iterator for this set.

Specified by:
iterator in interface Iterable<Key extends Comparable<Key>>

max

public Key max()
Return the key in this set with the maximum value.


min

public Key min()
Return the key in this set with the minimum value.


ceil

public Key ceil(Key k)
Return the smallest key in this set >= k.


floor

public Key floor(Key k)
Return the largest key in this set <= k.


union

public SET<Key> union(SET<Key> that)
Return the union of this set with that set.


intersects

public SET<Key> intersects(SET<Key> that)
Return the intersection of this set with that set.


main

public static void main(String[] args)
Test routine.