public Forest.Ref finalResult;
/** all nodes, keyed by the value returned by code() */
- /*private*/ HashMap<Long,Phase.Node> hash; /* ALLOC */
+ /*private*/ IntPairMap<Phase.Node> hash; /* ALLOC */
/** the number of nodes in this phase */
private int numNodes;
tail.clear();
waiting.clear();
performed.clear();
- hash = new HashMap<Long,Phase.Node>();
+ hash = new IntPairMap<Phase.Node>();
good = false;
closed = false;
numNodes = 0;
* @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);
}
reducing = true;
if (reducing_list==null || reducing_list.length < hash.size())
reducing_list = new Phase.Node[hash.size() * 4];
- Collection<Node> hv = hash.values();
- hv.toArray(reducing_list);
- int num = hv.size();
+ hash.toArray(reducing_list);
+ int num = hash.size();
for(int i=0; i<num; i++) {
Node n = reducing_list[i];
n.queueEmptyReductions();
this.holder().merge(pending);
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++;
}
}
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));
- }
}
}
testcase {
+ input "aabb";
+ output "xbx:{abab:{a b}}";
+
+ x !::= ~[]
+ s ::= x* b x* => xbx
+ b ::= [ab][ab] => abab
+ &~ ( "aa" | "bb" )
+}
+
+testcase {
input "12111211";
output "ac:{{2 1 2 1}}";
//output "a:{{2 1 2 1}}";
q ::= [a-z]++ => "q"
}
-testcase {
-
- input "
-
-
-
- while x>0
- while y>0
- foo()
- bar()
-
-
- while x>0
- while y>0
- foo()
- bar()
-
-
-
-";
- output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}";
-
-indent !::= ww
-outdent !::= " " outdent " "
- | " " (~[]*) "\n"
-
-w !::= " " | "\n" | "\r"
-ws !::= w*
-ww !::= sp*
-sp !::= " "
-any !::= ~[]*
-
-s ::= ws statement ws statement ws => smt
-
-block ::= "\n" indent blockBody
- &~ "\n" outdent ~[\ ] ~[]*
-
-blockBody ::= statement
- > statement ws blockBody => "sbb"
-
-statement ::= call
- | ^"while" expr block /ws
-
-expr ::= ident
- | call
- | expr ^">" expr /ws
- | num
-
-call ::= expr "()" /ws
-
-num ::= [0-9]++
-
-ident ::= [a-z]++ &~ keyword
-keyword ::= "if" | "then" | "else" | "while"
-
-
-
-}
+//testcase {
+//
+// input "
+//
+//
+//
+// while x>0
+// while y>0
+// foo()
+// bar()
+//
+//
+// while x>0
+// while y>0
+// foo()
+// bar()
+//
+//
+//
+//";
+// output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}";
+//
+//indent !::= ww
+//outdent !::= " " outdent " "
+// | " " (~[]*) "\n"
+//
+//w !::= " " | "\n" | "\r"
+//ws !::= w*
+//ww !::= sp*
+//sp !::= " "
+//any !::= ~[]*
+//
+//s ::= ws statement ws statement ws => smt
+//
+//block ::= "\n" indent blockBody
+// &~ "\n" outdent ~[\ ] ~[]*
+//
+//blockBody ::= statement
+// > statement ws blockBody => "sbb"
+//
+//statement ::= call
+// | ^"while" expr block /ws
+//
+//expr ::= ident
+// | call
+// | expr ^">" expr /ws
+// | num
+//
+//call ::= expr "()" /ws
+//
+//num ::= [0-9]++
+//
+//ident ::= [a-z]++ &~ keyword
+//keyword ::= "if" | "then" | "else" | "while"
+//
+//
+//
+//}
+//
\ No newline at end of file