changes + add two more benchmarks without annotations
[IRC.git] / Robust / src / Util / MultiViewMap.java
index aad5f0bbb7c5b8d5ff444319265a46343e1176a3..4ce0f9d343992d90313574838f4c81f2c57772d1 100644 (file)
@@ -32,6 +32,12 @@ public class MultiViewMap<T> {
   private boolean checkTypes;\r
   private boolean checkConsistency;\r
 \r
+\r
+  // for MultiViewMaps that don't need to use the value,\r
+  // template on type Object and map every key to this dummy\r
+  public static Object dummyValue = new Integer( -12345 );\r
+\r
+\r
   //  If the entire contents of this map are fullKey -> value:\r
   //    <a,b> -> 1\r
   //    <c,b> -> 2\r
@@ -73,10 +79,15 @@ public class MultiViewMap<T> {
   }\r
 \r
 \r
-  public int size() {\r
-    return fullKey2value.size();\r
+  public MultiViewMap<T> clone( MultiViewMapBuilder<T> builder ) {\r
+    MultiViewMap<T> out = builder.build();\r
+    for( Map.Entry<MultiKey, T> entry : this.get().entrySet() ) {\r
+      out.put( entry.getKey(), entry.getValue() );\r
+    }\r
+    return out;\r
   }\r
 \r
+\r
   public boolean equals( Object o ) {\r
     if( this == o ) {\r
       return true;\r
@@ -111,6 +122,16 @@ public class MultiViewMap<T> {
   }\r
 \r
 \r
+  public int size() {\r
+    return fullKey2value.size();\r
+  }\r
+\r
+\r
+  public void clear() {\r
+    fullKey2value.clear();\r
+    view2partialKey2fullKeys.clear();\r
+  }\r
+\r
  \r
   public void put( MultiKey fullKey, T value ) {\r
     assert( typesMatch( fullKey ) );\r
@@ -126,6 +147,13 @@ public class MultiViewMap<T> {
   }\r
 \r
 \r
+  public Map<MultiKey, T> get() {\r
+    Map<MultiKey, T> fullKey2valueALL = new HashMap<MultiKey, T>();\r
+    fullKey2valueALL.putAll( fullKey2value );\r
+    return fullKey2valueALL;\r
+  }\r
+\r
+\r
   public Map<MultiKey, T> get( final BitSet view, MultiKey partialKey ) {\r
     checkView( view );\r
 \r
@@ -193,6 +221,14 @@ public class MultiViewMap<T> {
     Set<MultiKey> getFullKeys( BitSet   view,\r
                                MultiKey partialKey ) {\r
 \r
+    if( view.equals( fullView ) ) {\r
+      Set<MultiKey> fullKeys = new HashSet<MultiKey>();\r
+      if( fullKey2value.containsKey( partialKey ) ) {\r
+        fullKeys.add( partialKey );\r
+      }\r
+      return fullKeys;\r
+    }\r
+\r
     Map<MultiKey, Set<MultiKey>> partialKey2fullKeys =\r
       getPartialKey2fullKeys( view );\r
     return getFullKeys( partialKey2fullKeys, partialKey );\r
@@ -320,4 +356,20 @@ public class MultiViewMap<T> {
 \r
     return true;\r
   }\r
+\r
+  public String toString() {\r
+    return toString( 0 );\r
+  }\r
+\r
+  public String toString( int indent ) {\r
+    StringBuilder s = new StringBuilder();\r
+    \r
+    for( MultiKey key : fullKey2value.keySet() ) {\r
+      for( int i = 0; i < indent; ++i ) {\r
+        s.append( ' ' );\r
+      }\r
+      s.append( key+" -> "+fullKey2value.get( key )+"\n" );\r
+    }\r
+    return s.toString();\r
+  }\r
 }\r