X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=1c8fbc5b6f8290bb0c6540a37fd2925900e7b89a;hp=65a80952e60321c48788a280293d9e28a084b30b;hb=f1dba2b015c3da04fc2fab45604da2e6c9ae0a1d;hpb=297f374e023e781f38f3fb2d6122c951f224380e diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 65a8095..1c8fbc5 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -12,7 +12,6 @@ import java.lang.reflect.*; */ public abstract class Forest implements GraphViz.ToGraphViz { - /** assume that this forest contains exactly one tree and return it; otherwise throw an exception */ public abstract Tree expand1() throws Ambiguous; @@ -24,7 +23,6 @@ public abstract class Forest implements GraphViz.ToGraphViz { return new One(loc, head, children, unwrap); } - // Package-Private ////////////////////////////////////////////////////////////////////////////// abstract void expand(HashSet> ht, HashSet> ignore, Tree bogus); @@ -37,7 +35,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { // One ////////////////////////////////////////////////////////////////////////////// /** A "single" forest with a head and child subforests */ - public static class One extends Forest { + private static class One extends Forest { private final Input.Region location; private final T head; @@ -61,11 +59,11 @@ public abstract class Forest implements GraphViz.ToGraphViz { return new Tree(location, head, ret, unwrap); } - public void gather(HashSet> hf) { + void gather(HashSet> hf) { hf.add(this); for(Forest f : children) f.gather(hf); } - public void expand(HashSet> ht, HashSet> ignore, Tree bogus) { + void expand(HashSet> ht, HashSet> ignore, Tree 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 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 implements GraphViz.ToGraphViz { // Many ////////////////////////////////////////////////////////////////////////////// /** An "ambiguity node"; this is immutable once it has been "looked at" */ - public static class Many extends Forest { + static class Many extends Forest { HashSet parents = new HashSet(); private FastSet> hp = new FastSet>(); @@ -146,14 +144,23 @@ public abstract class Forest implements GraphViz.ToGraphViz { return hp.iterator().next().expand1(); } - public void gather(HashSet> ht) { + void gather(HashSet> ht) { touched(); ht.add(this); for(Forest f : hp) f.gather(ht); } private void touched() { + if (touched) return; touched = true; + /* + FastSet> f2 = new FastSet>(); + 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(); @@ -171,7 +178,7 @@ public abstract class Forest implements GraphViz.ToGraphViz { return true; } - public void expand(HashSet> ht, HashSet> ignore, Tree bogus) { + void expand(HashSet> ht, HashSet> ignore, Tree bogus) { touched(); if (ignore.contains(this)) { ht.add(bogus); return; } for (Forest f : hp) f.expand(ht, ignore, bogus);