EDU.auburn.VGJ.graph
Class Set

java.lang.Object
  |
  +--EDU.auburn.VGJ.graph.Set
All Implemented Interfaces:
java.lang.Cloneable

public class Set
extends java.lang.Object
implements java.lang.Cloneable

This class is similar to Java's BitSet class (only it is not full of bugs). It is used to represent an ordered set of non-negative integers. The set automatically grows as more spaces are needed.

Here is the source.


Constructor Summary
Set()
          Construct an empty Set.
Set(int element)
          Construct a Set with one element.
 
Method Summary
 java.lang.Object clone()
          Make a copy of current set.
 void difference(Set s)
          Modify the current set to the difference of current set and s (current - s).
 boolean equals(Set s)
          Check if set s equals to current set.
 void fill(int n)
          Put elements 0 to n - 1 into the current set.
 int first()
          Find the first element of current set.
 void includeElement(int n)
          Include element n into the current set.
 void indexedUnion(Set[] set_list, Set index)
           
 void intersect(Set s)
          Modify the current set to the intersection of current set and set s.
 boolean intersects(Set set)
           
 boolean isElement(int n)
          Check if n is an element of currernt set.
 boolean isEmpty()
          Check if current set is empty.
 boolean isSubset(Set s)
          Check if set s is a subset of current set.
 int next()
          Find the next element of current set.
 int numberOfElements()
          Find the number of elements of current set.
 void removeElement(int n)
          Remove element n from the current set.
 int searchNext(int n)
          Start at position n to search next element.
 java.lang.String toShortString()
          Convert set to "(0-2, 5, 9 ..., n)" String format.
 java.lang.String toString()
          Convert set to "(0, 1, 2, ..., n)" String format.
 void union(Set s)
          Modify the current set to the union of current set and set s.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Set

public Set()
Construct an empty Set.

Set

public Set(int element)
Construct a Set with one element.
Method Detail

searchNext

public int searchNext(int n)
Start at position n to search next element.
Parameters:
n - start position of searching
Returns:
element -- if an element found, or -1 -- if no element found.

isEmpty

public boolean isEmpty()
Check if current set is empty.
Returns:
true -- if current set is empty, or false -- if current set is not empty.

first

public int first()
Find the first element of current set.
Returns:
element -- the first element of the set, or -1 -- if set is empty.

next

public int next()
Find the next element of current set.
Returns:
element -- the next element of the set, or -1 -- if there is no next element.

isElement

public boolean isElement(int n)
Check if n is an element of currernt set.
Parameters:
n - element to be checked
Returns:
true -- n is an element of current set, or flase -- n is not an element of current set.

includeElement

public void includeElement(int n)
Include element n into the current set. This routine doesn't check if element n exists.
Parameters:
n - element to be included

removeElement

public void removeElement(int n)
                   throws java.util.NoSuchElementException
Remove element n from the current set. This routine doesn't check if element n exists.
Parameters:
n - element to removed

isSubset

public boolean isSubset(Set s)
Check if set s is a subset of current set.
Parameters:
s - subset to be checked
Returns:
true -- s is a subset of current set, or false -- s is not a subset of current set.

intersect

public void intersect(Set s)
Modify the current set to the intersection of current set and set s.
Parameters:
s - set to be checked
Returns:
the intersection of current set and set s.

union

public void union(Set s)
Modify the current set to the union of current set and set s.
Parameters:
s - set to be united
Returns:
the union of current set and set s.

difference

public void difference(Set s)
Modify the current set to the difference of current set and s (current - s).
Parameters:
s - set to be checked
Returns:
the difference of current set - set s.

clone

public java.lang.Object clone()
Make a copy of current set.
Overrides:
clone in class java.lang.Object
Returns:
copy of current set.

equals

public boolean equals(Set s)
Check if set s equals to current set.
Parameters:
s - set to be check
Returns:
true -- set s is equal to current set, or false -- set s is not equal to current set.

toString

public java.lang.String toString()
Convert set to "(0, 1, 2, ..., n)" String format.
Overrides:
toString in class java.lang.Object
Returns:
current set in String format.

toShortString

public java.lang.String toShortString()
Convert set to "(0-2, 5, 9 ..., n)" String format.
Returns:
current set in String format.

numberOfElements

public int numberOfElements()
Find the number of elements of current set.
Returns:
number of elements.

fill

public void fill(int n)
Put elements 0 to n - 1 into the current set.
Parameters:
n - number of elements to be included

indexedUnion

public void indexedUnion(Set[] set_list,
                         Set index)

intersects

public boolean intersects(Set set)