- /**
- * This class represents a partially complete collection of
- * forests to be viewed as a forest at some later date; once
- * viewed, it becomes immutable
- */
- static class Ref<T> extends IterableForest<T> {
- private FastSet<Forest> hp = new FastSet<Forest>();
- private Forest res = null;
- public boolean valid = false;
- public Ref() { }
- public void merge(Forest p) {
- //if (p==null) throw new Error("bad evil bad!");
- if (res != null) throw new Error("already resolved!");
- if (p==null) throw new Error();
- if (p!=this) hp.add(p, true);
- }
- public Iterator<Body<T>> iterator() { return ((IterableForest<T>)resolve()).iterator(); }
- public HashSet<Tree<T>> expand(boolean toss) { return resolve().expand(toss); }
- public boolean valid() { if (valid) return true; resolve(); return valid; }
- public String toString() { return resolve().toString(); }
- public Forest resolve() {
- if (hp==null) return res;
- HashSet<Body> results = null;
- FastSet<Body> nh = new FastSet<Body>();
- for(Forest<?> p : hp)
- for(Body<?> b : (IterableForest<?>)p) {
- if (b.keep() && (b.creator==null || !b.creator.lame)) {
- valid = true;
- b.addTo(nh);
- } else {
- results = new HashSet<Body>();
- }
- }
- if (results != null) {
- for(Forest<?> p : hp)
- for(Body<?> b : (IterableForest<?>)p)
- results.add(b);
- for(Body b : results) {
- if (b.keep() && (b.creator==null || !b.creator.lame)) continue;
- if (b.creator!=null && b.creator.lame) continue;
- if (!b.keep(results)) continue;
- valid = true;
- b.addTo(nh);
+ HashSet<GSS.Phase.Node> parents = new HashSet<GSS.Phase.Node>();
+ private FastSet<Forest<NodeType>> hp = new FastSet<Forest<NodeType>>();
+ private boolean touched = false;
+
+ public Many() { }
+
+ Input.Region getRegion() { return hp.iterator().next().getRegion(); } // all should be identical
+
+ public Tree<NodeType> expand1() throws Ambiguous {
+ touched();
+ if (hp.size() > 1) {
+ HashSet<Forest<NodeType>> hf0 = new HashSet<Forest<NodeType>>();
+ Iterator<Forest<NodeType>> ih = hp.iterator();
+ ih.next().gather(hf0);
+ for(Forest<NodeType> f : hp) {
+ HashSet<Forest<NodeType>> hf1 = new HashSet<Forest<NodeType>>();
+ f.gather(hf1);
+ hf0.retainAll(hf1);