edu.mit.csail.sdg.alloy4compiler.sim
Class SimTupleset

java.lang.Object
  extended by edu.mit.csail.sdg.alloy4compiler.sim.SimTupleset
All Implemented Interfaces:
java.lang.Iterable<SimTuple>

public final class SimTupleset
extends java.lang.Object
implements java.lang.Iterable<SimTuple>

Immutable; represents a tupleset.


Field Summary
static SimTupleset EMPTY
          The tupleset containing no tuples.
 
Method Summary
 int arity()
          If this tupleset is empty, then return 0, else return the arity of every tuple in this tupleset.
 SimTupleset beginWith(SimTuple x)
          Return the set of tuples which begins with the given tuple (where we remove the "matching leading part")
 SimTupleset closure()
          Returns the closure of this tupleset (NOTE: if this.arity!=2, we will return an empty set)
 SimTupleset difference(SimTuple that)
          Return this minus that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
 SimTupleset difference(SimTupleset that)
          Return this minus that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
 SimTupleset domain(SimTupleset that)
          Returns this<:that (NOTE: if this.arity!=1, then we return the empty set)
 boolean empty()
          Returns true if this is empty.
 SimTupleset endWith(SimTuple x)
          Return the set of tuples which ends with the given tuple (where we remove the "matching trailing part")
 boolean equals(java.lang.Object that)
          Returns true if this contains the same tuples as that.
 boolean equals(SimTupleset that)
          Returns true if this contains the same tuples as that.
 java.util.List<SimAtom> getAllAtoms(int column)
          Returns a modifiable copy of the list of all i-th atom from all tuples in some arbitrary order (0 is first atom, 1 is second atom...)
 SimAtom getAtom()
          Returns an arbitrary atom from an arbitrary tuple.
 SimTuple getTuple()
          Returns an arbitrary tuple.
 boolean has(SimAtom that)
          Returns true if this tupleset is unary and contains the given atom.
 boolean has(SimTuple that)
          Returns true if this tupleset contains the given tuple.
 int hashCode()
          Returns a hashcode consistent with the equals() method.
 SimTupleset head(int n)
          Return the tupleset where each tuple is truncated to the first N atoms; if n is zero or negative, we return the emptyset; if n >= this.arity, we return this as is.
 SimTupleset iden()
          Return the identity over this tupleset; (if this tupleset's arity is not 1, then we return an emptyset)
Note: the result's tuple order is the same as this tupleset's tuple order.
 boolean in(SimTupleset that)
          Returns true if this is a subset of that.
 SimTupleset intersect(SimTupleset that)
          Return the intersection of this and that.
 boolean intersects(SimTupleset that)
          Return true if the intersection of this and that is nonempty.
 java.util.Iterator<SimTuple> iterator()
          Returns a read-only iterator over the tuples.
 SimTupleset join(SimTupleset that)
          Return the relational join between this and that (throws ErrorType if this.arity==1 and that.arity==1)
 java.util.Iterator<SimTupleset> loneOf()
          Return an iterator over all subset x of this where x.size<=1
 long longsize()
          Returns the number of tuples in this tupleset (this answer will never overflow)
static SimTupleset make(java.util.Collection<SimTuple> tuples)
          Make a tupleset containing a deep copy of the given list of tuples (Note: caller MUST make sure there are no duplicates, and all tuples are of same arity!)
static SimTupleset make(int min, int max)
          Construct the set containing integers between min and max (inclusively).
static SimTupleset make(SimTuple tuple)
          Construct a tupleset containing the given tuple.
static SimTupleset make(java.lang.String atom)
          Make a tupleset containing the given atom.
static SimTupleset makenext(int min, int max)
          Construct the set containing (min,min+1)...(max-1,max)
 java.util.Iterator<SimTupleset> oneOf()
          Return an iterator over all subset x of this where x.size==1
 SimTupleset override(SimTuple that)
          Return the relational override of this and that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
 SimTupleset override(SimTupleset that)
          Return the relational override of this and that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
 SimTupleset product(SimTupleset that)
          Return the cartesian product of this and that.
 SimTupleset range(SimTupleset that)
          Returns this:>that (NOTE: if that.arity!=1, then we return the empty set)
 SimTupleset removeAll(SimAtom that)
          Return this minus any tuple that contains the given atom.
 java.util.Iterator<SimTupleset> setOf()
          Return an iterator over all subset x of this
 int size()
          Returns the number of tuples in this tupleset (this answer may be truncated if it cannot fit in a 32-bit integer)
 java.util.Iterator<SimTupleset> someOf()
          Return an iterator over all subset x of this where x.size>=1
 int sum()
          Sum up all the integer atoms in this tupleset; (if this tupleset's arity is not 1, then we return 0)
 SimTupleset tail(int n)
          Return the tupleset where each tuple is truncated to the last N atoms; if n is zero or negative, we return the emptyset; if n >= this.arity, we return this as is.
 java.lang.String toString()
          
 boolean totalOrder(SimTupleset elem, SimTupleset first)
          Return true if this is a total ordering over "elem", with "first" being the first element of the total order.
 SimTupleset transpose()
          Return the transpose of this tupleset; (if this tupleset's arity is not 2, we'll return an empty set instead)
 SimTupleset union(SimTuple that)
          Return the union of this and that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
 SimTupleset union(SimTupleset that)
          Return the union of this and that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final SimTupleset EMPTY
The tupleset containing no tuples.

Method Detail

make

public static SimTupleset make(int min,
                               int max)
Construct the set containing integers between min and max (inclusively).


makenext

public static SimTupleset makenext(int min,
                                   int max)
Construct the set containing (min,min+1)...(max-1,max)


make

public static SimTupleset make(SimTuple tuple)
Construct a tupleset containing the given tuple.


make

public static SimTupleset make(java.lang.String atom)
Make a tupleset containing the given atom.


make

public static SimTupleset make(java.util.Collection<SimTuple> tuples)
Make a tupleset containing a deep copy of the given list of tuples (Note: caller MUST make sure there are no duplicates, and all tuples are of same arity!)


arity

public int arity()
If this tupleset is empty, then return 0, else return the arity of every tuple in this tupleset.


empty

public boolean empty()
Returns true if this is empty.


size

public int size()
Returns the number of tuples in this tupleset (this answer may be truncated if it cannot fit in a 32-bit integer)


longsize

public long longsize()
Returns the number of tuples in this tupleset (this answer will never overflow)


has

public boolean has(SimTuple that)
Returns true if this tupleset contains the given tuple.


has

public boolean has(SimAtom that)
Returns true if this tupleset is unary and contains the given atom.


getAtom

public SimAtom getAtom()
                throws ErrorAPI
Returns an arbitrary atom from an arbitrary tuple.

Throws:
- - ErrorAPI if this tupleset is empty
ErrorAPI

getTuple

public SimTuple getTuple()
                  throws ErrorAPI
Returns an arbitrary tuple.

Throws:
- - ErrorAPI if this tupleset is empty
ErrorAPI

union

public SimTupleset union(SimTupleset that)
Return the union of this and that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
Note: the tuples in the result will be ordered as follows: first comes the tuples in "this" in original order, then the tuples that are in "that" but not in "this".


union

public SimTupleset union(SimTuple that)
Return the union of this and that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
Note: if this operation is a no-op, we guarantee we'll return this SimTupleset as is.


head

public SimTupleset head(int n)
Return the tupleset where each tuple is truncated to the first N atoms; if n is zero or negative, we return the emptyset; if n >= this.arity, we return this as is.


tail

public SimTupleset tail(int n)
Return the tupleset where each tuple is truncated to the last N atoms; if n is zero or negative, we return the emptyset; if n >= this.arity, we return this as is.


iterator

public java.util.Iterator<SimTuple> iterator()
Returns a read-only iterator over the tuples.

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

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode consistent with the equals() method.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object that)
Returns true if this contains the same tuples as that.

Overrides:
equals in class java.lang.Object

equals

public boolean equals(SimTupleset that)
Returns true if this contains the same tuples as that.


in

public boolean in(SimTupleset that)
Returns true if this is a subset of that.


sum

public int sum()
Sum up all the integer atoms in this tupleset; (if this tupleset's arity is not 1, then we return 0)


iden

public SimTupleset iden()
Return the identity over this tupleset; (if this tupleset's arity is not 1, then we return an emptyset)
Note: the result's tuple order is the same as this tupleset's tuple order.


override

public SimTupleset override(SimTuple that)
Return the relational override of this and that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
Note: in general, the tuples may be ordered arbitrarily in the result.
Note: if this operation is a no-op, we guarantee we'll return this SimTupleset as is.


override

public SimTupleset override(SimTupleset that)
                     throws ErrorAPI
Return the relational override of this and that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
Note: in general, the tuples may be ordered arbitrarily in the result.

Throws:
ErrorAPI

difference

public SimTupleset difference(SimTupleset that)
Return this minus that; (if this tupleset and that tupleset does not have compatible arity, then we return this tupleset as is).
Note: The resulting tuples will keep their original order.


difference

public SimTupleset difference(SimTuple that)
Return this minus that; (if this tupleset and that tuple does not have compatible arity, then we return this tupleset as is).
Note: The resulting tuples will keep their original order.
Note: if this operation is a no-op, we guarantee we'll return this SimTupleset as is.


removeAll

public SimTupleset removeAll(SimAtom that)
Return this minus any tuple that contains the given atom.
Note: The resulting tuples will keep their original order.


transpose

public SimTupleset transpose()
Return the transpose of this tupleset; (if this tupleset's arity is not 2, we'll return an empty set instead)


product

public SimTupleset product(SimTupleset that)
Return the cartesian product of this and that.


join

public SimTupleset join(SimTupleset that)
                 throws ErrorType
Return the relational join between this and that (throws ErrorType if this.arity==1 and that.arity==1)

Throws:
ErrorType

intersect

public SimTupleset intersect(SimTupleset that)
Return the intersection of this and that.


intersects

public boolean intersects(SimTupleset that)
Return true if the intersection of this and that is nonempty.


domain

public SimTupleset domain(SimTupleset that)
Returns this<:that (NOTE: if this.arity!=1, then we return the empty set)


range

public SimTupleset range(SimTupleset that)
Returns this:>that (NOTE: if that.arity!=1, then we return the empty set)


closure

public SimTupleset closure()
Returns the closure of this tupleset (NOTE: if this.arity!=2, we will return an empty set)


beginWith

public SimTupleset beginWith(SimTuple x)
Return the set of tuples which begins with the given tuple (where we remove the "matching leading part")


endWith

public SimTupleset endWith(SimTuple x)
Return the set of tuples which ends with the given tuple (where we remove the "matching trailing part")


getAllAtoms

public java.util.List<SimAtom> getAllAtoms(int column)
                                    throws ErrorAPI
Returns a modifiable copy of the list of all i-th atom from all tuples in some arbitrary order (0 is first atom, 1 is second atom...)

Throws:
- - ErrorAPI if this tupleset contains at least one tuple whose length is less than or equal to i
ErrorAPI

totalOrder

public boolean totalOrder(SimTupleset elem,
                          SimTupleset first)
                   throws ErrorAPI
Return true if this is a total ordering over "elem", with "first" being the first element of the total order.

Throws:
ErrorAPI

loneOf

public java.util.Iterator<SimTupleset> loneOf()
Return an iterator over all subset x of this where x.size<=1


oneOf

public java.util.Iterator<SimTupleset> oneOf()
Return an iterator over all subset x of this where x.size==1


setOf

public java.util.Iterator<SimTupleset> setOf()
Return an iterator over all subset x of this


someOf

public java.util.Iterator<SimTupleset> someOf()
Return an iterator over all subset x of this where x.size>=1