Fix a minimisation bug, and keep the output smaller
This commit is contained in:
parent
83018bb1f1
commit
f052f7fd8d
|
@ -7,7 +7,7 @@
|
||||||
namespace lxs {
|
namespace lxs {
|
||||||
std::string toDot(const DFA& d)
|
std::string toDot(const DFA& d)
|
||||||
{
|
{
|
||||||
std::string s = "digraph {\nrankdir=LR\nin [shape=point style=invis]";
|
std::string s = "digraph {\nrankdir=LR\nin [shape=point style=invis]\n";
|
||||||
|
|
||||||
for (State state = 0; state < d.numStates; state++)
|
for (State state = 0; state < d.numStates; state++)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ namespace lxs {
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void markReachable(const DFA& d, State s, std::set<State> reachable) {
|
void markReachable(const DFA& d, State s, std::set<State>& reachable) {
|
||||||
if (reachable.count(s) > 0)
|
if (reachable.count(s) > 0)
|
||||||
return;
|
return;
|
||||||
reachable.insert(s);
|
reachable.insert(s);
|
||||||
|
@ -194,7 +194,7 @@ namespace lxs {
|
||||||
/**
|
/**
|
||||||
* Do the actual minimisation, using precomputed distinguishable pairs
|
* Do the actual minimisation, using precomputed distinguishable pairs
|
||||||
*/
|
*/
|
||||||
DFA compress(const DFA& d, std::set<State> reachables, Distinguishables& dist) {
|
DFA compress(const DFA& d, std::set<State>& reachables, Distinguishables& dist) {
|
||||||
DFA min;
|
DFA min;
|
||||||
min.starting = d.starting;
|
min.starting = d.starting;
|
||||||
|
|
||||||
|
@ -244,9 +244,8 @@ namespace lxs {
|
||||||
for (State s = 0; s < d.numStates; s++) {
|
for (State s = 0; s < d.numStates; s++) {
|
||||||
if (done.count(newStates[s]) > 0) continue;
|
if (done.count(newStates[s]) > 0) continue;
|
||||||
done.insert(newStates[s]);
|
done.insert(newStates[s]);
|
||||||
for (int i = 0; i < 256; i++) {
|
for (const auto& p : d.delta.find(s)->second)
|
||||||
min.delta[newStates[s]][(char) i] = newStates[d.delta.find(s)->second.find((char) i)->second];
|
min.delta[newStates[s]][p.first] = newStates[p.second];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return min;
|
return min;
|
||||||
|
|
Loading…
Reference in New Issue