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

fix unnecessary slowdown in DFA states from method

parent 2609ac54
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -512,38 +512,36 @@ ext::map < ext::pair < StateType, SymbolType >, StateType > && DFA<SymbolType, S ...@@ -512,38 +512,36 @@ ext::map < ext::pair < StateType, SymbolType >, StateType > && DFA<SymbolType, S
return std::move ( transitions ); return std::move ( transitions );
} }
   
template < class Type, class From > template < class Type, class From >
class PartialComparator { class PartialComparator {
const Type & m_data; const Type & m_data;
std::function < const Type & ( const From & ) > retrieveFunction; std::function < const Type & ( const From & ) > retrieveFunction;
   
public: public:
PartialComparator ( const Type & data, const Type & ( * function ) ( const From & ) ) : m_data ( data ), retrieveFunction ( function ) { PartialComparator ( const Type & data, const Type & ( * function ) ( const From & ) ) : m_data ( data ), retrieveFunction ( function ) {
}
}
   
friend bool operator < ( const PartialComparator & first, const Type & second ) { friend bool operator < ( const PartialComparator & first, const Type & second ) {
return first.m_data < first.retrieveFunction ( second ); return first.m_data < first.retrieveFunction ( second );
} }
   
friend bool operator < ( const Type & first, const PartialComparator & second ) { friend bool operator < ( const Type & first, const PartialComparator & second ) {
return second.retrieveFunction ( first ) < second.m_data; return second.retrieveFunction ( first ) < second.m_data;
} }
}; };
   
template<class SymbolType, class StateType > template<class SymbolType, class StateType >
ext::range < typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator > DFA<SymbolType, StateType>::getTransitionsFromState ( const StateType & from ) const { ext::range < typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator > DFA<SymbolType, StateType>::getTransitionsFromState ( const StateType & from ) const {
if ( !getStates ( ).count ( from ) ) if ( !getStates ( ).count ( from ) )
throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" ); throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist" );
typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator lower = transitions.begin ( ); typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator lower = transitions.begin ( );
while ( lower != transitions.end ( ) && lower->first.first < from ) { while ( lower != transitions.end ( ) && lower->first.first < from )
++ lower; ++ lower;
}
   
typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator upper = transitions.begin ( ); typename ext::map < ext::pair < StateType, SymbolType >, StateType >::const_iterator upper = lower;
while ( upper != transitions.end ( ) && upper->first.first <= from ) { while ( upper != transitions.end ( ) && upper->first.first <= from )
++ upper; ++ upper;
}
   
return ext::make_range ( lower, upper ); return ext::make_range ( lower, upper );
} }
......
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