+// 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.*;
//
/** 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>>();
public void putAll(Topology<K> k, Iterable<V> vi) { if (vi!=null) for(V v : vi) put(k, v); }
public void put(Topology<K> t, V v) {
- // XXX hack
- if (t instanceof Atom) t = ((Atom)t).underlying();
for(Topology<K> ht : h.keySet()) {
if (t.disjoint(ht)) continue;
if (t.containsAll(ht) && ht.containsAll(t)) {
private HashMap<K,Iterable<V>> cache = new HashMap<K,Iterable<V>>();
public Iterable<V> getAll(Topology<K> k) { return h.get(k); }
- public <B,C> void invoke(K k, Invokable<V,B,C> ivbc, B b, C c) {
+ public <B> void invoke(K k, Invokable<V,B> ivbc, B b) {
for(Topology<K> t : h.keySet())
if (t.contains(k))
for(V v : h.get(t))
- ivbc.invoke(v, b, c);
+ ivbc.invoke(v, b);
}
public Iterable<V> get(K k) {
return true;
return false;
}
- public <B,C> void invoke(K k, Invokable<V,B,C> ivbc, B b, C c) {
+ public <B> void invoke(K k, Invokable<V,B> ivbc, B b) {
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, c);
+ ivbc.invoke((V)arr[j], b);
}
}
}