From 0930e2a8843fccbcae339b7337f6c0d0034abf6f Mon Sep 17 00:00:00 2001 From: jjenista Date: Fri, 10 Apr 2009 03:45:24 +0000 Subject: [PATCH] structure for manipulating triples --- Robust/src/Analysis/MLP/VarSrcTokTable.java | 140 +++++++++++++++----- 1 file changed, 104 insertions(+), 36 deletions(-) diff --git a/Robust/src/Analysis/MLP/VarSrcTokTable.java b/Robust/src/Analysis/MLP/VarSrcTokTable.java index 62b385d0..9a22b5b3 100644 --- a/Robust/src/Analysis/MLP/VarSrcTokTable.java +++ b/Robust/src/Analysis/MLP/VarSrcTokTable.java @@ -7,14 +7,22 @@ import java.io.*; public class VarSrcTokTable { - // be able to grab the VariableSourceToken triples from the - // table by the sese, by the variable, or by a key that is - // an sese/variable pair + // the true set represents the set of (sese, variable, age) + // triples that are truly in the table + private HashSet trueSet; + + // these hashtables provide an efficient retreival from the + // true set. Note that a particular triple from the quick + // look up must be checked against the true set--remove ops + // can cause the hashtables to be inconsistent to each other private Hashtable< FlatSESEEnterNode, Set > sese2vst; private Hashtable< TempDescriptor, Set > var2vst; private Hashtable< SVKey, Set > sv2vst; + public VarSrcTokTable() { + trueSet = new HashSet(); + sese2vst = new Hashtable< FlatSESEEnterNode, Set >(); var2vst = new Hashtable< TempDescriptor, Set >(); sv2vst = new Hashtable< SVKey, Set >(); @@ -22,6 +30,8 @@ public class VarSrcTokTable { public void add( VariableSourceToken vst ) { + trueSet.add( vst ); + Set s; s = sese2vst.get( vst.getSESE() ); @@ -52,31 +62,89 @@ public class VarSrcTokTable { Set s = sese2vst.get( sese ); if( s == null ) { s = new HashSet(); + sese2vst.put( sese, s ); } + s.retainAll( trueSet ); return s; } public Set get( TempDescriptor var ) { Set s = var2vst.get( var ); if( s == null ) { - s = new HashSet(); + s = new HashSet(); + var2vst.put( var, s ); } + s.retainAll( trueSet ); return s; } public Set get( SVKey key ) { Set s = sv2vst.get( key ); if( s == null ) { - s = new HashSet(); + s = new HashSet(); + sv2vst.put( key, s ); } + s.retainAll( trueSet ); return s; } public void merge( VarSrcTokTable table ) { - sese2vst.putall( table.sese2vst ); - var2vst.putall( table.var2vst ); - sv2vst.putall( table.sv2vst ); + trueSet.addAll( table.trueSet ); + + Iterator i; + Set s; + + itr = sese2vst.getEntrySet().iterator(); + while( itr.hasNext() ) { + Map.Entry me = (Map.Entry) itr.next(); + FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey(); + Set s1 = (Set) me.getValue(); + Set s2 = table.sese2vst.get( sese ); + + assert s1 != null; + + if( s2 != null ) { + s1.addAll( s2 ); + } + } + s = table.sese2vst.getEntrySet(); + s.retainAll( sese2vst.getEntrySet() ); + sese2vst.putAll( table.sese2vst ); + + itr = var2vst.getEntrySet().iterator(); + while( itr.hasNext() ) { + Map.Entry me = (Map.Entry) itr.next(); + TempDescriptor var = (TempDescriptor) me.getKey(); + Set s1 = (Set) me.getValue(); + Set s2 = table.var2vst.get( var ); + + assert s1 != null; + + if( s2 != null ) { + s1.addAll( s2 ); + } + } + s = table.var2vst.getEntrySet(); + s.retainAll( var2vst.getEntrySet() ); + var2vst.putAll( table.var2vst ); + + itr = sv2vst.getEntrySet().iterator(); + while( itr.hasNext() ) { + Map.Entry me = (Map.Entry) itr.next(); + SVKey key = (SVKey) me.getKey(); + Set s1 = (Set) me.getValue(); + Set s2 = table.sv2vst.get( key ); + + assert s1 != null; + + if( s2 != null ) { + s1.addAll( s2 ); + } + } + s = table.sv2vst.getEntrySet(); + s.retainAll( sv2vst.getEntrySet() ); + sv2vst.putAll( table.sv2vst ); } @@ -85,54 +153,54 @@ public class VarSrcTokTable { if( s == null ) { return; } + + trueSet.removeAll( s ); + sese2vst.remove( sese ); + } - Iterator vstItr = s.iterator(); - while( vstItr.hasNext() ) { - VariableSourceToken vst = vstItr.next(); - - /* - TempDescriptor var = vst.getVar(); - - sv2vst.remove( new SVKey( sese, var ) ); + public void remove( TempDescriptor var ) { + Set s = var2vst.get( var ); + if( s == null ) { + return; + } + + trueSet.removeAll( s ); + var2vst.remove( var ); + } - Set sByVar = var2vst.get( var ); - if( sByVar == null ) { - continue; - } - Iterator byVarItr = sByVar.clone().iterator(); - while( byVarItr.hasNext() ) { - VariableSourceToken vstByVar = byVarItr.next(); + public void remove( FlatSESEEnterNode sese, + TempDescriptor var ) { - - } - */ + SVKey key = new SVKey( sese, var ); + Set s = sv2vst.get( key ); + if( s == null ) { + return; } - + + trueSet.removeAll( s ); sese2vst.remove( sese ); + var2vst .remove( var ); + sv2vst .remove( key ); } - public boolean equals( Object o ) { if( o == null ) { return false; } - if( !(o instanceof VariableSourceToken) ) { + if( !(o instanceof VarSrcTokTable) ) { return false; } - VariableSourceToken vst = (VariableSourceToken) o; - - return var.equals( vst.var ) && - age.equals( vst.age ); + VarSrcTokTable table = (VarSrcTokTable) o; + return trueSet.equals( table.trueSet ); } public int hashCode() { - return (var.hashCode() << 2) ^ age.intValue(); + return trueSet.hashCode(); } - public String toString() { - return "["+var+", "+age+"]"; + return trueSet.toString(); } } -- 2.34.1