add option to graph visualization that supresses reachability subsets, for improved...
[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
13         public EffectsSet() {
14                 readTable = new Hashtable<Integer, HashSet<EffectsKey>>();
15                 writeTable = new Hashtable<Integer, HashSet<EffectsKey>>();
16         }
17
18         public void addReadingVar(Integer idx, EffectsKey access) {
19                 HashSet<EffectsKey> aSet = readTable.get(idx);
20                 if (aSet == null) {
21                         aSet = new HashSet<EffectsKey>();
22                 }
23
24                 aSet.add(access);
25                 readTable.put(idx, aSet);
26         }
27
28         public void addReadingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
29
30                 if (newSet != null) {
31                         HashSet<EffectsKey> aSet = readTable.get(idx);
32                         if (aSet == null) {
33                                 aSet = new HashSet<EffectsKey>();
34                         }
35                         aSet.addAll(newSet);
36                         readTable.put(idx, aSet);
37                 }
38
39         }
40
41         public void addWritingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
42
43                 if (newSet != null) {
44                         HashSet<EffectsKey> aSet = writeTable.get(idx);
45                         if (aSet == null) {
46                                 aSet = new HashSet<EffectsKey>();
47                         }
48                         aSet.addAll(newSet);
49                         writeTable.put(idx, aSet);
50                 }
51
52         }
53
54         public Hashtable<Integer, HashSet<EffectsKey>> getReadTable() {
55                 return readTable;
56         }
57
58         public Hashtable<Integer, HashSet<EffectsKey>> getWriteTable() {
59                 return writeTable;
60         }
61
62         public void addWritingVar(Integer idx, EffectsKey access) {
63                 HashSet<EffectsKey> aSet = writeTable.get(idx);
64                 if (aSet == null) {
65                         aSet = new HashSet<EffectsKey>();
66                 }
67                 aSet.add(access);
68                 writeTable.put(idx, aSet);
69         }
70
71         public Set<EffectsKey> getReadingSet(Integer idx) {
72                 return readTable.get(idx);
73         }
74
75         public Set<EffectsKey> getWritingSet(Integer idx) {
76                 return writeTable.get(idx);
77         }
78
79         public void printSet() {
80                 System.out.println("writeTable=>" + writeTable.hashCode());
81
82                 Set<Integer> keySet = readTable.keySet();
83                 Iterator<Integer> iter = keySet.iterator();
84                 while (iter.hasNext()) {
85                         Integer idx = iter.next();
86                         Set<EffectsKey> effectSet = readTable.get(idx);
87                         String keyStr = "{";
88                         if (effectSet != null) {
89                                 Iterator<EffectsKey> effectIter = effectSet.iterator();
90                                 while (effectIter.hasNext()) {
91                                         EffectsKey key = effectIter.next();
92                                         keyStr += " " + key;
93                                 }
94                         } else {
95                                 keyStr = "null";
96                         }
97                         System.out.println("param" + idx + " R=" + keyStr);
98                 }
99
100                 keySet = writeTable.keySet();
101                 System.out.println("# R keyset=" + keySet.size());
102                 iter = keySet.iterator();
103                 while (iter.hasNext()) {
104                         Integer idx = iter.next();
105                         Set<EffectsKey> effectSet = writeTable.get(idx);
106                         String keyStr = "{";
107                         if (effectSet != null) {
108                                 Iterator<EffectsKey> effectIter = effectSet.iterator();
109                                 while (effectIter.hasNext()) {
110                                         EffectsKey key = effectIter.next();
111                                         keyStr += " " + key;
112                                 }
113                         } else {
114                                 keyStr = "null";
115                         }
116                         System.out.println("param" + idx + " W=" + keyStr);
117                 }
118
119         }
120
121         public boolean equals(Object o) {
122                 if (o == null) {
123                         return false;
124                 }
125
126                 if (!(o instanceof EffectsSet)) {
127                         return false;
128                 }
129
130                 EffectsSet in = (EffectsSet) o;
131
132                 if (getReadTable().equals(in.getReadTable())
133                                 && getWriteTable().equals(in.getWriteTable())) {
134                         return true;
135                 } else {
136                         return false;
137                 }
138
139         }
140
141         public int hashCode() {
142                 int hash = 1;
143
144                 hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31;
145
146                 return hash;
147         }
148
149 }