fix problems of shared loc extension
[IRC.git] / Robust / src / Analysis / SSJava / SharedLocMap.java
index 822c3e2b66837c5b846d58f6d18cfe0721e2f6a0..863ea95ba7261e4a75fa150305928ef3774aa78a 100644 (file)
@@ -39,22 +39,41 @@ public class SharedLocMap {
 
   public void addWrite(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
 
-    Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
-    if (writeSet == null) {
-      writeSet = new HashSet<NTuple<Descriptor>>();
-      map.put(locTuple, writeSet);
+    if (hpSet != null) {
+      Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
+      if (writeSet == null) {
+        writeSet = new HashSet<NTuple<Descriptor>>();
+        map.put(locTuple, writeSet);
+      }
+      writeSet.addAll(hpSet);
     }
-    writeSet.addAll(hpSet);
+
   }
 
   public void addWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
 
-    Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
-    if (writeSet == null) {
-      writeSet = new HashSet<NTuple<Descriptor>>();
-      map.put(locTuple, writeSet);
+    if (hp != null) {
+      Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
+      if (writeSet == null) {
+        writeSet = new HashSet<NTuple<Descriptor>>();
+        map.put(locTuple, writeSet);
+      }
+      writeSet.add(hp);
     }
-    writeSet.add(hp);
+
+  }
+
+  public void intersect(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
+
+    Set<NTuple<Descriptor>> set = map.get(locTuple);
+    if (set == null) {
+      set = new HashSet<NTuple<Descriptor>>();
+      map.put(locTuple, set);
+      set.addAll(hpSet);
+    }
+
+    set.addAll(hpSet);
+
   }
 
   public void removeWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
@@ -64,6 +83,17 @@ public class SharedLocMap {
     }
   }
 
+  public void removeWriteAll(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
+    
+    if(hpSet!=null){
+      Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
+      if (writeSet != null) {
+        writeSet.removeAll(hpSet);
+      }
+    }
+
+  }
+
   public String toString() {
     return map.toString();
   }
@@ -88,4 +118,23 @@ public class SharedLocMap {
     }
   }
 
+  public void clear() {
+    map.clear();
+  }
+
+  public SharedLocMap getHeapPathStartedWith(NTuple<Location> locTuple) {
+
+    SharedLocMap rtrSet = new SharedLocMap();
+
+    Set<NTuple<Location>> keySet = map.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      NTuple<Location> key = (NTuple<Location>) iterator.next();
+      if (key.startsWith(locTuple)) {
+        rtrSet.addWrite(key, map.get(key));
+      }
+    }
+    return rtrSet;
+
+  }
+
 }