1 package Analysis.Disjoint;
8 ///////////////////////////////////////////
10 // This class is an immutable Canonical, so
12 // 0) construct them with a factory pattern
13 // to ensure only canonical versions escape
15 // 1) any operation that modifies a Canonical
16 // is a static method in the Canonical class
18 // 2) operations that just read this object
19 // should be defined here
21 // 3) every Canonical subclass hashCode should
22 // throw an error if the hash ever changes
24 ///////////////////////////////////////////
26 // a reach state is a set of reach tuples
27 // such that any heap region ID in a tuple
28 // appears at most once in the state
30 public class ReachState extends Canonical {
32 protected HashSet<ReachTuple> reachTuples;
35 public static ReachState factory() {
36 ReachState out = new ReachState();
37 out = (ReachState) Canonical.makeCanonical( out );
41 public static ReachState factory( ReachTuple rt ) {
43 assert rt.isCanonical();
44 ReachState out = new ReachState();
45 out.reachTuples.add( rt );
46 out = (ReachState) Canonical.makeCanonical( out );
50 protected ReachState() {
51 reachTuples = new HashSet<ReachTuple>();
55 public Iterator iterator() {
56 return reachTuples.iterator();
59 public boolean isEmpty() {
60 return reachTuples.isEmpty();
63 public boolean isSubset( ReachState rsIn ) {
65 return rsIn.reachTuples.containsAll( this.reachTuples );
68 public boolean containsTuple( ReachTuple rt ) {
70 return reachTuples.contains( rt );
73 // this should be a hash table so we can do this by key
74 public ReachTuple containsHrnID( Integer hrnID ) {
77 Iterator<ReachTuple> rtItr = reachTuples.iterator();
78 while( rtItr.hasNext() ) {
79 ReachTuple rt = rtItr.next();
80 if( hrnID.equals( rt.getHrnID() ) ) {
90 public boolean equals( Object o ) {
95 if( !(o instanceof ReachState) ) {
99 ReachState rs = (ReachState) o;
100 assert this.isCanonical();
101 assert rs.isCanonical();
106 public int hashCodeSpecific() {
107 return reachTuples.hashCode();
111 public String toString() {
112 return reachTuples.toString();