1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
10 public class SharedLocMap {
12 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> map;
14 public SharedLocMap() {
15 map = new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
18 public Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMap() {
22 public boolean equals(Object obj) {
24 if (obj instanceof SharedLocMap) {
25 return map.equals(((SharedLocMap) obj).getMap());
32 public int hashCode() {
33 return map.hashCode();
36 public Set<NTuple<Descriptor>> get(NTuple<Location> locTuple) {
37 return map.get(locTuple);
40 public void addWrite(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
43 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
44 if (writeSet == null) {
45 writeSet = new HashSet<NTuple<Descriptor>>();
46 map.put(locTuple, writeSet);
48 writeSet.addAll(hpSet);
53 public void addWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
56 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
57 if (writeSet == null) {
58 writeSet = new HashSet<NTuple<Descriptor>>();
59 map.put(locTuple, writeSet);
66 public void intersect(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
68 Set<NTuple<Descriptor>> set = map.get(locTuple);
70 set = new HashSet<NTuple<Descriptor>>();
71 map.put(locTuple, set);
79 public void removeWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
80 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
81 if (writeSet != null) {
86 public void removeWriteAll(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
89 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
90 if (writeSet != null) {
91 writeSet.removeAll(hpSet);
97 public String toString() {
98 return map.toString();
101 public Set<NTuple<Location>> keySet() {
105 public void kill(SharedLocMap kill) {
106 Set<NTuple<Location>> killKeySet = kill.keySet();
107 for (Iterator iterator = killKeySet.iterator(); iterator.hasNext();) {
108 NTuple<Location> killKey = (NTuple<Location>) iterator.next();
113 public void gen(SharedLocMap gen) {
114 Set<NTuple<Location>> genKeySet = gen.keySet();
115 for (Iterator iterator = genKeySet.iterator(); iterator.hasNext();) {
116 NTuple<Location> genKey = (NTuple<Location>) iterator.next();
117 map.put(genKey, gen.get(genKey));
121 public void clear() {
125 public SharedLocMap getHeapPathStartedWith(NTuple<Location> locTuple) {
127 SharedLocMap rtrSet = new SharedLocMap();
129 Set<NTuple<Location>> keySet = map.keySet();
130 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
131 NTuple<Location> key = (NTuple<Location>) iterator.next();
132 if (key.startsWith(locTuple)) {
133 rtrSet.addWrite(key, map.get(key));
140 public boolean containsElement(NTuple<Descriptor> heapPath) {
142 Set<NTuple<Location>> locTupleSet = map.keySet();
143 for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
144 NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
145 if (map.get(locTuple).contains(heapPath)) {