checkpoint
[sbp.git] / src / edu / berkeley / sbp / Forest.java
index 65a8095..1c8fbc5 100644 (file)
@@ -12,7 +12,6 @@ import java.lang.reflect.*;
  */
 public abstract class Forest<T> implements GraphViz.ToGraphViz {
 
-
     /** assume that this forest contains exactly one tree and return it; otherwise throw an exception */
     public abstract Tree<T> expand1() throws Ambiguous;
 
@@ -24,7 +23,6 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
         return new One<T>(loc, head, children, unwrap);
     }
 
-
     // Package-Private //////////////////////////////////////////////////////////////////////////////
 
     abstract void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus);
@@ -37,7 +35,7 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
     // One //////////////////////////////////////////////////////////////////////////////
 
     /** A "single" forest with a head and child subforests */    
-    public static class One<T> extends Forest<T> {
+    private static class One<T> extends Forest<T> {
 
         private final Input.Region      location;
         private final T                 head;
@@ -61,11 +59,11 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
             return new Tree<T>(location, head, ret, unwrap);
         }
 
-        public void gather(HashSet<Forest<T>> hf) {
+        void gather(HashSet<Forest<T>> hf) {
             hf.add(this);
             for(Forest<T> f : children) f.gather(hf);
         }
-        public void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+        void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
             if (ignore.contains(this)) { ht.add(bogus); return; }
             expand(0, new Tree[children.length], ht, ignore, bogus);
         }
@@ -95,7 +93,7 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
             edges(n);
             return n;
         }
-        boolean edges = false;
+        boolean edges = false; // FIXME ??
         public void edges(GraphViz.Node n) {
             if (edges) return;
             edges = true;
@@ -119,7 +117,7 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
     // Many //////////////////////////////////////////////////////////////////////////////
 
     /** An "ambiguity node"; this is immutable once it has been "looked at" */
-    public static class Many<T> extends Forest<T> {
+    static class Many<T> extends Forest<T> {
 
         HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
         private FastSet<Forest<T>> hp = new FastSet<Forest<T>>();
@@ -146,14 +144,23 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
             return hp.iterator().next().expand1();
         }
         
-        public void gather(HashSet<Forest<T>> ht) {
+        void gather(HashSet<Forest<T>> ht) {
             touched();
             ht.add(this);
             for(Forest<T> f : hp) f.gather(ht);
         }
 
         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<T>)f))
+                    f2.add(ff);
+            hp = f2;
+            */
         }
         public boolean contains(Forest f) {
             touched();
@@ -171,7 +178,7 @@ public abstract class Forest<T> implements GraphViz.ToGraphViz {
             return true;
         }
 
-        public void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+        void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
             touched();
             if (ignore.contains(this)) { ht.add(bogus); return; }
             for (Forest<T> f : hp) f.expand(ht, ignore, bogus);