special union of reachability sets works correctly now
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ReachabilitySet.java
index 6f612414bada4286e7a23e04ec364cf6a5270065..83d6bfce40b5de2ba81e5c8c6de80ec5653456ad 100644 (file)
@@ -8,12 +8,17 @@ import java.io.*;
 
 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?!
     }
@@ -59,49 +64,45 @@ public class ReachabilitySet {
                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
 }
-*/