X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=11904d8b8eae83fde2fa6cd1f01e318508e63b9b;hp=80fbd5c4655f28e7e0e2aad060b02975fe09ddca;hb=628b3a8eaafdbe8507e841076051bff42aadf5ee;hpb=e5cfb136bf7fd1352eff1bd87a458aa4ff748537 diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 80fbd5c..11904d8 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -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; } - //private Forest pending() { return !Phase.this.closed ? holder : holder.resolve(); } - private HashMap resultMap = new HashMap(); + //private HashMap resultMap = new HashMap(); + + private HashSet resultMap = new HashSet(); 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); + */ } - //public Iterable childrenFor(Forest result) { return resultMap.getAll(result); } - public Iterable results() { return resultMap.values(); } - private Forest pending(Node n) { + public Iterable results() { return resultMap; } + //private Forest pending(Node n) { //return !Phase.this.closed ? holder : holder.resolve(); /* for(Forest f : resultMap) @@ -318,8 +330,10 @@ class GSS { return f; return null; */ + /* return resultMap.get(n); } + */ public FastSet 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); - 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; - 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) { - holder[pos] = pending(only); - System.arraycopy(holder, 0, r.holder, 0, holder.length); - for(int i=0; i)result).parents) { + if (child!=only) continue; + pending = holder[pos] = result; + System.arraycopy(holder, 0, r.holder, 0, holder.length); + for(int i=0; i)result).parents) + child.finish(r, rex, target, holder); } } } 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 { - 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;