edu.neu.ccs.demeterf.lib
Class Set<X>

java.lang.Object
  extended by edu.neu.ccs.demeterf.lib.Set<X>
All Implemented Interfaces:
java.lang.Iterable<X>

public class Set<X>
extends java.lang.Object
implements java.lang.Iterable<X>

Represents a Set of comparable Elements, implemented with RBTrees.


Nested Class Summary
static class Set.Merge<X>
          Function Class to help in the merging of Sets.
static class Set.tree
          Field Class
 
Constructor Summary
Set(java.util.Comparator<X> c, X... xs)
          Construct a Set from a parameter array.
Set(List<X> l)
          Construct a Set from a List of Comparable elements.
Set(RBTree<Wrap<X>> t)
          Construct a Set from a tree of Wrapped (Comparable) elements.
Set(X... xs)
          Construct a Set from a parameter array of Comparable elements.
 
Method Summary
 Set<X> add(X x)
          Returns a new Set that also contains the given element.
 boolean contains(X x)
          Is the given element present in this Set?
static
<X extends java.lang.Comparable<X>>
Set<X>
create()
          Construct the empty Set of Comparable elements.
static
<X> Set<X>
create(java.util.Comparator<X> c)
          Construct the empty Set with a separate Comparator.
static
<X extends java.lang.Comparable<X>>
Set<X>
create(List<X> l)
          Construct a Set from a List of Comparable elements.
static
<X> Set<X>
create(List<X> l, java.util.Comparator<X> c)
          Construct a Set from a List with a separate Comparator.
static
<X extends java.lang.Comparable<X>>
Set<X>
create(X... xs)
          Construct a Set from a number of Comparable elements.
 Set<X> difference(Set<X> s)
          Returns a new Set that is the difference of this and the given Set.
 boolean equals(java.lang.Object o)
          Set equality (s == t) is (s.subset(t) && t.subset(s)).
 int hashCode()
          Return the combined underlying elements HashCode
 Set<X> intersect(Set<X> s)
          Returns a new Set that is the intersection of this and the given Set.
 boolean isEmpty()
          Is this set empty?
 java.util.Iterator<X> iterator()
          Returns an iterator for this Set, in the order defined by the Comparator.
 Set<X> merge(Set<X> s, Set.Merge<X> m)
          Merge two sets with like elements merged by the given function object
 Set<X> merge(X x, Set.Merge<X> m)
          Merge a single element merged by the given function object
 Set<X> remove(X x)
          Returns a new Set that no longer contains the given element.
 int size()
          Return the nuber of elements in this Set
 boolean subseteq(Set<X> s)
          Is this Set a subset of (or equal to) the given set?
 List<X> toList()
          Returns this Set as a List, in the order defined by the Comparator.
 java.lang.String toString()
          Produce a string representation of this Set.
 Set<X> union(Set<X> s)
          Returns a new Set that is the union of this and the given Set.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Set

public Set(List<X> l)
Construct a Set from a List of Comparable elements. Duplicates will be ignored. Left Public to support Parsing


Set

public Set(X... xs)
Construct a Set from a parameter array of Comparable elements.


Set

public Set(java.util.Comparator<X> c,
           X... xs)
Construct a Set from a parameter array. The Comparator must be first due to Java's var-args syntax.


Set

public Set(RBTree<Wrap<X>> t)
Construct a Set from a tree of Wrapped (Comparable) elements.

Method Detail

create

public static <X extends java.lang.Comparable<X>> Set<X> create()
Construct the empty Set of Comparable elements.


create

public static <X> Set<X> create(java.util.Comparator<X> c)
Construct the empty Set with a separate Comparator.


create

public static <X extends java.lang.Comparable<X>> Set<X> create(List<X> l)
Construct a Set from a List of Comparable elements. Duplicates will be ignored.


create

public static <X> Set<X> create(List<X> l,
                                java.util.Comparator<X> c)
Construct a Set from a List with a separate Comparator. Duplicates will be ignored.


create

public static <X extends java.lang.Comparable<X>> Set<X> create(X... xs)
Construct a Set from a number of Comparable elements. Duplicates will be ignored.


contains

public boolean contains(X x)
Is the given element present in this Set?


isEmpty

public boolean isEmpty()
Is this set empty?


size

public int size()
Return the nuber of elements in this Set


add

public Set<X> add(X x)
Returns a new Set that also contains the given element.


remove

public Set<X> remove(X x)
Returns a new Set that no longer contains the given element.


subseteq

public boolean subseteq(Set<X> s)
Is this Set a subset of (or equal to) the given set?


union

public Set<X> union(Set<X> s)
Returns a new Set that is the union of this and the given Set.


intersect

public Set<X> intersect(Set<X> s)
Returns a new Set that is the intersection of this and the given Set.


difference

public Set<X> difference(Set<X> s)
Returns a new Set that is the difference of this and the given Set.


toList

public List<X> toList()
Returns this Set as a List, in the order defined by the Comparator.


iterator

public java.util.Iterator<X> iterator()
Returns an iterator for this Set, in the order defined by the Comparator.

Specified by:
iterator in interface java.lang.Iterable<X>

merge

public Set<X> merge(Set<X> s,
                    Set.Merge<X> m)
Merge two sets with like elements merged by the given function object


merge

public Set<X> merge(X x,
                    Set.Merge<X> m)
Merge a single element merged by the given function object


equals

public boolean equals(java.lang.Object o)
Set equality (s == t) is (s.subset(t) && t.subset(s)).

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Produce a string representation of this Set.

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Return the combined underlying elements HashCode

Overrides:
hashCode in class java.lang.Object