if (!routes.containsKey(hops[i])) routes.put(hops[i], new HashMap()); HashMap prevs = (HashMap)routes.get(hops[i]); if (!prevs.containsKey(hops[i-1])) prevs.put(hops[i-1], new HashSet()); HashSet nexts = (HashSet)prevs.get(hops[i-1]); nexts.add(hops[i+1]);
if (prev.containsKey(hops[i])) if (prev.get(hops[i]) != hops[i-1]) Utils.fail("More than one previous tile for a single data item"); prev.put(hops[i], hops[i-1]); if (!next.containsKey(hops[i])) next.put(hops[i], new HashSet()); ((HashSet)next.get(hops[i])).add(hops[i+1]);
    private void generateSwitchCode(FlatNode fire, List dests)     {	//keeps the next hop for the sends	HashSet sends = new HashSet();	//keeps routes for all of the intermediate hops	//this hashset points to a hashset 	//the secode hash map is indexed by the sources of 	//the route instructions for the tile	//the second hashmap points to a hashset	//of all the dest for a given source	HashMap routes = new HashMap();       	//maps receivers to their previous hop	HashMap receives = new HashMap();			//fill the maps	ListIterator destsIt = dests.listIterator();	while (destsIt.hasNext()) {	    FlatNode dest = (FlatNode)destsIt.next();	    Coordinate[] hops = 		(Coordinate[])Router.getRoute(fire, dest).toArray(new Coordinate[0]);	    //add each route to the maps	    sends.add(hops[1]);	    //add the intermediate routes	    for (int i = 1; i < hops.length -1; i++) {		if (!routes.containsKey(hops[i]))		    routes.put(hops[i], new HashMap());		HashMap prevs = (HashMap)routes.get(hops[i]);		if (!prevs.containsKey(hops[i-1]))		    prevs.put(hops[i-1], new HashSet());		HashSet nexts = (HashSet)prevs.get(hops[i-1]);		nexts.add(hops[i+1]);	    }	    //add the receive	    receives.put(hops[hops.length-1], hops[hops.length - 2]);	}	//now generate the send, routes, and receives	addSends(fire, sends);	addRoutes(routes);	addReceives(receives);    }