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

move semantics in tree automata addTransition

parent 75e7ada6
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
* @param next next state * @param next next state
* @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton
*/ */
bool addTransition ( const std::ranked_symbol < SymbolType, RankType > & current, const std::vector < StateType > & children, const StateType & next ); bool addTransition ( std::ranked_symbol < SymbolType, RankType > current, std::vector < StateType > children, StateType next );
   
/** /**
* Removes transition from the automaton. * Removes transition from the automaton.
...@@ -172,7 +172,7 @@ AutomatonBase* DFTA < SymbolType, RankType, StateType >::plunder() && { ...@@ -172,7 +172,7 @@ AutomatonBase* DFTA < SymbolType, RankType, StateType >::plunder() && {
} }
   
template<class SymbolType, class RankType, class StateType > template<class SymbolType, class RankType, class StateType >
bool DFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_symbol < SymbolType, RankType > & symbol, const std::vector<StateType> & prevStates, const StateType & next) { bool DFTA < SymbolType, RankType, StateType >::addTransition ( std::ranked_symbol < SymbolType, RankType > symbol, std::vector<StateType> prevStates, StateType next) {
if ( prevStates.size() != ( size_t ) symbol.getRank() ) if ( prevStates.size() != ( size_t ) symbol.getRank() )
throw AutomatonException("Number of states doesn't match rank of the symbol"); throw AutomatonException("Number of states doesn't match rank of the symbol");
   
...@@ -182,12 +182,12 @@ bool DFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s ...@@ -182,12 +182,12 @@ bool DFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s
if (! getStates().count(next)) if (! getStates().count(next))
throw AutomatonException("State \"" + std::to_string ( next ) + "\" doesn't exist."); throw AutomatonException("State \"" + std::to_string ( next ) + "\" doesn't exist.");
   
for (const StateType& it : prevStates) { for ( const StateType & it : prevStates) {
if (! getStates().count(it)) if (! getStates().count(it))
throw AutomatonException("State \"" + std::to_string ( it ) + "\" doesn't exist."); throw AutomatonException("State \"" + std::to_string ( it ) + "\" doesn't exist.");
} }
   
std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector<StateType> > key = std::make_pair(symbol, prevStates); std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector<StateType> > key = std::make_pair ( std::move ( symbol ), std::move ( prevStates ) );
if ( transitions.find ( key ) != transitions.end ( ) ) { if ( transitions.find ( key ) != transitions.end ( ) ) {
if ( transitions.find ( key )->second == next ) if ( transitions.find ( key )->second == next )
return false; return false;
...@@ -195,7 +195,7 @@ bool DFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s ...@@ -195,7 +195,7 @@ bool DFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s
throw AutomatonException("Transition already exists"); throw AutomatonException("Transition already exists");
} }
   
transitions.insert(std::make_pair(key, next)); transitions.insert ( std::make_pair ( std::move ( key ), std::move ( next ) ) );
return true; return true;
} }
   
......
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
* @param next next state * @param next next state
* @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton
*/ */
bool addTransition ( const std::ranked_symbol < SymbolType, RankType > & current, const std::vector < StateType > & children, const StateType & next ); bool addTransition ( std::ranked_symbol < SymbolType, RankType > current, std::vector < StateType > children, StateType next );
   
/** /**
* Removes transition from the automaton. * Removes transition from the automaton.
...@@ -190,7 +190,7 @@ AutomatonBase* NFTA < SymbolType, RankType, StateType >::plunder() && { ...@@ -190,7 +190,7 @@ AutomatonBase* NFTA < SymbolType, RankType, StateType >::plunder() && {
} }
   
template < class SymbolType, class RankType, class StateType > template < class SymbolType, class RankType, class StateType >
bool NFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_symbol < SymbolType, RankType > & symbol, const std::vector<StateType> & prevStates, const StateType & next) { bool NFTA < SymbolType, RankType, StateType >::addTransition ( std::ranked_symbol < SymbolType, RankType > symbol, std::vector<StateType> prevStates, StateType next) {
if (prevStates.size() != ( size_t ) symbol.getRank() ) if (prevStates.size() != ( size_t ) symbol.getRank() )
throw AutomatonException("Number of states doesn't match rank of the symbol"); throw AutomatonException("Number of states doesn't match rank of the symbol");
   
...@@ -205,8 +205,8 @@ bool NFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s ...@@ -205,8 +205,8 @@ bool NFTA < SymbolType, RankType, StateType >::addTransition(const std::ranked_s
throw AutomatonException("State \"" + std::to_string ( it ) + "\" doesn't exist."); throw AutomatonException("State \"" + std::to_string ( it ) + "\" doesn't exist.");
} }
   
std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector<StateType> > key = std::make_pair(symbol, prevStates); std::pair<std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > > key = std::make_pair ( std::move ( symbol ), std::move ( prevStates ) );
return transitions[key].insert(next).second; return transitions [ key ].insert ( std::move ( next ) ).second;
} }
   
template < class SymbolType, class RankType, class StateType > template < class SymbolType, class RankType, class StateType >
......
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