public class ChangeTupleSet {
- public HashSet<ChangeTuple> changeTuples;
+ private HashSet<ChangeTuple> changeTuples;
public ChangeTupleSet() {
changeTuples = new HashSet<ChangeTuple>();
}
public String toString() {
- return changeTuples.toString();
+ String s = "[";
+
+ Iterator i = this.iterator();
+ while( i.hasNext() ) {
+ s += "\n "+i.next();
+ }
+
+ s += "\n]";
+
+ return s;
}
}
public class ReachabilitySet {
- public HashSet<TokenTupleSet> possibleReachabilities;
+ private HashSet<TokenTupleSet> possibleReachabilities;
public ReachabilitySet() {
possibleReachabilities = new HashSet<TokenTupleSet>();
}
+ public ReachabilitySet( TokenTupleSet tts ) {
+ possibleReachabilities = new HashSet<TokenTupleSet>();
+ possibleReachabilities.add( tts );
+ }
+
public ReachabilitySet( ReachabilitySet rs ) {
possibleReachabilities = (HashSet<TokenTupleSet>) rs.possibleReachabilities.clone(); // again, DEEP COPY?!
}
while( itrRelement.hasNext() ) {
TokenTuple e = (TokenTuple) itrRelement.next();
- if( o.contains( e ) ) {
- theUnion.union( new TokenTupleSet( e.increaseArity() ) );
+ if( o.containsToken( e.getToken() ) ) {
+ theUnion = theUnion.union( new TokenTupleSet( e.increaseArity() ) );
+ } else {
+ theUnion = theUnion.union( new TokenTupleSet( e ) );
}
}
+
+ Iterator itrOelement = o.iterator();
+ while( itrOelement.hasNext() ) {
+ TokenTuple e = (TokenTuple) itrOelement.next();
+
+ if( !theUnion.containsToken( e.getToken() ) ) {
+ theUnion = theUnion.union( new TokenTupleSet( e ) );
+ }
+ }
+
+ if( !theUnion.isEmpty() ) {
+ ctsOut = ctsOut.union(
+ new ChangeTupleSet(
+ new ChangeTuple( o, theUnion )
+ )
+ );
+ }
}
}
return ctsOut;
}
-}
-
-/*
-Set specialUnion( Set O, Set R ) {
- Set C = {}
-
- foreach o in O {
- foreach r in R {
-
- Set theUnion = {}
- foreach e in r {
- if o.contains( e ) {
- if e.isSummaryToken() { // wait, stronger condition?
- theUnion.add( e.copy().increaseArity() )
- } else {
- theUnion.add( e.copy() )
- }
- }
- }
+ public String toString() {
+ String s = "[";
- foreach e in o {
- if !theUnion.contains( e ) {
- theUnion.add( e.copy() )
- }
- }
+ Iterator i = this.iterator();
+ while( i.hasNext() ) {
+ s += "\n "+i.next();
+ }
- if !theUnion.isEmpty() {
- C.add( <o, theUnion> )
- }
+ s += "\n]";
+ return s;
}
- }
-
- return C
}
-*/
public String toString() {
String s = "";
if( isNewSummary ) {
- s = "sum";
+ s = "S";
}
String t = "1";
if( arity == ARITY_MANY ) {
- t = "many";
+ t = "M";
}
- return new String( "<"+token+s+", "+t+">" );
+ return new String( "<"+token+s+","+t+">" );
}
}
public class TokenTupleSet {
- public HashSet<TokenTuple> tokenTuples;
+ private HashSet<TokenTuple> tokenTuples;
public TokenTupleSet() {
tokenTuples = new HashSet<TokenTuple>();
return ttsOut;
}
- public boolean contains( TokenTuple tt ) {
+ public boolean isEmpty() {
+ return tokenTuples.isEmpty();
+ }
+
+ public boolean containsTuple( TokenTuple tt ) {
return tokenTuples.contains( tt );
}
+ // this should be a hash table so we can do this by key
+ public boolean containsToken( Integer token ) {
+ Iterator itr = tokenTuples.iterator();
+ while( itr.hasNext() ) {
+ TokenTuple tt = (TokenTuple) itr.next();
+ if( token.equals( tt.getToken() ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
return tokenTuples.toString();
}
true,
TokenTuple.ARITY_ONE );
- TokenTuple tt1 = tt0.copy();
+ TokenTuple tt1 = new TokenTuple( new Integer( 1 ),
+ true,
+ TokenTuple.ARITY_ONE );
TokenTuple tt2 = new TokenTuple( new Integer( 2 ),
true,
test( "tt2 equals tt3?", false, tt2.equals( tt3 ) );
test( "tt3 equals tt2?", false, tt3.equals( tt2 ) );
- tt1.increaseArity();
+ tt1 = tt1.increaseArity();
test( "tt1 equals tt2?", false, tt1.equals( tt2 ) );
test( "tt2 equals tt1?", false, tt2.equals( tt1 ) );
System.out.println( "tts4 is "+tts4 );
System.out.println( "tts5 is "+tts5 );
System.out.println( "tts6 is "+tts6 );
+
+ ReachabilitySet rs0 = new ReachabilitySet( tts0 );
+ rs0 = rs0.union( new ReachabilitySet( tts2 ) );
+ rs0 = rs0.union( new ReachabilitySet( tts5 ) );
+
+ System.out.println( "rs0 is "+rs0 );
+
+ TokenTuple tt4 = new TokenTuple( new Integer( 4 ),
+ true,
+ TokenTuple.ARITY_ONE );
+
+ /* TokenTuple tt5 = new TokenTuple( new Integer( 4 ),
+ true,
+ TokenTuple.ARITY_ONE );
+ */
+ TokenTuple tt6 = new TokenTuple( new Integer( 6 ),
+ false,
+ TokenTuple.ARITY_ONE );
+
+ TokenTupleSet tts7 = new TokenTupleSet( tt4 );
+ //TokenTupleSet tts8 = new TokenTupleSet( tt5 );
+ TokenTupleSet tts9 = new TokenTupleSet( tt1 );
+ tts9 = tts9.union( tts2 );
+
+ ReachabilitySet rs1 = new ReachabilitySet( tts7 );
+ //rs1 = rs1.union( new ReachabilitySet( tts8 ) );
+ rs1 = rs1.union( new ReachabilitySet( tts9 ) );
+
+ System.out.println( "rs1 is "+rs1 );
+
+
+ ChangeTupleSet cts0 = rs0.unionUpArity( rs1 );
+ System.out.println( "cts0 is "+cts0 );
}
}
\ No newline at end of file