tentative checkpoint
[sbp.git] / src / edu / berkeley / sbp / GSS.java
index 80fbd5c..11904d8 100644 (file)
@@ -299,18 +299,30 @@ class GSS {
 
             /** which Phase this Node belongs to (node that Node is also a non-static inner class of Phase) */
             public  Phase phase() { return Phase.this; }
 
             /** which Phase this Node belongs to (node that Node is also a non-static inner class of Phase) */
             public  Phase phase() { return Phase.this; }
-            //private Forest pending() { return !Phase.this.closed ? holder : holder.resolve(); }
-            private HashMap<Node,Forest> resultMap = new HashMap<Node,Forest>();
+            //private HashMap<Node,Forest> resultMap = new HashMap<Node,Forest>();
+
+            private HashSet<Forest.Ref> resultMap = new HashSet<Forest.Ref>();
             public void merge(Node parent, Forest result) {
             public void merge(Node parent, Forest result) {
-                //holder.merge(result);
+                for(Forest.Ref f : results()) {
+                    if (f.parents.contains(parent) && f.parents.size()==1) {
+                        f.merge(result);
+                        return;
+                    }
+                }
+                Forest.Ref f = new Forest.Ref();
+                f.parents.add(parent);
+                f.merge(result);
+                resultMap.add(f);
+                set.add(parent, true);
+                /*
                 Forest.Ref f = (Forest.Ref)resultMap.get(parent);
                 if (f==null) { f = new Forest.Ref(); resultMap.put(parent, f); }
                 f.merge(result);
                 set.add(parent, true);
                 Forest.Ref f = (Forest.Ref)resultMap.get(parent);
                 if (f==null) { f = new Forest.Ref(); resultMap.put(parent, f); }
                 f.merge(result);
                 set.add(parent, true);
+                */
             }
             }
-            //public Iterable<Node> childrenFor(Forest result) { return resultMap.getAll(result); }
-            public Iterable<Forest> results() { return resultMap.values(); }
-            private Forest pending(Node n) {
+            public Iterable<Forest.Ref> results() { return resultMap; }
+            //private Forest pending(Node n) {
                 //return !Phase.this.closed ? holder : holder.resolve();
                 /*
                 for(Forest f : resultMap)
                 //return !Phase.this.closed ? holder : holder.resolve();
                 /*
                 for(Forest f : resultMap)
@@ -318,8 +330,10 @@ class GSS {
                         return f;
                 return null;
                 */
                         return f;
                 return null;
                 */
+            /*
                 return resultMap.get(n);
             }
                 return resultMap.get(n);
             }
+            */
             public  FastSet<Node> parents() { return set; }
 
             public void performReductions() {
             public  FastSet<Node> parents() { return set; }
 
             public void performReductions() {
@@ -344,12 +358,12 @@ class GSS {
                     if (n==null) return;
                     Forest[] holder = new Forest[r.pos];
                     if (r.pos==0) n.finish(r, r.zero(), n.phase(), holder);
                     if (n==null) return;
                     Forest[] holder = new Forest[r.pos];
                     if (r.pos==0) n.finish(r, r.zero(), n.phase(), holder);
-                    else          n.reduce(r, r.pos-1,  n.phase(), holder, null, n.pending(n));
+                    else          n.reduce(r, r.pos-1,  n.phase(), holder, null, null);
                 } else {
                     Forest[] holder = new Forest[r.pos];
                     if (r.pos<=0) throw new Error("called wrong form of reduce()");
                     int pos = r.pos-1;
                 } else {
                     Forest[] holder = new Forest[r.pos];
                     if (r.pos<=0) throw new Error("called wrong form of reduce()");
                     int pos = r.pos-1;
-                    n.reduce(r, pos, n.phase(), holder, n2, n.pending(n));
+                    n.reduce(r, pos, n.phase(), holder, n2, null);
                 }
             }
 
                 }
             }
 
@@ -371,16 +385,20 @@ class GSS {
                     //        since the same reduction can appear in more than one state.
 
                     if (only != null)  {
                     //        since the same reduction can appear in more than one state.
 
                     if (only != null)  {
-                        holder[pos] = pending(only);
-                        System.arraycopy(holder, 0, r.holder, 0, holder.length);
-                        for(int i=0; i<r.pos; i++) if (r.holder[i]==null) throw new Error("realbad");
-                        Forest rex = null;
-                        if (r.pos==1)  rex = singularReductions.get(pending, r);
-                        if (rex==null) {
-                            rex = r.rewrite(phase().getLocation());
-                            if (r.pos==1) singularReductions.put(pending, r, rex);
-                        }
-                        only.finish(r, rex, target, holder);
+                        for(Forest result : results())
+                            for(Node child : ((Forest.Ref<?>)result).parents) {
+                                if (child!=only) continue;
+                                pending = holder[pos] = result;
+                                System.arraycopy(holder, 0, r.holder, 0, holder.length);
+                                for(int i=0; i<r.pos; i++) if (r.holder[i]==null) throw new Error("realbad");
+                                Forest rex = null;
+                                if (r.pos==1)  rex = singularReductions.get(pending, r);
+                                if (rex==null) {
+                                    rex = r.rewrite(phase().getLocation());
+                                    if (r.pos==1) singularReductions.put(pending, r, rex);
+                                }
+                                only.finish(r, rex, target, holder);
+                            }
                     } else {
                         for(Forest result : results()) {
                             pending = holder[pos] = result;
                     } else {
                         for(Forest result : results()) {
                             pending = holder[pos] = result;
@@ -392,21 +410,24 @@ class GSS {
                                 rex = r.rewrite(phase().getLocation());
                                 if (r.pos==1) singularReductions.put(pending, r, rex);
                             }
                                 rex = r.rewrite(phase().getLocation());
                                 if (r.pos==1) singularReductions.put(pending, r, rex);
                             }
-                            for(Node child : parents()) {
-                                if (pending(child)==result)
-                                    child.finish(r, rex, target, holder);
-                            }
+                            for(Node child : ((Forest.Ref<?>)result).parents)
+                                child.finish(r, rex, target, holder);
                         }
                     }
                 } else {
                     if (only != null)  {
                         }
                     }
                 } else {
                     if (only != null)  {
-                        holder[pos] = pending(only);
-                        only.reduce(r, pos-1, target, holder, null, only.pending(only));
+                        for(Forest result : results())
+                            for(Node child : ((Forest.Ref<?>)result).parents) {
+                                if (child!=only) continue;
+                                holder[pos] = result;
+                                only.reduce(r, pos-1, target, holder, null, null);
+                            }
                     } else {
                     } else {
-                        for(Node child : this.parents()) {
-                            holder[pos] = pending(child);
-                            child.reduce(r, pos-1, target, holder, null, child.pending(child));
-                        }
+                        for(Forest result : results())
+                            for(Node child : ((Forest.Ref<?>)result).parents) {
+                                holder[pos] = result;
+                                child.reduce(r, pos-1, target, holder, null, null);
+                            }
                     }
                 }
                 holder[pos] = old;
                     }
                 }
                 holder[pos] = old;