import java.util.*;\r
import java.io.*;\r
\r
+// This class formerly had lazy consistency properties, but\r
+// it is being changed so that the full set and the extra\r
+// hash tables to access the full set efficiently by different\r
+// elements will be consistent after EVERY operation. Also,\r
+// a consistent assert method allows a debugger to ask whether\r
+// an operation has produced an inconsistent VarSrcTokTable.\r
public class VarSrcTokTable {\r
- \r
- // the true set represents the set of (sese, variable, age)\r
- // triples that are truly in the table\r
+\r
+ // a set of every token in the table\r
private HashSet<VariableSourceToken> trueSet;\r
\r
- // these hashtables provide an efficient retreival from the\r
- // true set. Note that a particular triple from the quick\r
- // look up must be checked against the true set--remove ops\r
- // can cause the hashtables to be inconsistent to each other\r
+ // these hashtables provide an efficient retreival from the true set\r
private Hashtable< TempDescriptor, Set<VariableSourceToken> > var2vst;\r
private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;\r
private Hashtable< SVKey, Set<VariableSourceToken> > sv2vst;\r
Iterator itr; Set s;\r
\r
sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();\r
- itr = sese2vst.entrySet().iterator();\r
+ itr = in.sese2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();\r
}\r
\r
var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();\r
- itr = var2vst.entrySet().iterator();\r
+ itr = in.var2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
TempDescriptor var = (TempDescriptor) me.getKey();\r
}\r
\r
sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();\r
- itr = sv2vst.entrySet().iterator();\r
+ itr = in.sv2vst.entrySet().iterator();\r
while( itr.hasNext() ) {\r
Map.Entry me = (Map.Entry) itr.next();\r
SVKey key = (SVKey) me.getKey();\r
s = new HashSet<VariableSourceToken>(); \r
sese2vst.put( sese, s );\r
}\r
- s.retainAll( trueSet );\r
return s;\r
}\r
\r
s = new HashSet<VariableSourceToken>();\r
var2vst.put( var, s );\r
}\r
- s.retainAll( trueSet );\r
return s;\r
}\r
\r
s = new HashSet<VariableSourceToken>();\r
sv2vst.put( key, s );\r
}\r
- s.retainAll( trueSet );\r
return s;\r
}\r
\r
\r
- public void merge( VarSrcTokTable table ) {\r
+ public void merge( VarSrcTokTable tableIn ) {\r
\r
- if( table == null ) {\r
+ if( tableIn == null ) {\r
return;\r
}\r
\r
+ // make a copy for modification to use in the merge\r
+ VarSrcTokTable table = new VarSrcTokTable( tableIn );\r
+\r
trueSet.addAll( table.trueSet );\r
\r
Iterator itr; \r
\r
if( s2 != null ) {\r
s1.addAll( s2 );\r
- } \r
+ }\r
}\r
s = table.sese2vst.entrySet();\r
s.removeAll( sese2vst.entrySet() );\r
}\r
\r
\r
+ // remove operations must leave the trueSet \r
+ // and the hash maps consistent!\r
+ public void remove( VariableSourceToken vst ) {\r
+ trueSet.remove( vst );\r
+ \r
+ Set<VariableSourceToken> s;\r
+\r
+ s = get( vst.getSESE() );\r
+ if( s != null ) { s.remove( vst ); }\r
+\r
+ s = get( vst.getVarLive() );\r
+ if( s != null ) { s.remove( vst ); }\r
+\r
+ s = get( new SVKey( vst.getSESE(), vst.getVarLive() ) );\r
+ if( s != null ) { s.remove( vst ); }\r
+ }\r
+\r
public void remove( FlatSESEEnterNode sese ) {\r
Set<VariableSourceToken> s = sese2vst.get( sese );\r
if( s == null ) {\r
return;\r
}\r
\r
- trueSet.removeAll( s ); \r
+ trueSet.removeAll( s );\r
sese2vst.remove( sese );\r
+\r
+ Iterator<VariableSourceToken> itr = s.iterator();\r
+ while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+ remove( vst );\r
+ }\r
}\r
\r
public void remove( TempDescriptor var ) {\r
\r
trueSet.removeAll( s ); \r
var2vst.remove( var );\r
+\r
+ Iterator<VariableSourceToken> itr = s.iterator();\r
+ while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+ remove( vst );\r
+ }\r
}\r
\r
public void remove( FlatSESEEnterNode sese,\r
\r
trueSet.removeAll( s );\r
sv2vst.remove( key );\r
- }\r
\r
- public void remove( VariableSourceToken vst ) {\r
- trueSet.remove( vst );\r
+ Iterator<VariableSourceToken> itr = s.iterator();\r
+ while( itr.hasNext() ) {\r
+ VariableSourceToken vst = itr.next();\r
+ remove( vst );\r
+ }\r
}\r
\r
\r
+\r
// return a new table based on this one and\r
// age tokens with respect to SESE curr, where\r
- // any child becomes curr with age 0, and any\r
- // curr tokens increase age by 1\r
+ // any curr tokens increase age by 1\r
public VarSrcTokTable age( FlatSESEEnterNode curr ) {\r
\r
- VarSrcTokTable out = new VarSrcTokTable();\r
+ // create a table to modify as a copy of this\r
+ VarSrcTokTable out = new VarSrcTokTable( this );\r
\r
Iterator<VariableSourceToken> itr = trueSet.iterator();\r
while( itr.hasNext() ) {\r
VariableSourceToken vst = itr.next();\r
+\r
if( vst.getSESE().equals( curr ) ) {\r
+\r
Integer newAge = vst.getAge()+1;\r
if( newAge > MAX_AGE ) {\r
newAge = MAX_AGE;\r
}\r
+\r
+ out.remove( vst );\r
+\r
out.add( new VariableSourceToken( vst.getVarLive(), \r
curr, \r
newAge,\r
Iterator<FlatSESEEnterNode> childItr = curr.getChildren().iterator();\r
if( childItr.hasNext() ) {\r
FlatSESEEnterNode child = childItr.next();\r
-\r
+ \r
Iterator<VariableSourceToken> vstItr = get( child ).iterator();\r
while( vstItr.hasNext() ) {\r
VariableSourceToken vst = vstItr.next();\r
+\r
out.remove( vst );\r
+\r
out.add( new VariableSourceToken( vst.getVarLive(),\r
curr,\r
new Integer( 0 ),\r
vst.getVarLive() ) );\r
}\r
}\r
-\r
+ \r
return out; \r
} \r
\r
out.remove_A_if_B( child, curr );\r
}\r
}\r
-\r
+ \r
return out; \r
}\r
-\r
+ \r
// if B is also a source for some variable, remove all entries\r
// of A as a source for that variable\r
protected void remove_A_if_B( FlatSESEEnterNode a, FlatSESEEnterNode b ) {\r
}\r
\r
\r
- public Set<VariableSourceToken> getStallSet( FlatSESEEnterNode curr/*,\r
- TempDescriptor varLive*/ ) {\r
+ public Set<VariableSourceToken> getStallSet( FlatSESEEnterNode curr/*, TempDescriptor varLive*/ ) {\r
+\r
\r
Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();\r
\r
}\r
\r
\r
+ // use as an aid for debugging, where true-set is checked\r
+ // against the alternate mappings: assert that nothing is\r
+ // missing or extra in the alternates\r
+ public void assertConsistency() {\r
+\r
+ Iterator itr; \r
+ Set s;\r
+\r
+ Set<VariableSourceToken> trueSetByAlts = new HashSet<VariableSourceToken>();\r
+\r
+ itr = sese2vst.entrySet().iterator();\r
+ while( itr.hasNext() ) {\r
+ Map.Entry me = (Map.Entry) itr.next();\r
+ FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();\r
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue(); \r
+ assert s1 != null;\r
+ \r
+ // the trueSet should have all entries in s1\r
+ assert trueSet.containsAll( s1 );\r
+\r
+ // s1 should not have anything that doesn't appear in truese\r
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();\r
+ sInt.removeAll( trueSet );\r
+\r
+ assert sInt.isEmpty();\r
+\r
+ // add s1 to a running union--at the end check if trueSet has extra\r
+ trueSetByAlts.addAll( s1 );\r
+ }\r
+\r
+ // make sure trueSet isn't too big\r
+ assert trueSetByAlts.containsAll( trueSet );\r
+ }\r
+\r
+\r
public boolean equals( Object o ) {\r
if( o == null ) {\r
return false;\r
}\r
\r
public String toString() {\r
+ return "trueSet ="+trueSet.toString();\r
+ }\r
+\r
+ public String toStringVerbose() {\r
return "trueSet ="+trueSet.toString()+"\n"+\r
"sese2vst="+sese2vst.toString()+"\n"+\r
"var2vst ="+var2vst.toString()+"\n"+\r