Skip to content
Snippets Groups Projects
Commit 1879523c authored by Jan Trávníček's avatar Jan Trávníček
Browse files

tweak NFA, DFA, IDNPDA determinisation

parent 28a752a4
No related branches found
No related tags found
No related merge requests found
......@@ -27,36 +27,36 @@ automaton::InputDrivenDPDA Determinize::determinize(const automaton::InputDriven
 
// 2
std::deque<automaton::State> todo;
todo.push_back(initialState);
todo.push_back(std::move(initialState));
 
do {
// 3a, c
automaton::State state = todo.front();
automaton::State state = std::move(todo.front());
todo.pop_front();
 
// 3b
for (const auto& input : nfa.getInputAlphabet()) {
for (const alphabet::Symbol& input : nfa.getInputAlphabet()) {
std::set<automaton::State> targetIDPDAStates;
for(const auto& nfaState : recreateNFAStates(state)) {
auto iter = nfa.getTransitions().find(std::make_pair(nfaState, input));
for(automaton::State nfaState : std::make_moveable_set(recreateNFAStates(state))) {
auto iter = nfa.getTransitions().find(std::make_pair(std::move(nfaState), input));
if(iter != nfa.getTransitions().end()) {
targetIDPDAStates.insert(iter->second.begin(), iter->second.end());
}
}
automaton::State dfaState = createDFAState(targetIDPDAStates);
automaton::State dfaState = createDFAState(std::move(targetIDPDAStates));
 
// 4
bool existed = !res.addState(dfaState);
 
// 3b
res.addTransition(state, input, dfaState);
if(!existed) todo.push_back(dfaState);
// 3b
res.addTransition(std::move(state), input, std::move(dfaState));
}
} while(!todo.empty());
 
// 5
for (const auto& dfaState : res.getStates()) {
for (const automaton::State & dfaState : res.getStates()) {
std::set<automaton::State> nfaStates = recreateNFAStates(dfaState);
if(std::any_of(nfaStates.begin(), nfaStates.end(), [&](const automaton::State& nfaState) { return nfa.getFinalStates().count(nfaState); })) {
res.addFinalState(dfaState);
......
......@@ -24,7 +24,7 @@ automaton::DFA Determinize::determinize(const automaton::MultiInitialStateNFA& n
 
// 2
std::deque<automaton::State> todo;
todo.push_back(initialState);
todo.push_back(std::move(initialState));
 
do {
// 3a, c
......@@ -35,7 +35,7 @@ automaton::DFA Determinize::determinize(const automaton::MultiInitialStateNFA& n
for (const alphabet::Symbol& input : nfa.getInputAlphabet()) {
std::set<automaton::State> targetNFAStates;
for(automaton::State nfaState : std::make_moveable_set(recreateNFAStates(state))) {
auto iter = nfa.getTransitions().find(std::make_pair(std::move(nfaState), alphabet::Symbol(input)));
auto iter = nfa.getTransitions().find(std::make_pair(std::move(nfaState), input));
if(iter != nfa.getTransitions().end()) {
targetNFAStates.insert(iter->second.begin(), iter->second.end());
}
......@@ -45,10 +45,10 @@ automaton::DFA Determinize::determinize(const automaton::MultiInitialStateNFA& n
// 4
bool existed = !res.addState(dfaState);
 
// 3b
res.addTransition(state, input, dfaState);
if(!existed) todo.push_back(std::move(dfaState));
// 3b
res.addTransition(std::move(state), input, std::move(dfaState));
}
} while(!todo.empty());
 
......@@ -73,7 +73,7 @@ automaton::DFA Determinize::determinize(const automaton::NFA& nfa) {
 
// 2
std::deque<automaton::State> todo;
todo.push_back(initialState);
todo.push_back(std::move(initialState));
 
do {
// 3a, c
......@@ -84,7 +84,7 @@ automaton::DFA Determinize::determinize(const automaton::NFA& nfa) {
for (const alphabet::Symbol& input : nfa.getInputAlphabet()) {
std::set<automaton::State> targetNFAStates;
for(automaton::State nfaState : std::make_moveable_set(recreateNFAStates(state))) {
auto iter = nfa.getTransitions().find(std::make_pair(std::move(nfaState), alphabet::Symbol(input)));
auto iter = nfa.getTransitions().find(std::make_pair(std::move(nfaState), input));
if(iter != nfa.getTransitions().end()) {
targetNFAStates.insert(iter->second.begin(), iter->second.end());
}
......@@ -94,10 +94,10 @@ automaton::DFA Determinize::determinize(const automaton::NFA& nfa) {
// 4
bool existed = !res.addState(dfaState);
 
// 3b
res.addTransition(state, input, dfaState);
if(!existed) todo.push_back(dfaState);
 
if(!existed) todo.push_back(std::move(dfaState));
// 3b
res.addTransition(std::move(state), input, std::move(dfaState));
}
} while(!todo.empty());
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment