--- /dev/null
+package edu.berkeley.fleet.ir;
+import java.util.*;
+import java.net.*;
+import edu.berkeley.fleet.two.*;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction.*;
+import edu.berkeley.fleet.api.Instruction.Set;
+import edu.berkeley.fleet.api.Instruction.Set.*;
+import static edu.berkeley.fleet.util.BitManipulations.*;
+
+public class ShipPool implements Iterable<Ship> {
+
+ public final Fleet fleet;
+
+ public ShipPool(Fleet fleet) { this.fleet = fleet; }
+
+ private HashSet<Ship> allocatedShips = new HashSet<Ship>();
+
+ public Iterator<Ship> iterator() { return allocatedShips.iterator(); }
+
+ public Ship allocateShip(String name) {
+ for(int i=0; ; i++) {
+ Ship ship = fleet.getShip(name, i);
+ if (ship==null)
+ throw new RuntimeException("no more ships of type " + name);
+ if (allocatedShips.contains(ship)) continue;
+ allocatedShips.add(ship);
+ return ship;
+ }
+ }
+}