X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FTopologicalBag.java;h=28166fb561fd66d4a01db4506b8e2e95ddaf1d84;hp=9a18eef7fa98eda82d0bc51d6b33b8732748403b;hb=f069d11a0bc59d63b078df8a4aa488498c4e9cc2;hpb=3eb9fa560dee4f8c3b3af0460ff850d755676d81 diff --git a/src/edu/berkeley/sbp/util/TopologicalBag.java b/src/edu/berkeley/sbp/util/TopologicalBag.java index 9a18eef..28166fb 100644 --- a/src/edu/berkeley/sbp/util/TopologicalBag.java +++ b/src/edu/berkeley/sbp/util/TopologicalBag.java @@ -1,3 +1,5 @@ +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp.util; import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.*; @@ -12,7 +14,7 @@ import java.lang.ref.*; // /** a mapping from topologies over K to sets of values of type V */ -public class TopologicalBag implements MapBag,V>, VisitableMap { +public class TopologicalBag implements MapBag,V>, VisitableMap, Serializable { // CRUCIAL INVARIANT: keys in this hashmap MUST be disjoint or the universe will implode private final HashMap,HashSet> h = new HashMap,HashSet>(); @@ -135,7 +137,7 @@ public class TopologicalBag implements MapBag,V>, VisitableMap< } } - public VisitableMap optimize() { + public VisitableMap optimize(final Functor f) { ArrayList min_ = new ArrayList(); ArrayList max_ = new ArrayList(); ArrayList v_ = new ArrayList(); @@ -157,16 +159,14 @@ public class TopologicalBag implements MapBag,V>, VisitableMap< final Object[][] v = new Object[size][]; v_.toArray(v); return new VisitableMap() { public boolean contains(K k) { - IntegerMappable im = (IntegerMappable)k; - int asint = im.toInt(); + int asint = f.invoke(k); for(int i=0; i= asint && v[i].length > 0) return true; return false; } public void invoke(K k, Invokable ivbc, B b, C c) { - IntegerMappable im = (IntegerMappable)k; - int asint = im.toInt(); + int asint = f.invoke(k); for(int i=0; i= asint) { Object[] arr = v[i];