1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
10 public class ReadSummary {
12 Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>> summary;
14 public ReadSummary() {
15 summary = new Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>>();
18 public Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>> getSummary() {
22 public Set<NTuple<Descriptor>> keySet() {
23 return summary.keySet();
26 public Hashtable<Location, Set<Descriptor>> get(NTuple<Descriptor> hp) {
27 return summary.get(hp);
30 private Set<Descriptor> getReadSet(NTuple<Descriptor> key, Location loc) {
31 Hashtable<Location, Set<Descriptor>> map = summary.get(key);
33 map = new Hashtable<Location, Set<Descriptor>>();
34 summary.put(key, map);
36 Set<Descriptor> descSet = map.get(loc);
37 if (descSet == null) {
38 descSet = new HashSet<Descriptor>();
39 map.put(loc, descSet);
44 public void addRead(NTuple<Descriptor> key, Location loc, Descriptor in) {
46 // if location is null, we do not need to care about it!
47 Set<Descriptor> readSet = getReadSet(key, loc);
52 public void addReadSet(NTuple<Descriptor> key, Location loc, Set<Descriptor> inSet) {
53 Set<Descriptor> readSet = getReadSet(key, loc);
54 readSet.addAll(inSet);
57 public int hashCode() {
58 return summary.hashCode();
61 public boolean equals(Object o) {
63 if (!(o instanceof ReadSummary)) {
67 ReadSummary in = (ReadSummary) o;
69 if (getSummary().equals(in.getSummary())) {
76 public void put(NTuple<Descriptor> boundHeapPath, Hashtable<Location, Set<Descriptor>> inTable) {
78 Set<Location> keySet = inTable.keySet();
79 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
80 Location locKey = (Location) iterator.next();
81 Set<Descriptor> readSet = inTable.get(locKey);
82 addReadSet(boundHeapPath, locKey, readSet);
87 public void merge(ReadSummary in) {
89 Set<NTuple<Descriptor>> keySet = in.keySet();
90 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
91 NTuple<Descriptor> heapPathKey = (NTuple<Descriptor>) iterator.next();
92 put(heapPathKey, in.get(heapPathKey));
96 public String toString() {
97 return summary.toString();