changes to maintain strong update effects.
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / EffectsSet.java
1 package Analysis.OwnershipAnalysis;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 public class EffectsSet {
9
10         private Hashtable<Integer, HashSet<EffectsKey>> readTable;
11         private Hashtable<Integer, HashSet<EffectsKey>> writeTable;
12         private Hashtable<Integer, HashSet<EffectsKey>> strongUpdateTable;
13
14         public EffectsSet() {
15                 readTable = new Hashtable<Integer, HashSet<EffectsKey>>();
16                 writeTable = new Hashtable<Integer, HashSet<EffectsKey>>();
17                 strongUpdateTable = new Hashtable<Integer, HashSet<EffectsKey>>();
18         }
19
20         public void addReadingVar(Integer idx, EffectsKey access) {
21                 HashSet<EffectsKey> aSet = readTable.get(idx);
22                 if (aSet == null) {
23                         aSet = new HashSet<EffectsKey>();
24                 }
25
26                 aSet.add(access);
27                 readTable.put(idx, aSet);
28         }
29
30         public void addReadingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
31
32                 if (newSet != null) {
33                         HashSet<EffectsKey> aSet = readTable.get(idx);
34                         if (aSet == null) {
35                                 aSet = new HashSet<EffectsKey>();
36                         }
37                         aSet.addAll(newSet);
38                         readTable.put(idx, aSet);
39                 }
40
41         }
42
43         public void addWritingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
44
45                 if (newSet != null) {
46                         HashSet<EffectsKey> aSet = writeTable.get(idx);
47                         if (aSet == null) {
48                                 aSet = new HashSet<EffectsKey>();
49                         }
50                         aSet.addAll(newSet);
51                         writeTable.put(idx, aSet);
52                 }
53
54         }
55         
56         public void addStrongUpdateEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
57
58                 if (newSet != null) {
59                         HashSet<EffectsKey> aSet = strongUpdateTable.get(idx);
60                         if (aSet == null) {
61                                 aSet = new HashSet<EffectsKey>();
62                         }
63                         aSet.addAll(newSet);
64                         strongUpdateTable.put(idx, aSet);
65                 }
66
67         }
68         
69
70         public Hashtable<Integer, HashSet<EffectsKey>> getReadTable() {
71                 return readTable;
72         }
73
74         public Hashtable<Integer, HashSet<EffectsKey>> getWriteTable() {
75                 return writeTable;
76         }
77         
78         public Hashtable<Integer, HashSet<EffectsKey>> getStrongUpdateTable() {
79                 return strongUpdateTable;
80         }
81
82         public void addWritingVar(Integer idx, EffectsKey access) {
83                 HashSet<EffectsKey> aSet = writeTable.get(idx);
84                 if (aSet == null) {
85                         aSet = new HashSet<EffectsKey>();
86                 }
87                 aSet.add(access);
88                 writeTable.put(idx, aSet);      
89         }
90         
91         public void addStrongUpdateVar(Integer idx, EffectsKey access) {
92                 HashSet<EffectsKey> aSet = strongUpdateTable.get(idx);
93                 if (aSet == null) {
94                         aSet = new HashSet<EffectsKey>();
95                 }
96                 aSet.add(access);
97                 strongUpdateTable.put(idx, aSet);       
98         }
99
100         public Set<EffectsKey> getReadingSet(Integer idx) {
101                 return readTable.get(idx);
102         }
103
104         public Set<EffectsKey> getWritingSet(Integer idx) {
105                 return writeTable.get(idx);
106         }
107         
108         public Set<EffectsKey> getStrongUpdateSet(Integer idx) {
109                 return strongUpdateTable.get(idx);
110         }
111
112         public void printSet() {
113                 System.out.println("writeTable=>" + writeTable.hashCode());
114
115                 Set<Integer> keySet = readTable.keySet();
116                 Iterator<Integer> iter = keySet.iterator();
117                 while (iter.hasNext()) {
118                         Integer idx = iter.next();
119                         Set<EffectsKey> effectSet = readTable.get(idx);
120                         String keyStr = "{";
121                         if (effectSet != null) {
122                                 Iterator<EffectsKey> effectIter = effectSet.iterator();
123                                 while (effectIter.hasNext()) {
124                                         EffectsKey key = effectIter.next();
125                                         keyStr += " " + key;
126                                 }
127                         } else {
128                                 keyStr = "null";
129                         }
130                         System.out.println("param" + idx + " R=" + keyStr);
131                 }
132
133                 keySet = writeTable.keySet();
134                 System.out.println("# R keyset=" + keySet.size());
135                 iter = keySet.iterator();
136                 while (iter.hasNext()) {
137                         Integer idx = iter.next();
138                         Set<EffectsKey> effectSet = writeTable.get(idx);
139                         String keyStr = "{";
140                         if (effectSet != null) {
141                                 Iterator<EffectsKey> effectIter = effectSet.iterator();
142                                 while (effectIter.hasNext()) {
143                                         EffectsKey key = effectIter.next();
144                                         keyStr += " " + key;
145                                 }
146                         } else {
147                                 keyStr = "null";
148                         }
149                         System.out.println("param" + idx + " W=" + keyStr);
150                 }
151
152         }
153
154         public boolean equals(Object o) {
155                 if (o == null) {
156                         return false;
157                 }
158
159                 if (!(o instanceof EffectsSet)) {
160                         return false;
161                 }
162
163                 EffectsSet in = (EffectsSet) o;
164
165                 if (getReadTable().equals(in.getReadTable())
166                                 && getWriteTable().equals(in.getWriteTable())
167                                 && getStrongUpdateTable().equals(in.getStrongUpdateTable())) {
168                         return true;
169                 } else {
170                         return false;
171                 }
172
173         }
174
175         public int hashCode() {
176                 int hash = 1;
177
178                 hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31 + getStrongUpdateTable().hashCode();
179
180                 return hash;
181         }
182
183 }