checkpoint
authoradam <adam@megacz.com>
Sun, 16 Jul 2006 07:04:41 +0000 (03:04 -0400)
committeradam <adam@megacz.com>
Sun, 16 Jul 2006 07:04:41 +0000 (03:04 -0400)
darcs-hash:20060716070441-5007d-c0f6d2afb9fec6558813fdfb6ad433755f17e19e.gz

src/edu/berkeley/sbp/Forest.java

index 65a8095..3795c9a 100644 (file)
@@ -127,6 +127,11 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
 
         public Many() { }
 
+        public Iterator<One<T>> iterator() {
+            touched();
+            return (Iterator<One<T>>)hp.iterator();    // FIXME: fastset's iterator is not safe!
+        }
+
         public Tree<T> expand1() throws Ambiguous {
             touched();
             if (hp.size() > 1) {
@@ -153,7 +158,14 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
         }
 
         private void touched() {
+            if (touched) return;
             touched = true;
+            FastSet<Forest<T>> f2 = new FastSet<Forest<T>>();
+            for(Forest f : hp)
+                if (f instanceof Forest.One) f2.add(f);
+                else for(Forest ff : ((Forest.Many)f))
+                    f2.add(ff);
+            hp = f2;
         }
         public boolean contains(Forest f) {
             touched();