X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FStateNode.java;h=4b7834e0ffe66e1dfdffbbd7b1c6c21bca202c40;hp=f54e65f5b68dd4c8081d7cd7606e3cc4287bf8bb;hb=c404939a6dfed4dcfdca5ede08db99b3e5ef0c91;hpb=5ac63262248a11cc6412e145794321110327405e diff --git a/src/edu/berkeley/sbp/StateNode.java b/src/edu/berkeley/sbp/StateNode.java index f54e65f..4b7834e 100644 --- a/src/edu/berkeley/sbp/StateNode.java +++ b/src/edu/berkeley/sbp/StateNode.java @@ -12,13 +12,13 @@ import java.lang.reflect.*; /** a node in the GSS */ final class StateNode - extends Node + extends Node implements Invokable, Iterable { /** which GSS.Phase this StateNode belongs to */ public GSS.Phase phase() { return phase; } - public Iterator iterator() { return results.iterator(); } + public Iterator iterator() { return predecessors.iterator(); } public Parser.Table.State state() { return state; } boolean destroyed = false; @@ -34,7 +34,7 @@ final class StateNode else for(ResultNode r : successors) if (state.doomed) { if (r.usedByAnyNode()) { dead = false; break; } } else { if (r.usedByNonDoomedNode()) { dead = false; break; } } - dead |= results.size()==0; + dead |= predecessors.size()==0; if (!dead) return; destroyed = true; if (phase() != null && phase().hash != null) @@ -45,13 +45,13 @@ final class StateNode r.removePred(this); break; } - while(results.size()>0) - for(ResultNode r : results) { - results.remove(r); + while(predecessors.size()>0) + for(ResultNode r : predecessors) { + predecessors.remove(r); r.removeSucc(this); break; } - results = null; + predecessors = null; successors = null; } @@ -61,10 +61,6 @@ final class StateNode private final GSS.Phase predPhase; private final Parser.Table.State state; private boolean fromEmptyReduction; - private FastSet results = new FastSet(); - private FastSet successors = new FastSet(); - //private HashSet results = new HashSet(); - //private HashSet successors = new HashSet(); public final void invoke(Pos r, ResultNode only, Object o) { boolean emptyProductions = only==null; @@ -77,7 +73,7 @@ final class StateNode } private void reduce(Pos r, int pos, GSS.Phase target, ResultNode only) { - for(ResultNode res : results) + for(ResultNode res : predecessors) if (only == null || res == only) for(StateNode pred : res.getPreds()) reduce2(r, pos, target, pred, res.getForest()); @@ -106,7 +102,7 @@ final class StateNode this.predPhase = pred.phase(); phase.hash.put(state, pred.phase(), this); - results.add(pred); + predecessors.add(pred); pred.addSucc(this); if (!fromEmptyReduction) state.invokeReductions(phase().getToken(), this, pred); @@ -114,27 +110,27 @@ final class StateNode state.invokeEpsilonReductions(phase().token, this); } - // Add/Remove Successors/Results ////////////////////////////////////////////////////////////////////////////// + // Add/Remove Successors/Predecessors ////////////////////////////////////////////////////////////////////////////// public void removeSucc(ResultNode succ) { successors.remove(succ); check(); } public void removeResult(ResultNode result) { - results.remove(result); + predecessors.remove(result); check(); } public void addSucc(ResultNode succ) { successors.add(succ); } public void addResult(Forest f, Pos reduction, StateNode pred) { - for(ResultNode r : results) + for(ResultNode r : predecessors) if (r.predecessorsContains(pred)) { r.merge(f); return; } ResultNode result = new ResultNode(f, reduction, pred); - results.add(result); + predecessors.add(result); result.addSucc(this); if (!this.fromEmptyReduction) state.invokeReductions(phase().getToken(), this, result); }