X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=0fb10c6cbf3b442a36eb27f61bd4c4c59854cbfe;hb=fdfbcb35985749c03225bdef24ad5e4add42661b;hp=65a80952e60321c48788a280293d9e28a084b30b;hpb=297f374e023e781f38f3fb2d6122c951f224380e;p=sbp.git diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 65a8095..0fb10c6 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -119,7 +119,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 { + public static class Many extends Forest implements Iterable> { HashSet parents = new HashSet(); private FastSet> hp = new FastSet>(); @@ -127,6 +127,11 @@ public abstract class Forest implements GraphViz.ToGraphViz { public Many() { } + public Iterator> iterator() { + touched(); + return (Iterator>)(Object)hp.iterator(); // FIXME: fastset's iterator is not safe! + } + public Tree expand1() throws Ambiguous { touched(); if (hp.size() > 1) { @@ -153,7 +158,14 @@ public abstract class Forest implements GraphViz.ToGraphViz { } 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();