changes.
[IRC.git] / Robust / src / Analysis / SSJava / SharedLocMap.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import IR.Descriptor;
9
10 public class SharedLocMap {
11
12   Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> map;
13
14   public SharedLocMap() {
15     map = new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
16   }
17
18   public Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMap() {
19     return map;
20   }
21
22   public boolean equals(Object obj) {
23
24     if (obj instanceof SharedLocMap) {
25       return map.equals(((SharedLocMap) obj).getMap());
26     } else {
27       return false;
28     }
29
30   }
31
32   public int hashCode() {
33     return map.hashCode();
34   }
35
36   public Set<NTuple<Descriptor>> get(NTuple<Location> locTuple) {
37     return map.get(locTuple);
38   }
39
40   public void addWrite(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
41
42     if (hpSet != null) {
43       Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
44       if (writeSet == null) {
45         writeSet = new HashSet<NTuple<Descriptor>>();
46         map.put(locTuple, writeSet);
47       }
48       writeSet.addAll(hpSet);
49     }
50
51   }
52
53   public void addWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
54
55     if (hp != null) {
56       Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
57       if (writeSet == null) {
58         writeSet = new HashSet<NTuple<Descriptor>>();
59         map.put(locTuple, writeSet);
60       }
61       writeSet.add(hp);
62     }
63
64   }
65
66   public void intersect(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
67
68     Set<NTuple<Descriptor>> set = map.get(locTuple);
69     if (set == null) {
70       set = new HashSet<NTuple<Descriptor>>();
71       map.put(locTuple, set);
72       set.addAll(hpSet);
73     }
74
75     set.addAll(hpSet);
76
77   }
78
79   public void removeWrite(NTuple<Location> locTuple, NTuple<Descriptor> hp) {
80     Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
81     if (writeSet != null) {
82       writeSet.remove(hp);
83     }
84   }
85
86   public void removeWriteAll(NTuple<Location> locTuple, Set<NTuple<Descriptor>> hpSet) {
87
88     if (hpSet != null) {
89       Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
90       if (writeSet != null) {
91         writeSet.removeAll(hpSet);
92       }
93     }
94
95   }
96
97   public String toString() {
98     return map.toString();
99   }
100
101   public Set<NTuple<Location>> keySet() {
102     return map.keySet();
103   }
104
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();
109       map.remove(killKey);
110     }
111   }
112
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));
118     }
119   }
120
121   public void clear() {
122     map.clear();
123   }
124
125   public SharedLocMap getHeapPathStartedWith(NTuple<Location> locTuple) {
126
127     SharedLocMap rtrSet = new SharedLocMap();
128
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));
134       }
135     }
136     return rtrSet;
137
138   }
139
140   public boolean containsElement(NTuple<Descriptor> heapPath) {
141
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)) {
146         return true;
147       }
148     }
149     return false;
150   }
151
152 }