bug fixes
[IRC.git] / Robust / src / Analysis / Prefetch / PairMap.java
1 /*
2  * PairMap.java
3  * Author: Alokika Dash adash@uci.edu
4  * Date: 11-24-2007
5  */
6
7 package Analysis.Prefetch;
8 import IR.Flat.*;
9 import java.util.*;
10 import IR.*;
11
12 /**
13  * Descriptor
14  * This class is used to represent mappings between Prefetch sets of a parent and
15  * child flatnode m(PSchildnode --> PSparentnode) Such analysis  is used to insert
16  * prefetches during static analysis
17  */
18
19 public class PairMap {
20         public HashMap<PrefetchPair, PrefetchPair>  mappair;
21
22         public PairMap() {
23                 mappair = new HashMap<PrefetchPair, PrefetchPair>();
24         }
25
26         public void addPair(PrefetchPair ppKey, PrefetchPair ppValue) {
27                 mappair.put(ppKey, ppValue);
28         }
29
30         public void removePair(PrefetchPair ppKey) {
31                 mappair.remove(ppKey);
32         }
33
34         public PrefetchPair getPair(PrefetchPair ppKey) {
35                 if(mappair != null) 
36                         return mappair.get(ppKey);
37                 return null;
38         }
39
40         public int hashCode() {
41                 int hashcode = mappair.hashCode();
42                 return hashcode;
43         }
44
45         public String pairMapToString() {
46                 String label = null;
47                 Set mapping = mappair.entrySet();
48                 Iterator it = mapping.iterator();
49                 label = "Mappings are:  ";
50                 for(;it.hasNext();) {
51                         Object o = it.next();
52                         label += o.toString() + "  ";
53                 }
54                 return label;
55         }
56
57         public boolean equals(Object o) {
58                 if(o instanceof PairMap) {
59                         PairMap pm = (PairMap) o;
60                         if(mappair == null && pm.mappair == null) {
61                                 return true;
62                         } else if(mappair != null && pm.mappair != null) {
63                                 if(mappair.equals((HashMap) pm.mappair)) {
64                                         return true;
65                                 }
66                         } else {
67                                 return false;
68                         }
69                 }
70                 return false;
71         }
72
73         public boolean isEmpty() {
74                 if(mappair.isEmpty())
75                         return true;
76                 return false;
77         }
78 }