optimizations to IntPairMap.java
[sbp.git] / src / edu / berkeley / sbp / util / TopologicalBag.java
index eb71cdc..28166fb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
 
 package edu.berkeley.sbp.util;
 import edu.berkeley.sbp.util.*;
@@ -14,7 +14,7 @@ import java.lang.ref.*;
 //
 
 /** a mapping from topologies over <tt>K</tt> to <i>sets of</i> values of type <tt>V</tt> */
-public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<K,V> {
+public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<K,V>, Serializable {
 
     // CRUCIAL INVARIANT: keys in this hashmap MUST be disjoint or the universe will implode
     private final HashMap<Topology<K>,HashSet<V>> h = new HashMap<Topology<K>,HashSet<V>>();
@@ -103,11 +103,11 @@ public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<
     private HashMap<K,Iterable<V>> cache = new HashMap<K,Iterable<V>>();
     public Iterable<V> getAll(Topology<K> k) { return h.get(k); }
 
-    public <B> void invoke(K k, Invokable<V,B> ivbc, B b) {
+    public <B,C> void invoke(K k, Invokable<V,B,C> ivbc, B b, C c) {
         for(Topology<K> t : h.keySet())
             if (t.contains(k))
                 for(V v : h.get(t))
-                    ivbc.invoke(v, b);
+                    ivbc.invoke(v, b, c);
     }
 
     public Iterable<V> get(K k) {
@@ -165,13 +165,13 @@ public class TopologicalBag<K,V> implements MapBag<Topology<K>,V>, VisitableMap<
                         return true;
                 return false;
             }
-            public <B> void invoke(K k, Invokable<V,B> ivbc, B b) {
+            public <B,C> void invoke(K k, Invokable<V,B,C> ivbc, B b, C c) {
                 int asint = f.invoke(k);
                 for(int i=0; i<size; i++) {
                     if (min[i] <= asint && max[i] >= asint) {
                         Object[] arr = v[i];
                         for(int j=0; j<arr.length; j++)
-                            ivbc.invoke((V)arr[j], b);
+                            ivbc.invoke((V)arr[j], b, c);
                     }
                 }
             }