X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=0718a109ab5406646aceef72a5be0f974b9d378a;hb=60a01254256be2e3b4be2edb66bd84e72de5f1c9;hp=80fbd5c4655f28e7e0e2aad060b02975fe09ddca;hpb=e5cfb136bf7fd1352eff1bd87a458aa4ff748537;p=sbp.git diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 80fbd5c..0718a10 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); } } @@ -362,53 +376,31 @@ class GSS { */ public void reduce(Position r, int pos, Phase target, Forest[] holder, Node only, Forest pending) { Forest old = holder[pos]; - holder[pos] = pending; - if (pos==0) { - - // FIXME: I'm unsure about this -- basically we want to deal with the case where - // there are two nodes, each of whose Ref points to the same Forest instance. - // Some node in the next phase has both of these as parents. This might happen - // 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 (only != null && child!=only) continue; + pending = holder[pos] = result; + if (pos==0) { System.arraycopy(holder, 0, r.holder, 0, holder.length); for(int i=0; i