X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=cff543d699845a77aa71ee30ec05570fb724472f;hp=1adb8e445ee2dfb192f5a242b0a619bac940383e;hb=c366dacc334fe2e35835164f5a37d3eebb2ca6d5;hpb=526da96dd06e152d194ec92c9ef9df6085a1251b diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 1adb8e4..cff543d 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -24,7 +24,8 @@ class GSS { HashSet tail = new HashSet(); /** corresponds to a positions between tokens the input stream; same as Tomita's U_i's */ - public class Phase implements Invokable { + public class Phase implements Invokable, IntegerMappable { + public int toInt() { return pos+1; } /** the token immediately after this phase */ public final Token token; @@ -38,7 +39,7 @@ class GSS { public Forest.Ref finalResult; /** all nodes, keyed by the value returned by code() */ - /*private*/ HashMap hash; /* ALLOC */ + /*private*/ IntPairMap hash; /* ALLOC */ /** the number of nodes in this phase */ private int numNodes; @@ -69,7 +70,7 @@ class GSS { tail.clear(); waiting.clear(); performed.clear(); - hash = new HashMap(); + hash = new IntPairMap(); good = false; closed = false; numNodes = 0; @@ -131,7 +132,10 @@ class GSS { ret.append("\n "); ret.append(message); HashMap> errors = new HashMap>(); - for(Node n : hash.values()) complain(n, errors, false); + for(Node n : hash.values()) { + //System.out.println(n.state); + complain(n, errors, false); + } for(String s : errors.keySet()) { ret.append(" while parsing " + yellow(s)); HashSet hs = errors.get(s); @@ -168,7 +172,7 @@ class GSS { * @param start the earliest part of the input contributing to this node (used to make merging decisions) */ public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction) { - Node p = hash.get(code(state, parent==null?null:parent.phase())); + Node p = hash.get(state, parent==null?null:parent.phase()); if (p != null) return newNode2(p, parent, pending, state, fromEmptyReduction); else return newNode3(parent, pending, state, fromEmptyReduction); } @@ -269,9 +273,8 @@ class GSS { reducing = true; if (reducing_list==null || reducing_list.length < hash.size()) reducing_list = new Phase.Node[hash.size() * 4]; - Collection hv = hash.values(); - hv.toArray(reducing_list); - int num = hv.size(); + hash.toArray(reducing_list); + int num = hash.size(); for(int i=0; inext */ @@ -304,7 +311,6 @@ class GSS { Forest res = null; boolean ok = false; for(Phase.Node n : hash.values()) { - //if (n.holder().empty() && pos>0) continue; if (token == null && n.state.isAccepting()) { if (finalResult==null) finalResult = new Forest.Ref(); finalResult.merge(n.holder); @@ -398,11 +404,10 @@ class GSS { this.fe = fe; this.state = state; this.holder().merge(pending); - //if (holder().empty()) throw new Error(holder()+""); Phase start = parent==null ? null : parent.phase(); if (parent != null) parents().add(parent, true); - if (Phase.this.hash.get(code(state, start)) != null) throw new Error("severe problem!"); - Phase.this.hash.put(code(state, start), this); + if (Phase.this.hash.get(state, start) != null) throw new Error("severe problem!"); + Phase.this.hash.put(state, start, this); Phase.this.numNodes++; } } @@ -415,9 +420,4 @@ class GSS { if (a==null || b==null) return false; return a.equals(b); } - - /** this is something of a hack right now */ - private static long code(State state, Phase start) { - return (((long)state.idx) << 32) | (start==null ? 0 : (start.pos+1)); - } }