checkpoint
authoradam <adam@megacz.com>
Sun, 22 Jan 2006 09:18:51 +0000 (04:18 -0500)
committeradam <adam@megacz.com>
Sun, 22 Jan 2006 09:18:51 +0000 (04:18 -0500)
darcs-hash:20060122091851-5007d-5ee6389a77a8d5e7248d3534a28456335d957563.gz

src/edu/berkeley/sbp/Forest.java

index 748c435..df7a3ea 100644 (file)
@@ -7,7 +7,7 @@ import java.util.*;
 import java.lang.reflect.*;
 
 /** an efficient representation of a collection of trees (Tomita's shared packed parse forest) */
-public abstract class Forest<T> /*extends PrintableTree<Forest.Body<T>>*/ implements Visitable<Forest.Body<T>>, Iterable<Forest.Body<T>>  {
+public abstract class Forest<T> /*extends PrintableTree<Forest.Body<T>>*/ implements Visitable<Forest.Body<T>> {
 
     public abstract <B,C> void invoke(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c);
     private static class TreeMaker<T> extends HashSet<Tree<T>> implements Invokable<Forest.Body<T>,Boolean,Integer> {
@@ -49,7 +49,7 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.Body<T>>*/ implem
         TreeMaker<T> expand(boolean toss, int i, TreeMaker<T> h);
     }
 
-    protected static class MyBody<T> extends Forest<T> implements Body<T> /* extends PrintableTree<Forest<T>> implements */,Iterable<Forest.Body<T>> {
+    protected static class MyBody<T> extends Forest<T> implements Body<T> /* extends PrintableTree<Forest<T>> implements */ {
 
         public <B,C> void invoke(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
             ivbc.invoke(this, b, c);
@@ -112,30 +112,13 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.Body<T>>*/ implem
      *  forests to be viewed as a forest at some later date; once
      *  viewed, it becomes immutable
      */
-    static class Ref<T> extends Forest<T> implements Iterable<Forest.Body<T>> {
+    static class Ref<T> extends Forest<T> {
         private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
         public Ref() { }
         public void merge(Forest p) { if (p!=this) hp.add(p, true); }
         public <B,C> void invoke(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
-            for(Forest.Body<T> bod : this)
-                ivbc.invoke(bod, b, c);
-        }
-        public Iterator<Body<T>> iterator() {
-            final Iterator<Forest<T>> ift = hp==null ? null : hp.iterator();
-            return new Iterator<Body<T>>() {
-                Iterator<Body<T>> ibt = ift==null ? null : ift.hasNext() ? ift.next().iterator() : null;
-                public void remove() { throw new RuntimeException("not supported"); }
-                public boolean hasNext() {
-                    if (ibt==null) return false;
-                    if (ibt.hasNext()) return true;
-                    ibt = ift.hasNext() ? ift.next().iterator() : null;
-                    return hasNext();
-                }
-                public Body<T> next() {
-                    return ibt.next();
-                }
-            };
-
+            if (hp==null) return;
+            for(Forest<T> f : hp) f.invoke(ivbc, b, c);
         }
         public Forest resolve() { return this; }
     }