X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FTopologicalBag.java;h=259560260e602efd057bfc41fb16f59c57ffaec6;hb=142b31e063c97d2d6dc141a9e687d49b7f2ab826;hp=2a1bb53a0c2fb0ba1001ecd70f1e3a216e02d0fa;hpb=0516ea34996c86664928ef948013b749876b87ec;p=sbp.git
diff --git a/src/edu/berkeley/sbp/util/TopologicalBag.java b/src/edu/berkeley/sbp/util/TopologicalBag.java
index 2a1bb53..2595602 100644
--- a/src/edu/berkeley/sbp/util/TopologicalBag.java
+++ b/src/edu/berkeley/sbp/util/TopologicalBag.java
@@ -12,7 +12,7 @@ import java.lang.ref.*;
//
/** a mapping from topologies over K to sets of values of type V */
-public class TopologicalBag implements MapBag,V> {
+public class TopologicalBag implements MapBag,V>, VisitableMap {
// CRUCIAL INVARIANT: keys in this hashmap MUST be disjoint or the universe will implode
private final HashMap,HashSet> h = new HashMap,HashSet>();
@@ -31,7 +31,7 @@ public class TopologicalBag implements MapBag,V> {
public void put(Topology t, V v) {
for(Topology ht : h.keySet()) {
if (t.disjoint(ht)) continue;
- if (t.equals(ht)) {
+ if (t.containsAll(ht) && ht.containsAll(t)) {
h.get(ht).add(v);
return;
}
@@ -82,7 +82,7 @@ public class TopologicalBag implements MapBag,V> {
return true;
}
- public boolean contains(K k) { return get(k).iterator().hasNext(); }
+ public boolean contains(K k) { return has(k); }
public boolean contains(K k, V v) {
for(Topology t : h.keySet())
@@ -91,8 +91,23 @@ public class TopologicalBag implements MapBag,V> {
return false;
}
+ public boolean has(K k) {
+ for(Topology t : h.keySet())
+ if (t.contains(k) && !h.get(t).isEmpty())
+ return true;
+ return false;
+ }
+
private HashMap> cache = new HashMap>();
public Iterable getAll(Topology k) { return h.get(k); }
+
+ public void invoke(K k, Invokable ivbc, B b, C c) {
+ for(Topology t : h.keySet())
+ if (t.contains(k))
+ for(V v : h.get(t))
+ ivbc.invoke(v, b, c);
+ }
+
public Iterable get(K k) {
Iterable c = cache.get(k);
if (c != null) return c;
@@ -119,5 +134,47 @@ public class TopologicalBag implements MapBag,V> {
return ret;
}
}
+
+ public VisitableMap optimize(final Functor f) {
+ ArrayList min_ = new ArrayList();
+ ArrayList max_ = new ArrayList();
+ ArrayList